Skip to contentSkip to conversation

gpio: Check for error from devm_mutex_init()

PATCH In review Andy Shevchenko 3 participants 7 messages Oct 30, 2024

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

cover gpio: 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):
gpio: mpsse: Check for error code from devm_mutex_init() call
gpio: sloppy-logic-analyzer: Check for error code from
devm_mutex_init() call

 drivers/gpio/gpio-mpsse.c                 | 9 +++++++--
 drivers/gpio/gpio-sloppy-logic-analyzer.c | 4 +++-
 2 files changed, 10 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#1 lore raw

PATCH 1/2 gpio: mpsse: 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 c46a74ff05c0 ("gpio: add support for FTDI's MPSSE as GPIO")
---
 drivers/gpio/gpio-mpsse.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpio/gpio-mpsse.c +7 -2
index 3ab6651d2226..8fba0779ae17 100644
@@ -430,8 +430,13 @@ static int gpio_mpsse_probe(struct usb_interface *interface,
 	if (err)
 		return err;
 
-	devm_mutex_init(dev, &priv->io_mutex);
-	devm_mutex_init(dev, &priv->irq_mutex);
+	err = devm_mutex_init(dev, &priv->io_mutex);
+	if (err)
+		return err;
+
+	ret = devm_mutex_init(dev, &priv->irq_mutex);
+	if (err)
+		return err;
 
 	priv->gpio.label = devm_kasprintf(dev, GFP_KERNEL,
 					  "gpio-mpsse.%d.%d",
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH v1 1/2] gpio: mpsse: Check for error code from devm_mutex_init() call

Hello Andy!

Quoted 4 lines · 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.

Totally missed this... Thanks!

drivers/gpio/gpio-mpsse.c static int gpio_mpsse_probe(struct usb_interface *interface, · line 437

Quoted 11 lines
drivers/gpio/gpio-mpsse.c +5 -2
@@ -430,8 +430,13 @@ static int gpio_mpsse_probe(struct usb_interface *interface,
 	if (err)
 		return err;
 
-	devm_mutex_init(dev, &priv->io_mutex);
-	devm_mutex_init(dev, &priv->irq_mutex);
+	err = devm_mutex_init(dev, &priv->io_mutex);
+	if (err)
+		return err;
+
+	ret = devm_mutex_init(dev, &priv->irq_mutex);

I think this should be err =

Other than that, it looks good to me (I doubt you need this, but just in case):

Thanks!

#3 lore raw

Re: [PATCH v1 1/2] gpio: mpsse: Check for error code from devm_mutex_init() call

Quoted 1 line · Mary Strodl

On Wed, Oct 30, 2024 at 05:30:26PM +0200, Andy Shevchenko wrote:

...

Quoted 7 lines

drivers/gpio/gpio-mpsse.c static int gpio_mpsse_probe(struct usb_interface *interface, · line 437

Quoted 5 lines
drivers/gpio/gpio-mpsse.c +5 -0
+	err = devm_mutex_init(dev, &priv->io_mutex);
+	if (err)
+		return err;
+
+	ret = devm_mutex_init(dev, &priv->irq_mutex);

I think this should be err =

Oh, I haven't compiled that for sure :-)

Quoted 3 lines

Other than that, it looks good to me (I doubt you need this, but just in case):

Thanks, I will fix that, I dunno how I missed that because I carefully read the code before adding the checks.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH v1 1/2] gpio: mpsse: Check for error code from devm_mutex_init() call

Quoted 2 lines · Andy Shevchenko

Thanks, I will fix that, I dunno how I missed that because I carefully read the code before adding the checks.

Proof that it happens to the best of us :)

Thanks again!

#5 lore raw

PATCH 2/2 gpio: sloppy-logic-analyzer: 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 7828b7bbbf20 ("gpio: add sloppy logic analyzer using polling")
---
 drivers/gpio/gpio-sloppy-logic-analyzer.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpio/gpio-sloppy-logic-analyzer.c +3 -1
index 64f2ca4a72b2..8cf3b171c599 100644
@@ -234,7 +234,9 @@ static int gpio_la_poll_probe(struct platform_device *pdev)
 	if (!priv)
 		return -ENOMEM;
 
-	devm_mutex_init(dev, &priv->blob_lock);
+	ret = devm_mutex_init(dev, &priv->blob_lock);
+	if (ret)
+		return ret;
 
 	fops_buf_size_set(priv, GPIO_LA_DEFAULT_BUF_SIZE);
 
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
maintainer Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH v1 2/2] gpio: sloppy-logic-analyzer: Check for error code from devm_mutex_init() call

Quoted 7 lines · 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 7828b7bbbf20 ("gpio: add sloppy logic analyzer using polling")

Thanks!