Skip to contentSkip to conversation

iio: magnetometer: correct a harmless off by one check

PATCH Applied Dan Carpenter 3 participants 3 messages May 27, 2015 – Jun 1, 2015

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

PATCH 1/1 iio: magnetometer: correct a harmless off by one check

The line before limits i to 0-3 so the existing code works fine but the check is still off by one and >= is intended instead of >.

drivers/iio/magnetometer/mmc35240.c +1 -1
index aa6e25d..c71392c 100644
@@ -308,7 +308,7 @@ static int mmc35240_read_raw(struct iio_dev *indio_dev,
 			return ret;
 
 		i = (reg & MMC35240_CTRL1_BW_MASK) >> MMC35240_CTRL1_BW_SHIFT;
-		if (i < 0 || i > ARRAY_SIZE(mmc35240_samp_freq))
+		if (i < 0 || i >= ARRAY_SIZE(mmc35240_samp_freq))
 			return -EINVAL;
 
 		*val = mmc35240_samp_freq[i];
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Dan Carpenter

The line before limits i to 0-3 so the existing code works fine but the check is still off by one and >= is intended instead of >.

Good catch.

Quoted 18 lines
drivers/iio/magnetometer/mmc35240.c +1 -2
index aa6e25d..c71392c 100644
@@ -308,7 +308,7 @@ static int mmc35240_read_raw(struct iio_dev *indio_dev,
                        return ret;
 
                i = (reg & MMC35240_CTRL1_BW_MASK) >> MMC35240_CTRL1_BW_SHIFT;
-               if (i < 0 || i > ARRAY_SIZE(mmc35240_samp_freq))
+               if (i < 0 || i >= ARRAY_SIZE(mmc35240_samp_freq))
                        return -EINVAL;
 
                *val = mmc35240_samp_freq[i];
--

To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer Applied
#2 lore raw
Quoted 10 lines · Daniel Baluta
Quoted 4 lines · Dan Carpenter

The line before limits i to 0-3 so the existing code works fine but the check is still off by one and >= is intended instead of >.

Good catch.

Applied to the togreg branch of iio.git - initially pushed out as testing when I have a network that does anything other than https.

J

Quoted 24 lines
Quoted 16 lines
drivers/iio/magnetometer/mmc35240.c +1 -2
index aa6e25d..c71392c 100644
@@ -308,7 +308,7 @@ static int mmc35240_read_raw(struct iio_dev *indio_dev,
                        return ret;
 
                i = (reg & MMC35240_CTRL1_BW_MASK) >> MMC35240_CTRL1_BW_SHIFT;
-               if (i < 0 || i > ARRAY_SIZE(mmc35240_samp_freq))
+               if (i < 0 || i >= ARRAY_SIZE(mmc35240_samp_freq))
                        return -EINVAL;
 
                *val = mmc35240_samp_freq[i];
--
Quoted 3 lines

To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html