Skip to contentSkip to conversation

iio: cros_ec_sensors_core: fix unsigned compared less than zero on status

PATCH In review Colin King 3 participants 3 messages Nov 9, 2016 – Nov 12, 2016

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 iio: cros_ec_sensors_core: fix unsigned compared less than zero on status

From: Colin Ian King <[email protected]>

status is a u8 hence the check if status is less than zero has no effect. Fix this by replacing status with int ret so the less than zero compare will correctly detect errors.

Issue found with static analysis with CoverityScan, CID 1375919

---
 drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +4 -4
index a3be799..416cae5 100644
@@ -291,15 +291,15 @@ int cros_ec_sensors_read_lpc(struct iio_dev *indio_dev,
 			return -EIO;
 
 		/* Read status byte until EC is not busy. */
-		status = cros_ec_sensors_read_until_not_busy(st);
-		if (status < 0)
-			return status;
+		ret = cros_ec_sensors_read_until_not_busy(st);
+		if (ret < 0)
+			return ret;
 
 		/*
 		 * Store the current sample id so that we can compare to the
 		 * sample id after reading the data.
 		 */
-		samp_id = status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
+		samp_id = ret & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
 
 		/* Read all EC data, format it, and store it into data. */
 		ret = cros_ec_sensors_read_data_unsafe(indio_dev, scan_mask,
Signature · 1 line
2.10.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Colin King

From: Colin Ian King <[email protected]>

status is a u8 hence the check if status is less than zero has no effect. Fix this by replacing status with int ret so the less than zero compare will correctly detect errors.

Issue found with static analysis with CoverityScan, CID 1375919

Good catch!

Fixes 974e6f02e27e ("iio: cros_ec_sensors_core: Add common functions

for the ChromeOS EC Sensor Hub")

For the benefit of others, this is in today's linux-next.

Thanks,
Guenter

Quoted 31 lines
---
 drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +4 -5
index a3be799..416cae5 100644
@@ -291,15 +291,15 @@ int cros_ec_sensors_read_lpc(struct iio_dev *indio_dev,
                        return -EIO;
 
                /* Read status byte until EC is not busy. */
-               status = cros_ec_sensors_read_until_not_busy(st);
-               if (status < 0)
-                       return status;
+               ret = cros_ec_sensors_read_until_not_busy(st);
+               if (ret < 0)
+                       return ret;
 
                /*
                 * Store the current sample id so that we can compare to the
                 * sample id after reading the data.
                 */
-               samp_id = status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
+               samp_id = ret & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
 
                /* Read all EC data, format it, and store it into data. */
                ret = cros_ec_sensors_read_data_unsafe(indio_dev, scan_mask,
--

2.10.2

maintainer
#2 lore raw
Quoted 9 lines · Guenter Roeck
Quoted 8 lines · Colin King

From: Colin Ian King <[email protected]>

status is a u8 hence the check if status is less than zero has no effect. Fix this by replacing status with int ret so the less than zero compare will correctly detect errors.

Issue found with static analysis with CoverityScan, CID 1375919

Quoted 7 lines
Quoted 1 line

Good catch!

Fixes 974e6f02e27e ("iio: cros_ec_sensors_core: Add common functions

for the ChromeOS EC Sensor Hub")

Thanks and applied to the togreg branch of iio.git - shortly to be pushed out as testing for the autobuilders to take a look at it.

Jonathan

Quoted 42 lines

For the benefit of others, this is in today's linux-next.

Thanks,
Guenter

Quoted 29 lines
---
 drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +4 -5
index a3be799..416cae5 100644
@@ -291,15 +291,15 @@ int cros_ec_sensors_read_lpc(struct iio_dev *indio_dev,
                        return -EIO;
 
                /* Read status byte until EC is not busy. */
-               status = cros_ec_sensors_read_until_not_busy(st);
-               if (status < 0)
-                       return status;
+               ret = cros_ec_sensors_read_until_not_busy(st);
+               if (ret < 0)
+                       return ret;
 
                /*
                 * Store the current sample id so that we can compare to the
                 * sample id after reading the data.
                 */
-               samp_id = status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
+               samp_id = ret & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
 
                /* Read all EC data, format it, and store it into data. */
                ret = cros_ec_sensors_read_data_unsafe(indio_dev, scan_mask,
--
Quoted 2 lines

2.10.2

--
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