iio: accel: adxl313: small cleanups and error-handling improvements
cover iio: accel: adxl313: small cleanups and error-handling improvements
From: Sanjay Chitroda <[email protected]>
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(-)
Signature · 1 line
2.34.1
PATCH 1/3 iio: accel: adxl313_core: Use devm-managed mutex initialization
From: Sanjay Chitroda <[email protected]>
Use devm_mutex_init() to tie the mutex lifetime to the device and improve debugging when CONFIG_DEBUG_MUTEXES is enabled.
--- drivers/iio/accel/adxl313_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/accel/adxl313_core.c +3 -1
@@ -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;
Signature · 1 line
2.34.1
Re: [PATCH 1/3] iio: accel: adxl313_core: Use devm-managed mutex initialization
Quoted 2 lines · Sanjay Chitroda
Use
devm_mutex_init()to tie the mutex lifetime to the device and improve debugging whenCONFIG_DEBUG_MUTEXESis enabled.
This one valid.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 2/3 iio: accel: adxl313_core: use guard() to release mutex
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
Replace explicit mutex_lock() and mutex_unlock() with the guard() macro for cleaner and safer mutex handling.
--- drivers/iio/accel/adxl313_core.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/iio/accel/adxl313_core.c +3 -7
@@ -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,
Signature · 1 line
2.34.1
Re: [PATCH 2/3] iio: accel: adxl313_core: use guard() to release mutex
Quoted 2 lines · Sanjay Chitroda
Replace explicit
mutex_lock()andmutex_unlock()with theguard()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).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/3] iio: accel: adxl313_core: use guard() to release mutex
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Sanjay Chitroda
Replace explicit
mutex_lock()andmutex_unlock()with theguard()macro for cleaner and safer mutex handling.
Quoted 7 lines
You missed two things:
-cleanup.h
- the patch is already in treePlease, 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.
PATCH 3/3 iio: accel: adxl313: Use dev_err_probe
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
dev_err_probe() makes error code handling simpler and handle deferred probe nicely (avoid spamming logs).
--- 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(-)
drivers/iio/accel/adxl313_core.c +2 -4
@@ -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 ) {
drivers/iio/accel/adxl313_i2c.c +3 -5
@@ -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 ); }
drivers/iio/accel/adxl313_spi.c +3 -5
@@ -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);
Signature · 1 line
2.34.1
Re: [PATCH 3/3] iio: accel: adxl313: Use dev_err_probe
Quoted 2 lines · Sanjay Chitroda
dev_err_probe()makes error code handling simpler and handle deferred probe nicely (avoid spamming logs).
...
drivers/iio/accel/adxl313_i2c.c static int adxl313_i2c_probe(struct i2c_client *client) · line 80
Quoted 10 lines
drivers/iio/accel/adxl313_i2c.c +3
-5regmap =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.
...
drivers/iio/accel/adxl313_spi.c static int adxl313_spi_probe(struct spi_device *spi) · line 88
Quoted 8 lines
drivers/iio/accel/adxl313_spi.c +3
-5-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.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 3/3] iio: accel: adxl313: Use dev_err_probe
Quoted 24 lines · Andy Shevchenko
Quoted 2 lines · Sanjay Chitroda
dev_err_probe()makes error code handling simpler and handle deferred probe nicely (avoid spamming logs)....
drivers/iio/accel/adxl313_i2c.c static int adxl313_i2c_probe(struct i2c_client *client) · line 80
Quoted 10 lines
drivers/iio/accel/adxl313_i2c.c +3
-5regmap =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
Quoted 7 lines
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.
Quoted 12 lines
drivers/iio/accel/adxl313_spi.c static int adxl313_spi_probe(struct spi_device *spi) · line 88
Quoted 9 lines
drivers/iio/accel/adxl313_spi.c +3
-5-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.
Quoted 9 lines · Sanjay Chitroda
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 todev_err_probe()to better handle deferred probing and avoid repeated log noise.
Quoted 8 lines
No functional changes are intended.
Testing:
- Compiled with W=1
- Build-tested on QEMUx86_64Based 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.
Signature · 2 lines
With Best Regards, Andy Shevchenko