* [PATCH 0/3] iio: accel: adxl313: small cleanups and error-handling improvements
@ 2026-04-16 5:16 Sanjay Chitroda
2026-04-16 5:16 ` [PATCH 1/3] iio: accel: adxl313_core: Use devm-managed mutex initialization Sanjay Chitroda
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Sanjay Chitroda @ 2026-04-16 5:16 UTC (permalink / raw)
To: lucas.p.stankus, lars, Michael.Hennerich, jic23
Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
From: Sanjay Chitroda <sanjayembeddedse@gmail.com>
Hi all,
This series contains a few small cleanups and robustness improvements
to the ADXL313 IIO accelerometer driver.
The changes modernize mutex handling using devm-managed helpers and
guard() to simplify locking logic and improve safety. In addition,
error handling during probe is cleaned up by switching to dev_err_probe()
to better handle deferred probing and avoid repeated log noise.
No functional changes are intended.
Testing:
- Compiled with W=1
- Build-tested on QEMU x86_64
Based on:
<linux-v7.0-rc7>
Thanks,
Sanjay Chitroda
Sanjay Chitroda (3):
iio: accel: adxl313_core: Use devm-managed mutex initialization
iio: accel: adxl313_core: use guard() to release mutex
iio: accel: adxl313: Use dev_err_probe
drivers/iio/accel/adxl313_core.c | 20 ++++++++------------
drivers/iio/accel/adxl313_i2c.c | 8 +++-----
drivers/iio/accel/adxl313_spi.c | 8 +++-----
3 files changed, 14 insertions(+), 22 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/3] iio: accel: adxl313_core: Use devm-managed mutex initialization
2026-04-16 5:16 [PATCH 0/3] iio: accel: adxl313: small cleanups and error-handling improvements Sanjay Chitroda
@ 2026-04-16 5:16 ` Sanjay Chitroda
2026-04-16 8:25 ` Andy Shevchenko
2026-04-16 5:16 ` [PATCH 2/3] iio: accel: adxl313_core: use guard() to release mutex Sanjay Chitroda
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Sanjay Chitroda @ 2026-04-16 5:16 UTC (permalink / raw)
To: lucas.p.stankus, lars, Michael.Hennerich, jic23
Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
From: Sanjay Chitroda <sanjayembeddedse@gmail.com>
Use devm_mutex_init() to tie the mutex lifetime to the device and
improve debugging when CONFIG_DEBUG_MUTEXES is enabled.
Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
---
drivers/iio/accel/adxl313_core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/accel/adxl313_core.c b/drivers/iio/accel/adxl313_core.c
index 83dcac17a042..2ca4ce90cd86 100644
--- a/drivers/iio/accel/adxl313_core.c
+++ b/drivers/iio/accel/adxl313_core.c
@@ -1243,7 +1243,9 @@ int adxl313_core_probe(struct device *dev,
data->regmap = regmap;
data->chip_info = chip_info;
- mutex_init(&data->lock);
+ ret = devm_mutex_init(dev, &data->lock);
+ if (ret)
+ return ret;
indio_dev->name = chip_info->name;
indio_dev->info = &adxl313_info;
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/3] iio: accel: adxl313_core: use guard() to release mutex
2026-04-16 5:16 [PATCH 0/3] iio: accel: adxl313: small cleanups and error-handling improvements Sanjay Chitroda
2026-04-16 5:16 ` [PATCH 1/3] iio: accel: adxl313_core: Use devm-managed mutex initialization Sanjay Chitroda
@ 2026-04-16 5:16 ` Sanjay Chitroda
2026-04-16 8:22 ` Andy Shevchenko
2026-04-16 5:16 ` [PATCH 3/3] iio: accel: adxl313: Use dev_err_probe Sanjay Chitroda
2026-04-16 8:16 ` [PATCH 0/3] iio: accel: adxl313: small cleanups and error-handling improvements Andy Shevchenko
3 siblings, 1 reply; 10+ messages in thread
From: Sanjay Chitroda @ 2026-04-16 5:16 UTC (permalink / raw)
To: lucas.p.stankus, lars, Michael.Hennerich, jic23
Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
From: Sanjay Chitroda <sanjayembeddedse@gmail.com>
Replace explicit mutex_lock() and mutex_unlock() with the guard() macro
for cleaner and safer mutex handling.
Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
---
drivers/iio/accel/adxl313_core.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/accel/adxl313_core.c b/drivers/iio/accel/adxl313_core.c
index 2ca4ce90cd86..339570701083 100644
--- a/drivers/iio/accel/adxl313_core.c
+++ b/drivers/iio/accel/adxl313_core.c
@@ -356,19 +356,15 @@ static int adxl313_read_axis(struct adxl313_data *data,
{
int ret;
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
ret = regmap_bulk_read(data->regmap,
ADXL313_REG_DATA_AXIS(chan->address),
&data->transf_buf, sizeof(data->transf_buf));
if (ret)
- goto unlock_ret;
-
- ret = le16_to_cpu(data->transf_buf);
+ return ret;
-unlock_ret:
- mutex_unlock(&data->lock);
- return ret;
+ return le16_to_cpu(data->transf_buf);
}
static int adxl313_read_freq_avail(struct iio_dev *indio_dev,
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/3] iio: accel: adxl313: Use dev_err_probe
2026-04-16 5:16 [PATCH 0/3] iio: accel: adxl313: small cleanups and error-handling improvements Sanjay Chitroda
2026-04-16 5:16 ` [PATCH 1/3] iio: accel: adxl313_core: Use devm-managed mutex initialization Sanjay Chitroda
2026-04-16 5:16 ` [PATCH 2/3] iio: accel: adxl313_core: use guard() to release mutex Sanjay Chitroda
@ 2026-04-16 5:16 ` Sanjay Chitroda
2026-04-16 8:24 ` Andy Shevchenko
2026-04-16 8:16 ` [PATCH 0/3] iio: accel: adxl313: small cleanups and error-handling improvements Andy Shevchenko
3 siblings, 1 reply; 10+ messages in thread
From: Sanjay Chitroda @ 2026-04-16 5:16 UTC (permalink / raw)
To: lucas.p.stankus, lars, Michael.Hennerich, jic23
Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
From: Sanjay Chitroda <sanjayembeddedse@gmail.com>
dev_err_probe() makes error code handling simpler and handle
deferred probe nicely (avoid spamming logs).
Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
---
drivers/iio/accel/adxl313_core.c | 6 ++----
drivers/iio/accel/adxl313_i2c.c | 8 +++-----
drivers/iio/accel/adxl313_spi.c | 8 +++-----
3 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/drivers/iio/accel/adxl313_core.c b/drivers/iio/accel/adxl313_core.c
index 339570701083..1e9df5702de4 100644
--- a/drivers/iio/accel/adxl313_core.c
+++ b/drivers/iio/accel/adxl313_core.c
@@ -1251,10 +1251,8 @@ int adxl313_core_probe(struct device *dev,
indio_dev->available_scan_masks = adxl313_scan_masks;
ret = adxl313_setup(dev, data, setup);
- if (ret) {
- dev_err(dev, "ADXL313 setup failed\n");
- return ret;
- }
+ if (ret)
+ return dev_err_probe(dev, ret, "ADXL313 setup failed\n");
int_line = adxl313_get_int_type(dev, &irq);
if (int_line == ADXL313_INT_NONE) {
diff --git a/drivers/iio/accel/adxl313_i2c.c b/drivers/iio/accel/adxl313_i2c.c
index b67ff0b4dc54..896d6ee8a3ef 100644
--- a/drivers/iio/accel/adxl313_i2c.c
+++ b/drivers/iio/accel/adxl313_i2c.c
@@ -75,11 +75,9 @@ static int adxl313_i2c_probe(struct i2c_client *client)
regmap = devm_regmap_init_i2c(client,
&adxl31x_i2c_regmap_config[chip_data->type]);
- if (IS_ERR(regmap)) {
- dev_err(&client->dev, "Error initializing i2c regmap: %ld\n",
- PTR_ERR(regmap));
- return PTR_ERR(regmap);
- }
+ if (IS_ERR(regmap))
+ return dev_err_probe(&client->dev, PTR_ERR(regmap),
+ "Error initializing i2c regmap\n");
return adxl313_core_probe(&client->dev, regmap, chip_data, NULL);
}
diff --git a/drivers/iio/accel/adxl313_spi.c b/drivers/iio/accel/adxl313_spi.c
index dedb0885c277..6a0deea2209f 100644
--- a/drivers/iio/accel/adxl313_spi.c
+++ b/drivers/iio/accel/adxl313_spi.c
@@ -83,11 +83,9 @@ static int adxl313_spi_probe(struct spi_device *spi)
regmap = devm_regmap_init_spi(spi,
&adxl31x_spi_regmap_config[chip_data->type]);
- if (IS_ERR(regmap)) {
- dev_err(&spi->dev, "Error initializing spi regmap: %ld\n",
- PTR_ERR(regmap));
- return PTR_ERR(regmap);
- }
+ if (IS_ERR(regmap))
+ return dev_err_probe(&spi->dev, PTR_ERR(regmap),
+ "Error initializing spi regmap\n");
return adxl313_core_probe(&spi->dev, regmap,
chip_data, &adxl313_spi_setup);
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 0/3] iio: accel: adxl313: small cleanups and error-handling improvements
2026-04-16 5:16 [PATCH 0/3] iio: accel: adxl313: small cleanups and error-handling improvements Sanjay Chitroda
` (2 preceding siblings ...)
2026-04-16 5:16 ` [PATCH 3/3] iio: accel: adxl313: Use dev_err_probe Sanjay Chitroda
@ 2026-04-16 8:16 ` Andy Shevchenko
3 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2026-04-16 8:16 UTC (permalink / raw)
To: Sanjay Chitroda
Cc: lucas.p.stankus, lars, Michael.Hennerich, jic23, dlechner,
nuno.sa, andy, linux-iio, linux-kernel
On Thu, Apr 16, 2026 at 10:46:28AM +0530, Sanjay Chitroda wrote:
>
> This series contains a few small cleanups and robustness improvements
> to the ADXL313 IIO accelerometer driver.
>
> The changes modernize mutex handling using devm-managed helpers and
> guard() to simplify locking logic and improve safety. In addition,
> error handling during probe is cleaned up by switching to dev_err_probe()
> to better handle deferred probing and avoid repeated log noise.
>
> No functional changes are intended.
>
> Testing:
> - Compiled with W=1
> - Build-tested on QEMU x86_64
> Based on:
> <linux-v7.0-rc7>
Use --base instead of this comment (comment may be left untouched, of course,
but --base gives a hint to CIs and other tools.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/3] iio: accel: adxl313_core: use guard() to release mutex
2026-04-16 5:16 ` [PATCH 2/3] iio: accel: adxl313_core: use guard() to release mutex Sanjay Chitroda
@ 2026-04-16 8:22 ` Andy Shevchenko
2026-04-16 18:22 ` Sanjay Chitroda
0 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2026-04-16 8:22 UTC (permalink / raw)
To: Sanjay Chitroda
Cc: lucas.p.stankus, lars, Michael.Hennerich, jic23, dlechner,
nuno.sa, andy, linux-iio, linux-kernel
On Thu, Apr 16, 2026 at 10:46:30AM +0530, Sanjay Chitroda wrote:
> Replace explicit mutex_lock() and mutex_unlock() with the guard() macro
> for cleaner and safer mutex handling.
You missed two things:
- cleanup.h
- the patch is already in tree
Please, always use the tip of the respective subsystem treer
(it's usually iio/testing for IIO).
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/3] iio: accel: adxl313: Use dev_err_probe
2026-04-16 5:16 ` [PATCH 3/3] iio: accel: adxl313: Use dev_err_probe Sanjay Chitroda
@ 2026-04-16 8:24 ` Andy Shevchenko
2026-04-16 19:41 ` Sanjay Chitroda
0 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2026-04-16 8:24 UTC (permalink / raw)
To: Sanjay Chitroda
Cc: lucas.p.stankus, lars, Michael.Hennerich, jic23, dlechner,
nuno.sa, andy, linux-iio, linux-kernel
On Thu, Apr 16, 2026 at 10:46:31AM +0530, Sanjay Chitroda wrote:
> dev_err_probe() makes error code handling simpler and handle
> deferred probe nicely (avoid spamming logs).
...
> regmap = devm_regmap_init_i2c(client,
> &adxl31x_i2c_regmap_config[chip_data->type]);
> - if (IS_ERR(regmap)) {
> - dev_err(&client->dev, "Error initializing i2c regmap: %ld\n",
> - PTR_ERR(regmap));
> - return PTR_ERR(regmap);
> - }
> + if (IS_ERR(regmap))
> + return dev_err_probe(&client->dev, PTR_ERR(regmap),
> + "Error initializing i2c regmap\n");
Add
struct device *dev = &client->dev;
to the top of the function and use it here as
if (IS_ERR(regmap))
return dev_err_probe(dev, PTR_ERR(regmap), "Error initializing i2c regmap\n");
Note, it's fine to have trailing string literals, even in strict mode
checkpatch won't complain.
...
> - if (IS_ERR(regmap)) {
> - dev_err(&spi->dev, "Error initializing spi regmap: %ld\n",
> - PTR_ERR(regmap));
> - return PTR_ERR(regmap);
> - }
> + if (IS_ERR(regmap))
> + return dev_err_probe(&spi->dev, PTR_ERR(regmap),
> + "Error initializing spi regmap\n");
Same way as in I2C driver.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] iio: accel: adxl313_core: Use devm-managed mutex initialization
2026-04-16 5:16 ` [PATCH 1/3] iio: accel: adxl313_core: Use devm-managed mutex initialization Sanjay Chitroda
@ 2026-04-16 8:25 ` Andy Shevchenko
0 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2026-04-16 8:25 UTC (permalink / raw)
To: Sanjay Chitroda
Cc: lucas.p.stankus, lars, Michael.Hennerich, jic23, dlechner,
nuno.sa, andy, linux-iio, linux-kernel
On Thu, Apr 16, 2026 at 10:46:29AM +0530, Sanjay Chitroda wrote:
> Use devm_mutex_init() to tie the mutex lifetime to the device and
> improve debugging when CONFIG_DEBUG_MUTEXES is enabled.
This one valid.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/3] iio: accel: adxl313_core: use guard() to release mutex
2026-04-16 8:22 ` Andy Shevchenko
@ 2026-04-16 18:22 ` Sanjay Chitroda
0 siblings, 0 replies; 10+ messages in thread
From: Sanjay Chitroda @ 2026-04-16 18:22 UTC (permalink / raw)
To: Andy Shevchenko
Cc: lucas.p.stankus, lars, Michael.Hennerich, jic23, dlechner,
nuno.sa, andy, linux-iio, linux-kernel
On 16 April 2026 1:52:09 pm IST, Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
>On Thu, Apr 16, 2026 at 10:46:30AM +0530, Sanjay Chitroda wrote:
>
>> Replace explicit mutex_lock() and mutex_unlock() with the guard() macro
>> for cleaner and safer mutex handling.
>
>You missed two things:
>- cleanup.h
>- the patch is already in tree
>
>Please, always use the tip of the respective subsystem treer
>(it's usually iio/testing for IIO).
>
Thank you for the input.
Understood, I will always use iio/testing for further development.
I have dropped this change.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/3] iio: accel: adxl313: Use dev_err_probe
2026-04-16 8:24 ` Andy Shevchenko
@ 2026-04-16 19:41 ` Sanjay Chitroda
0 siblings, 0 replies; 10+ messages in thread
From: Sanjay Chitroda @ 2026-04-16 19:41 UTC (permalink / raw)
To: Andy Shevchenko
Cc: lucas.p.stankus, lars, Michael.Hennerich, jic23, dlechner,
nuno.sa, andy, linux-iio, linux-kernel
On 16 April 2026 1:54:47 pm IST, Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
>On Thu, Apr 16, 2026 at 10:46:31AM +0530, Sanjay Chitroda wrote:
>
>> dev_err_probe() makes error code handling simpler and handle
>> deferred probe nicely (avoid spamming logs).
>
>...
>
>> regmap = devm_regmap_init_i2c(client,
>> &adxl31x_i2c_regmap_config[chip_data->type]);
>> - if (IS_ERR(regmap)) {
>> - dev_err(&client->dev, "Error initializing i2c regmap: %ld\n",
>> - PTR_ERR(regmap));
>> - return PTR_ERR(regmap);
>> - }
>> + if (IS_ERR(regmap))
>> + return dev_err_probe(&client->dev, PTR_ERR(regmap),
>> + "Error initializing i2c regmap\n");
>
>Add
>
> struct device *dev = &client->dev;
>
>to the top of the function and use it here as
>
> if (IS_ERR(regmap))
> return dev_err_probe(dev, PTR_ERR(regmap), "Error initializing i2c regmap\n");
>
>Note, it's fine to have trailing string literals, even in strict mode
>checkpatch won't complain.
>
>...
Thank you Andy for the input.
I will address review comment in next series. Also, string literals is under 100 after the dev changes so keeping single line for both i2c & spi.
>
>> - if (IS_ERR(regmap)) {
>> - dev_err(&spi->dev, "Error initializing spi regmap: %ld\n",
>> - PTR_ERR(regmap));
>> - return PTR_ERR(regmap);
>> - }
>> + if (IS_ERR(regmap))
>> + return dev_err_probe(&spi->dev, PTR_ERR(regmap),
>> + "Error initializing spi regmap\n");
>
>Same way as in I2C driver.
>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-04-16 19:42 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-16 5:16 [PATCH 0/3] iio: accel: adxl313: small cleanups and error-handling improvements Sanjay Chitroda
2026-04-16 5:16 ` [PATCH 1/3] iio: accel: adxl313_core: Use devm-managed mutex initialization Sanjay Chitroda
2026-04-16 8:25 ` Andy Shevchenko
2026-04-16 5:16 ` [PATCH 2/3] iio: accel: adxl313_core: use guard() to release mutex Sanjay Chitroda
2026-04-16 8:22 ` Andy Shevchenko
2026-04-16 18:22 ` Sanjay Chitroda
2026-04-16 5:16 ` [PATCH 3/3] iio: accel: adxl313: Use dev_err_probe Sanjay Chitroda
2026-04-16 8:24 ` Andy Shevchenko
2026-04-16 19:41 ` Sanjay Chitroda
2026-04-16 8:16 ` [PATCH 0/3] iio: accel: adxl313: small cleanups and error-handling improvements Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox