Skip to contentSkip to conversation

iio: adc: Check for error from devm_mutex_init()

PATCH Applied Andy Shevchenko 3 participants 5 messages Oct 30, 2024 – Oct 31, 2024

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

cover iio: adc: Check for error from devm_mutex_init()

Ignoring error checking from devm calls is a bad practice in general. While not critical today, it may become a problem tomorrow. Fix this for devm_mutex_init().

Andy Shevchenko (2):
iio: adc: ad4000: Check for error code from devm_mutex_init() call
iio: adc: pac1921: Check for error code from devm_mutex_init() call

 drivers/iio/adc/ad4000.c  | 4 +++-
 drivers/iio/adc/pac1921.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#1 lore raw

PATCH 1/2 iio: adc: ad4000: Check for error code from devm_mutex_init() call

Even if it's not critical, the avoidance of checking the error code from devm_mutex_init() call today diminishes the point of using devm variant of it. Tomorrow it may even leak something. Add the missed check.

Fixes 938fd562b974 ("iio: adc: Add support for AD4000")
---
 drivers/iio/adc/ad4000.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/ad4000.c +3 -1
index 6ea491245084..b4a23c97ee52 100644
@@ -637,7 +637,9 @@ static int ad4000_probe(struct spi_device *spi)
 	indio_dev->name = chip->dev_name;
 	indio_dev->num_channels = 1;
 
-	devm_mutex_init(dev, &st->lock);
+	ret = devm_mutex_init(dev, &st->lock);
+	if (ret)
+		return ret;
 
 	st->gain_milli = 1000;
 	if (chip->has_hardware_gain) {
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#2 lore raw

PATCH 2/2 iio: adc: pac1921: Check for error code from devm_mutex_init() call

In reply to Andy Shevchenko

Even if it's not critical, the avoidance of checking the error code from devm_mutex_init() call today diminishes the point of using devm variant of it. Tomorrow it may even leak something. Add the missed check.

Fixes 371f778b83cd ("iio: adc: add support for pac1921")
---
 drivers/iio/adc/pac1921.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/pac1921.c +3 -1
index f6f8f9122a78..385e86ecc441 100644
@@ -1132,7 +1132,9 @@ static int pac1921_probe(struct i2c_client *client)
 		return dev_err_probe(dev, PTR_ERR(priv->regmap),
 				     "Cannot initialize register map\n");
 
-	devm_mutex_init(dev, &priv->lock);
+	ret = devm_mutex_init(dev, &priv->lock);
+	if (ret)
+		return ret;
 
 	priv->dv_gain = PAC1921_DEFAULT_DV_GAIN;
 	priv->di_gain = PAC1921_DEFAULT_DI_GAIN;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
maintainer Acked-by on v1 2/2
#3 lore raw

Re: [PATCH v1 2/2] iio: adc: pac1921: Check for error code from devm_mutex_init() call

Quoting Andy Shevchenko (2024-10-30 17:19:19)

Quoted 29 lines

Even if it's not critical, the avoidance of checking the error code from devm_mutex_init() call today diminishes the point of using devm variant of it. Tomorrow it may even leak something. Add the missed check.

Fixes 371f778b83cd ("iio: adc: add support for pac1921")
---
 drivers/iio/adc/pac1921.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/pac1921.c +3 -1
index f6f8f9122a78..385e86ecc441 100644
@@ -1132,7 +1132,9 @@ static int pac1921_probe(struct i2c_client *client)
                return dev_err_probe(dev, PTR_ERR(priv->regmap),
                                     "Cannot initialize register map\n");
 
-       devm_mutex_init(dev, &priv->lock);
+       ret = devm_mutex_init(dev, &priv->lock);
+       if (ret)
+               return ret;
 
        priv->dv_gain = PAC1921_DEFAULT_DV_GAIN;
        priv->di_gain = PAC1921_DEFAULT_DI_GAIN;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac

Totally agree, thanks!

Best regards,
Matteo Martelli

maintainer Applied
#4 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · On Wed, 30 Oct 2024 18:19:17 +0200 Andy Shevchenko…

Ignoring error checking from devm calls is a bad practice in general. While not critical today, it may become a problem tomorrow. Fix this for devm_mutex_init().

Andy Shevchenko (2):
iio: adc: ad4000: Check for error code from devm_mutex_init() call
iio: adc: pac1921: Check for error code from devm_mutex_init() call

Oops. Missed this in review obviously.

Applied.

Quoted 4 lines
 drivers/iio/adc/ad4000.c  | 4 +++-
 drivers/iio/adc/pac1921.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)