Skip to contentSkip to conversation

iio: chemical: scd30: Use devm_mutex_init() over non-devm mutex_init()

PATCH In review Maxwell Doose 3 participants 3 messages Jun 6 – Jun 14

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

PATCH v3 1/1 iio: chemical: scd30: Use devm_mutex_init() over non-devm mutex_init()

The current code uses mutex_init() instead of devm_mutex_init(), which is incorrect as the rest of the file uses the devm automatic resource management API. Fix this so that the mutex is set up in the same way as the rest of the device data structure.

---
v3:
- Return ret instead of -ENOMEM.

 drivers/iio/chemical/scd30_core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/iio/chemical/scd30_core.c +4 -1
index db5cc295aeab..f1f2507c03b2 100644
@@ -714,7 +714,10 @@ int scd30_probe(struct device *dev, int irq, const char *name, void *priv,
 	state->pressure_comp = SCD30_PRESSURE_COMP_DEFAULT;
 	state->meas_interval = SCD30_MEAS_INTERVAL_DEFAULT;
 	state->command = command;
-	mutex_init(&state->lock);
+	ret = devm_mutex_init(dev, &state->lock);
+	if (ret)
+		return ret;
+
 	init_completion(&state->meas_ready);
 
 	dev_set_drvdata(dev, indio_dev);
Signature · 1 line
2.54.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 4 lines · Maxwell Doose

The current code uses mutex_init() instead of devm_mutex_init(), which is incorrect as the rest of the file uses the devm automatic resource management API. Fix this so that the mutex is set up in the same way as the rest of the device data structure.

...

drivers/iio/chemical/scd30_core.c int scd30_probe(struct device *dev, int irq, const char *name, void *priv, · line 716

Quoted 2 lines
drivers/iio/chemical/scd30_core.c +0 -0
 	state->meas_interval = SCD30_MEAS_INTERVAL_DEFAULT;
 	state->command = command;

+ blank line here.

Quoted 4 lines
drivers/iio/chemical/scd30_core.c +3 -1
-	mutex_init(&state->lock);
+	ret = devm_mutex_init(dev, &state->lock);
+	if (ret)
+		return ret;
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#2 lore raw
Quoted 6 lines · On Sat, 6 Jun 2026 08:58:20 +0300 Andy Shevchenko…
Quoted 4 lines · Maxwell Doose

The current code uses mutex_init() instead of devm_mutex_init(), which is incorrect as the rest of the file uses the devm automatic resource management API. Fix this so that the mutex is set up in the same way as the rest of the device data structure.

Quoted 9 lines

...

drivers/iio/chemical/scd30_core.c int scd30_probe(struct device *dev, int irq, const char *name, void *priv, · line 716

Quoted 2 lines
drivers/iio/chemical/scd30_core.c +0 -0
 	state->meas_interval = SCD30_MEAS_INTERVAL_DEFAULT;
 	state->command = command;  

+ blank line here.

Tweaked and applied.

Quoted 5 lines
Quoted 4 lines
drivers/iio/chemical/scd30_core.c +3 -1
-	mutex_init(&state->lock);
+	ret = devm_mutex_init(dev, &state->lock);
+	if (ret)
+		return ret;