Skip to contentSkip to conversation

iio: adis16400: Fix an error code in adis16400_initial_setup()

PATCH In review Dan Carpenter 2 participants 2 messages Feb 16, 2021 – Feb 21, 2021

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

PATCH 1/1 iio: adis16400: Fix an error code in adis16400_initial_setup()

This is to silence a new Smatch warning:

drivers/iio/imu/adis16400.c:492 adis16400_initial_setup()
warn: sscanf doesn't return error codes

If the condition "if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) {" is false then we return 1 instead of returning 0 and probe will fail.

Fixes 72a868b38bdd ("iio: imu: check sscanf return value")
---
 drivers/iio/imu/adis16400.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iio/imu/adis16400.c +1 -2
index 54af2ed664f6..785a4ce606d8 100644
@@ -462,8 +462,7 @@ static int adis16400_initial_setup(struct iio_dev *indio_dev)
 		if (ret)
 			goto err_ret;
 
-		ret = sscanf(indio_dev->name, "adis%u\n", &device_id);
-		if (ret != 1) {
+		if (sscanf(indio_dev->name, "adis%u\n", &device_id) != 1) {
 			ret = -EINVAL;
 			goto err_ret;
 		}
Signature · 1 line
2.30.0
maintainer
#1 lore raw
Quoted 10 lines · On Tue, 16 Feb 2021 22:42:13 +0300 Dan Carpenter <[email protected]>…

This is to silence a new Smatch warning:

drivers/iio/imu/adis16400.c:492 adis16400_initial_setup()
warn: sscanf doesn't return error codes

If the condition "if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) {" is false then we return 1 instead of returning 0 and probe will fail.

Fixes 72a868b38bdd ("iio: imu: check sscanf return value")

Hi Dan,

May be worth a follow up at some point to get rid of the silliness of goto err_ret by using direct returns. Obviously that is a rather less minimal fix however so not so good for backports.

Hence, applied this to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan

Quoted 18 lines
---
 drivers/iio/imu/adis16400.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iio/imu/adis16400.c +1 -2
index 54af2ed664f6..785a4ce606d8 100644
@@ -462,8 +462,7 @@ static int adis16400_initial_setup(struct iio_dev *indio_dev)
 		if (ret)
 			goto err_ret;
 
-		ret = sscanf(indio_dev->name, "adis%u\n", &device_id);
-		if (ret != 1) {
+		if (sscanf(indio_dev->name, "adis%u\n", &device_id) != 1) {
 			ret = -EINVAL;
 			goto err_ret;
 		}