diff mbox

[ethtool] Fix iteration count in sff8472_calibration()

Message ID 1379813802.21174.36.camel@deadeye.wl.decadent.org.uk
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Ben Hutchings Sept. 22, 2013, 1:36 a.m. UTC
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.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 sfpdiag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ben Hutchings Nov. 8, 2013, 4:54 p.m. UTC | #1
On Sun, 2013-09-22 at 02:36 +0100, Ben Hutchings wrote:
> 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.
> 
> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
> ---

Applied.  Thanks, me.

Ben.

>  sfpdiag.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sfpdiag.c b/sfpdiag.c
> index f67e491..04fd880 100644
> --- a/sfpdiag.c
> +++ b/sfpdiag.c
> @@ -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)
>  		 */
>
diff mbox

Patch

diff --git a/sfpdiag.c b/sfpdiag.c
index f67e491..04fd880 100644
--- a/sfpdiag.c
+++ b/sfpdiag.c
@@ -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)
 		 */