public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: dac: mcp47feb02: Fix mutex used before initialization
@ 2026-02-23  8:03 Felix Gu
  2026-02-23  8:52 ` Andy Shevchenko
  2026-02-23 11:13 ` Nuno Sá
  0 siblings, 2 replies; 5+ messages in thread
From: Felix Gu @ 2026-02-23  8:03 UTC (permalink / raw)
  To: Ariana Lazar, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko
  Cc: Jonathan Cameron, linux-iio, linux-kernel, Felix Gu

The mcp47feb02_parse_fw() function uses data->lock, but the mutex was
initialized after this function in probe path.

Fix this by moving devm_mutex_init() before mcp47feb02_parse_fw().

Fixes: bf394cc80369 ("iio: dac: adding support for Microchip MCP47FEB02")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/iio/dac/mcp47feb02.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/dac/mcp47feb02.c b/drivers/iio/dac/mcp47feb02.c
index b218f0c3a0bd..4ff5abcfecea 100644
--- a/drivers/iio/dac/mcp47feb02.c
+++ b/drivers/iio/dac/mcp47feb02.c
@@ -1131,14 +1131,14 @@ static int mcp47feb02_probe(struct i2c_client *client)
 
 	indio_dev->name = chip_features->name;
 
-	ret = mcp47feb02_parse_fw(indio_dev, chip_features);
-	if (ret)
-		return dev_err_probe(dev, ret, "Error parsing firmware data\n");
-
 	ret = devm_mutex_init(dev, &data->lock);
 	if (ret)
 		return ret;
 
+	ret = mcp47feb02_parse_fw(indio_dev, chip_features);
+	if (ret)
+		return dev_err_probe(dev, ret, "Error parsing firmware data\n");
+
 	ret = devm_regulator_get_enable_read_voltage(dev, "vdd");
 	if (ret < 0)
 		return ret;

---
base-commit: d4906ae14a5f136ceb671bb14cedbf13fa560da6
change-id: 20260223-mcp47feb02-e0bed17e198b

Best regards,
-- 
Felix Gu <ustc.gu@gmail.com>


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: dac: mcp47feb02: Fix mutex used before initialization
  2026-02-23  8:03 [PATCH] iio: dac: mcp47feb02: Fix mutex used before initialization Felix Gu
@ 2026-02-23  8:52 ` Andy Shevchenko
  2026-02-23  9:22   ` Felix Gu
  2026-02-23 11:13 ` Nuno Sá
  1 sibling, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2026-02-23  8:52 UTC (permalink / raw)
  To: Felix Gu
  Cc: Ariana Lazar, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Jonathan Cameron, linux-iio, linux-kernel

On Mon, Feb 23, 2026 at 04:03:34PM +0800, Felix Gu wrote:
> The mcp47feb02_parse_fw() function uses data->lock, but the mutex was
> initialized after this function in probe path.
> 
> Fix this by moving devm_mutex_init() before mcp47feb02_parse_fw().

There are several patches from you lately. Are you sure the version is correct,
id est this one is indeed v1? Sorry, I'm a bit lost.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: dac: mcp47feb02: Fix mutex used before initialization
  2026-02-23  8:52 ` Andy Shevchenko
@ 2026-02-23  9:22   ` Felix Gu
  0 siblings, 0 replies; 5+ messages in thread
From: Felix Gu @ 2026-02-23  9:22 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Ariana Lazar, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Jonathan Cameron, linux-iio, linux-kernel

> There are several patches from you lately. Are you sure the version is correct,
> id est this one is indeed v1? Sorry, I'm a bit lost.
>
Hi Andy,
This is V1.
It seems b4 doesn't include V1 in the subject prefix by default.

Best regards,
Felix

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: dac: mcp47feb02: Fix mutex used before initialization
  2026-02-23  8:03 [PATCH] iio: dac: mcp47feb02: Fix mutex used before initialization Felix Gu
  2026-02-23  8:52 ` Andy Shevchenko
@ 2026-02-23 11:13 ` Nuno Sá
  2026-02-23 11:36   ` Andy Shevchenko
  1 sibling, 1 reply; 5+ messages in thread
From: Nuno Sá @ 2026-02-23 11:13 UTC (permalink / raw)
  To: Felix Gu, Ariana Lazar, Jonathan Cameron, David Lechner,
	Nuno Sá, Andy Shevchenko
  Cc: Jonathan Cameron, linux-iio, linux-kernel

On Mon, 2026-02-23 at 16:03 +0800, Felix Gu wrote:
> The mcp47feb02_parse_fw() function uses data->lock, but the mutex was
> initialized after this function in probe path.
> 
> Fix this by moving devm_mutex_init() before mcp47feb02_parse_fw().
> 
> Fixes: bf394cc80369 ("iio: dac: adding support for Microchip MCP47FEB02")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
>  drivers/iio/dac/mcp47feb02.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/dac/mcp47feb02.c b/drivers/iio/dac/mcp47feb02.c
> index b218f0c3a0bd..4ff5abcfecea 100644
> --- a/drivers/iio/dac/mcp47feb02.c
> +++ b/drivers/iio/dac/mcp47feb02.c
> @@ -1131,14 +1131,14 @@ static int mcp47feb02_probe(struct i2c_client *client)
>  
>  	indio_dev->name = chip_features->name;
>  
> -	ret = mcp47feb02_parse_fw(indio_dev, chip_features);
> -	if (ret)
> -		return dev_err_probe(dev, ret, "Error parsing firmware data\n");
> -
>  	ret = devm_mutex_init(dev, &data->lock);
>  	if (ret)
>  		return ret;
>  
> +	ret = mcp47feb02_parse_fw(indio_dev, chip_features);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "Error parsing firmware data\n");
> +

Actually I think the better fix is to not lock at all? Why do we need a lock around 
mcp47feb02_parse_fw() if it's only called from probe()?

- Nuno Sá
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: dac: mcp47feb02: Fix mutex used before initialization
  2026-02-23 11:13 ` Nuno Sá
@ 2026-02-23 11:36   ` Andy Shevchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2026-02-23 11:36 UTC (permalink / raw)
  To: Nuno Sá
  Cc: Felix Gu, Ariana Lazar, Jonathan Cameron, David Lechner,
	Nuno Sá, Andy Shevchenko, Jonathan Cameron, linux-iio,
	linux-kernel

On Mon, Feb 23, 2026 at 11:13:33AM +0000, Nuno Sá wrote:
> On Mon, 2026-02-23 at 16:03 +0800, Felix Gu wrote:
> > The mcp47feb02_parse_fw() function uses data->lock, but the mutex was
> > initialized after this function in probe path.

> Actually I think the better fix is to not lock at all? Why do we need a lock around 
> mcp47feb02_parse_fw() if it's only called from probe()?

+1! The lock should be called when it's required. Any explanations from the Git
history on it?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-02-23 11:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-23  8:03 [PATCH] iio: dac: mcp47feb02: Fix mutex used before initialization Felix Gu
2026-02-23  8:52 ` Andy Shevchenko
2026-02-23  9:22   ` Felix Gu
2026-02-23 11:13 ` Nuno Sá
2026-02-23 11:36   ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox