iio: chemical: scd30: Use devm_mutex_init() over non-devm mutex_init()
Subsystems (2)
PATCH v2 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.
---
v2:
- Drop fixes tag per Jonathan's suggestion.
- Replace dev_err_probe() with return -ENOMEM per Jonathan and Andy's suggestions.
drivers/iio/chemical/scd30_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/iio/chemical/scd30_core.c +4 -1
@@ -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 -ENOMEM ; +init_completion (&state->meas_ready);dev_set_drvdata (dev, indio_dev);
Signature · 1 line
2.54.0
Quoted 8 lines · Maxwell Doose
The current code uses
mutex_init()instead ofdevm_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.Signed-off-by Maxwell Doose <[email protected]>---
David Lechner
reviewerQuoted 21 lines · Maxwell Doose
The current code uses
mutex_init()instead ofdevm_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.Signed-off-by Maxwell Doose <[email protected]>---
v2:
- Drop fixes tag per Jonathan's suggestion.
- Replacedev_err_probe()with return-ENOMEMper Jonathan and Andy's suggestions.drivers/iio/chemical/scd30_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/iio/chemical/scd30_core.c +0
-0
drivers/iio/chemical/scd30_core.c int scd30_probe(struct device *dev, int irq, const char *name, void *priv, · line 719
Quoted 7 lines
drivers/iio/chemical/scd30_core.c +3
-1@@ -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 -ENOMEM ;
Why are we ignoring ret?
I would expect:
return ret;
Quoted 7 lines
drivers/iio/chemical/scd30_core.c +1
-1+init_completion (&state->meas_ready);dev_set_drvdata (dev, indio_dev); --2.54.0
Quoted 33 lines · David Lechner
Quoted 21 lines · Maxwell Doose
The current code uses
mutex_init()instead ofdevm_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.Signed-off-by Maxwell Doose <[email protected]>---
v2:
- Drop fixes tag per Jonathan's suggestion.
- Replacedev_err_probe()with return-ENOMEMper Jonathan and Andy's suggestions.drivers/iio/chemical/scd30_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/iio/chemical/scd30_core.c +0
-0drivers/iio/chemical/scd30_core.c int scd30_probe(struct device *dev, int irq, const char *name, void *priv, · line 719
Quoted 7 lines
drivers/iio/chemical/scd30_core.c +3
-1@@ -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 -ENOMEM ;Why are we ignoring ret?
Quoted 4 lines
I would expect:
return ret;
Gah, I must've Jonathan's + Andy's comments get to my head (He said it should likely only return -ENOMEM) :(
I don't know if he'll want to tweak while applying or if I should just go back and resubmit.
Quoted 2 lines · Maxwell Doose
Quoted 1 line · David Lechner
On Thu, Jun 4, 2026 at 3:17 PM Maxwell Doose <[email protected]> wrote:
...
Quoted 6 lines
Quoted 6 lines
drivers/iio/chemical/scd30_core.c int scd30_probe(struct device *dev, int irq, const char *name, void *priv, · line 719
Quoted 3 lines
drivers/iio/chemical/scd30_core.c +3
-0+ ret =devm_mutex_init (dev, &state->lock); +if (ret) +return -ENOMEM ;Why are we ignoring ret?
Quoted 8 lines
Quoted 3 lines
I would expect:
return ret;Gah, I must've Jonathan's + Andy's comments get to my head (He said it should likely only return
-ENOMEM) :(
I don't know if he'll want to tweak while applying or if I should just go back and resubmit.
What we meant is that:
- devm_mutex_init() may return only -ENOMEM as of today
- dev_err_probe() will ignore (print nothing) when err == -ENOMEM
It has nothing to do with the caller, we explained how callee do. TL;DR: it should be simple return ret; as Jonathan said already.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 36 lines · On Thu, 4 Jun 2026 11:21:07 -0500 Maxwell Doose <[email protected]> wrote:
Quoted 35 lines · David Lechner
Quoted 21 lines · Maxwell Doose
The current code uses
mutex_init()instead ofdevm_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.Signed-off-by Maxwell Doose <[email protected]>---
v2:
- Drop fixes tag per Jonathan's suggestion.
- Replacedev_err_probe()with return-ENOMEMper Jonathan and Andy's suggestions.drivers/iio/chemical/scd30_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/iio/chemical/scd30_core.c +0
-0drivers/iio/chemical/scd30_core.c int scd30_probe(struct device *dev, int irq, const char *name, void *priv, · line 719
Quoted 7 lines
drivers/iio/chemical/scd30_core.c +3
-1@@ -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 -ENOMEM ;Why are we ignoring ret?
I would expect:
Quoted 7 lines
Quoted 2 lines
return ret;Gah, I must've Jonathan's + Andy's comments get to my head (He said it should likely only return
-ENOMEM) :(
I don't know if he'll want to tweak while applying or if I should just go back and resubmit.
IIO is effectively closed for this cycle so plenty of time and I'm lazy so please send a v3.
Jonathan