[PATCH v1 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization

Andy Shevchenko posted 3 patches 3 weeks, 4 days ago
There is a newer version of this series
[PATCH v1 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization
Posted by Andy Shevchenko 3 weeks, 4 days ago
Replace mutex_init() with the devm_mutex_init(), to ensure proper mutex
cleanup during probe failure and driver removal.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpio-pca9570.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-pca9570.c b/drivers/gpio/gpio-pca9570.c
index c5a1287079a0..eae35135c71e 100644
--- a/drivers/gpio/gpio-pca9570.c
+++ b/drivers/gpio/gpio-pca9570.c
@@ -115,7 +115,9 @@ static int pca9570_set(struct gpio_chip *chip, unsigned int offset, int value)
 
 static int pca9570_probe(struct i2c_client *client)
 {
+	struct device *dev = &client->dev;
 	struct pca9570 *gpio;
+	int ret;
 
 	gpio = devm_kzalloc(&client->dev, sizeof(*gpio), GFP_KERNEL);
 	if (!gpio)
@@ -132,7 +134,9 @@ static int pca9570_probe(struct i2c_client *client)
 	gpio->chip.ngpio = gpio->chip_data->ngpio;
 	gpio->chip.can_sleep = true;
 
-	mutex_init(&gpio->lock);
+	ret = devm_mutex_init(dev, &gpio->lock);
+	if (ret)
+		return ret;
 
 	/* Read the current output level */
 	pca9570_read(gpio, &gpio->out);
-- 
2.50.1
Re: [PATCH v1 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization
Posted by Bartosz Golaszewski 3 weeks, 4 days ago
On Tue, Jan 13, 2026 at 11:09 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> Replace mutex_init() with the devm_mutex_init(), to ensure proper mutex
> cleanup during probe failure and driver removal.
>

Well, I can almost hear Johan Hovold yelling at you that this is not
about mutex cleanup but merely a useless debugging feature.

Though personally, I'm fine with it. Just reword the commit message
because there's no actual cleanup happening other than freeing the
memory allocated for the devres entry. :)

Bartosz
Re: [PATCH v1 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization
Posted by Andy Shevchenko 3 weeks, 4 days ago
On Tue, Jan 13, 2026 at 12:01:40PM +0100, Bartosz Golaszewski wrote:
> On Tue, Jan 13, 2026 at 11:09 AM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > Replace mutex_init() with the devm_mutex_init(), to ensure proper mutex
> > cleanup during probe failure and driver removal.
> 
> Well, I can almost hear Johan Hovold yelling at you that this is not
> about mutex cleanup but merely a useless debugging feature.
> 
> Though personally, I'm fine with it. Just reword the commit message
> because there's no actual cleanup happening other than freeing the
> memory allocated for the devres entry. :)

v2 is sent, thanks for review!

-- 
With Best Regards,
Andy Shevchenko


Re: [PATCH v1 1/3] gpio: pca9570: Use devm_mutex_init() for mutex initialization
Posted by Linus Walleij 3 weeks, 4 days ago
On Tue, Jan 13, 2026 at 11:09 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> Replace mutex_init() with the devm_mutex_init(), to ensure proper mutex
> cleanup during probe failure and driver removal.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Linus Walleij <linusw@kernel.org>

Yours,
Linus Walleij