Skip to contentSkip to conversation

Fix iteration count in sff8472_calibration()

PATCH Applied Ben Hutchings 2 participants 2 messages Sep 22, 2013 – Nov 8, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix iteration count in sff8472_calibration()

We want to iterate over all elements of the various arrays of readings (which all have the same dimensions - and maybe ought to be a single array). Unfortunately the iteration count is sizeof(sd->bias_cur) and bias_cur has 2-byte elements, so we iterate over twice as many elements as are really there.

Compiler-detected, and compile-tested only.

---
 sfpdiag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sfpdiag.c +1 -1
index f67e491..04fd880 100644
@@ -224,7 +224,7 @@ static void sff8472_calibration(const __u8 *id, struct sff8472_diags *sd)
 	__u16 rx_reading;
 
 	/* Calibration should occur for all values (threshold and current) */
-	for (i = 0; i < sizeof(sd->bias_cur); ++i) {
+	for (i = 0; i < ARRAY_SIZE(sd->bias_cur); ++i) {
 		/*
 		 * Apply calibration formula 1 (Temp., Voltage, Bias, Tx Power)
 		 */
#1 lore raw
Quoted 10 lines · Ben Hutchings

We want to iterate over all elements of the various arrays of readings (which all have the same dimensions - and maybe ought to be a single array). Unfortunately the iteration count is sizeof(sd->bias_cur) and bias_cur has 2-byte elements, so we iterate over twice as many elements as are really there.

Compiler-detected, and compile-tested only.

---

Applied. Thanks, me.

Ben.

Quoted 17 lines
 sfpdiag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sfpdiag.c +1 -1
index f67e491..04fd880 100644
@@ -224,7 +224,7 @@ static void sff8472_calibration(const __u8 *id, struct sff8472_diags *sd)
 	__u16 rx_reading;
 
 	/* Calibration should occur for all values (threshold and current) */
-	for (i = 0; i < sizeof(sd->bias_cur); ++i) {
+	for (i = 0; i < ARRAY_SIZE(sd->bias_cur); ++i) {
 		/*
 		 * Apply calibration formula 1 (Temp., Voltage, Bias, Tx Power)
 		 */
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.