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

Andy Shevchenko posted 2 patches 3 weeks, 4 days ago
[PATCH v1 2/2] iio: adc: pac1921: Check for error code from devm_mutex_init() call
Posted by Andy Shevchenko 3 weeks, 4 days ago
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")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/adc/pac1921.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/pac1921.c b/drivers/iio/adc/pac1921.c
index f6f8f9122a78..385e86ecc441 100644
--- a/drivers/iio/adc/pac1921.c
+++ b/drivers/iio/adc/pac1921.c
@@ -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;
-- 
2.43.0.rc1.1336.g36b5255a03ac
Re: [PATCH v1 2/2] iio: adc: pac1921: Check for error code from devm_mutex_init() call
Posted by Matteo Martelli 3 weeks, 4 days ago
Quoting Andy Shevchenko (2024-10-30 17:19:19)
> 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")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/iio/adc/pac1921.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/pac1921.c b/drivers/iio/adc/pac1921.c
> index f6f8f9122a78..385e86ecc441 100644
> --- a/drivers/iio/adc/pac1921.c
> +++ b/drivers/iio/adc/pac1921.c
> @@ -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;
> -- 
> 2.43.0.rc1.1336.g36b5255a03ac
> 

Totally agree, thanks!

Acked-by: Matteo Martelli <matteomartelli3@gmail.com>

Best regards,
Matteo Martelli