From 0d9424b9ffac86589fee405bd1e7cacc4df35ee5 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Wed, 15 May 2024 21:26:07 +0200 Subject: [PATCH] fix(ipmi/sdrs): iterate over the last item in the SDR list only once --- src/lib.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 86f0368..b8dcb2c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,6 +114,12 @@ where fn next(&mut self) -> Option { let current_id = self.next_id?; + + if current_id.is_last() { + self.next_id.take(); + return None; + } + let next_record = self .ipmi .send_recv(sdr::GetDeviceSdr::new(None, current_id)); @@ -125,14 +131,14 @@ where (Some(record.record), next_record_id) } Err(IpmiError::ParsingFailed { - error: ParseResponseError::Parse((e, next_id)), + error: ParseResponseError::Parse((e, next_record_id)), .. }) => { log::warn!( "Recoverable error while parsing SDR record 0x{:04X}: {e:?}", current_id.value() ); - (None, next_id) + (None, next_record_id) } Err(e) => { log::error!( @@ -144,16 +150,12 @@ where } }; - if current_id.is_last() { + if next_record_id == current_id { + log::error!("Got duplicate SDR record IDs! Stopping iteration."); self.next_id.take(); + return None; } else { - if next_record_id == current_id { - log::error!("Got duplicate SDR record IDs! Stopping iteration."); - self.next_id.take(); - return None; - } else { - self.next_id = Some(next_record_id); - } + self.next_id = Some(next_record_id); } value