Skip to contentSkip to conversation

iio: dac: mcp47feb02: Fix mutex used before initialization

PATCH Superseded Felix Gu 3 participants 5 messages Feb 23

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH 1/1 iio: dac: mcp47feb02: Fix mutex used before initialization

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")
---
 drivers/iio/dac/mcp47feb02.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iio/dac/mcp47feb02.c +4 -4
index b218f0c3a0bd..4ff5abcfecea 100644
@@ -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,

Signature · 1 line
Felix Gu <[email protected]>
#1 lore raw
Quoted 4 lines · 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().

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.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#2 lore raw
Quoted 3 lines

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

#3 lore raw
In reply to Felix Gu
Quoted 27 lines · 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")

---
 drivers/iio/dac/mcp47feb02.c | 8 ++++----

 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iio/dac/mcp47feb02.c +0 -0
index b218f0c3a0bd..4ff5abcfecea 100644
@@ -1131,14 +1131,14 @@ static int mcp47feb02_probe(struct i2c_client *client)


  indio_dev->name = chip_features->name;

drivers/iio/dac/mcp47feb02.c +0 -4
-	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;

drivers/iio/dac/mcp47feb02.c static int mcp47feb02_probe(struct i2c_client *client) · line 1141

Quoted 4 lines
drivers/iio/dac/mcp47feb02.c +4 -0
+	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á

Quoted 1 line
#4 lore raw
Quoted 6 lines · Nuno Sá
Quoted 2 lines · Felix Gu

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?

Signature · 2 lines
With Best Regards,
Andy Shevchenko