iio: accel: mma8452: improve coding style, pm and resource cleanup
v3 cover iio: accel: mma8452: improve coding style, pm and resource cleanup
From: Sanjay Chitroda <[email protected]>
Hi all,
This series contains a small fixes, cleanup and improvements to use modern kernel helper API and coding style for mma8452 accel driver.
The changes modernize mutex with guard(), dev_err_probe usage, resolve checkpatch CHECKS and pm_ptr macro usage.
Changes in v3:
- Following input from Andy and Jonathan added new changes as following 0001: handle return value to have proper error propagation
0002: use non-devm API to maintain resource management LIFO order
0006: convert individual regulator using bulk regulator API
0009: use IIO cleanup helper for DIRECT_MODE
- Address kernel coding stype specific review comment
- Reorder local struct device and dev_err_probe change
v2 series -> https://lore.kernel.org/all/[email protected]/
Changes in v2:
- 0005: address review comment from Andy and Geert
and use DEFINE_RUNTIME_DEV_PM_OPS macro
- Added new cleanup channges in mma8452 driver
No functional behavior changes are intended.
Testing:
- Compiled with W=1
- Build-tested on QEMU x86_64
Feedback and reviews are very welcome.
Thanks,
Sanjay Chitroda
Sanjay Chitroda (10):
iio: accel: mma8452: handle I2C read error(s) in mma8452_read()
iio: accel: mma8452: switch to non-devm request_threaded_irq()
iio: accel: mma8452: cleanup codestyle warning
iio: accel: mma8452: sort headers alphabetically
iio: accel: mma8452: Use dev_err_probe()
iio: accel: mma8452: convert to bulk regulator usage
iio: accel: mma8452: use local struct device
iio: accel: mma8452: use pm_ptr() and direct runtime PM calls
iio: accel: mma8452: Use IIO cleanup helpers
iio: accel: mma8452: use guard() to release mutexes
drivers/iio/accel/mma8452.c | 278 +++++++++++++++--------------------- 1 file changed, 116 insertions(+), 162 deletions(-)
base-commit: 39b80c5c9830d12d2d6531059001301c4265322a
Signature · 1 line
2.34.1
PATCH v3 1/10 iio: accel: mma8452: handle I2C read error(s) in mma8452_read()
From: Sanjay Chitroda <[email protected]>
Currently, If i2c_smbus_read_i2c_block_data() fails but mma8452_set_runtime_pm_state() succeeds, mma8452_read() returns 0.
As a result, the caller mma8452_read_raw() assumes the read was successful and proceeds to use a buffer containing uninitialized stack memory.
Add proper checking of the I2C read return value and propagate errors to the caller.
--- drivers/iio/accel/mma8452.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/accel/mma8452.c +2 -0
@@ -252,6 +252,8 @@ static int mma8452_read(struct mma8452_data *data, __be16 buf[3]) ret =i2c_smbus_read_i2c_block_data (data->client,MMA8452_OUT_X ,3 *sizeof (__be16), (u8 *)buf); +if (ret <0 ) +return ret; ret =mma8452_set_runtime_pm_state (data->client, false);
Signature · 1 line
2.34.1
Jonathan Cameron
maintainerRe: [PATCH v3 01/10] iio: accel: mma8452: handle I2C read error(s) in mma8452_read()
Quoted 9 lines · On Tue, 5 May 2026 23:16:31 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Currently, If
i2c_smbus_read_i2c_block_data()fails butmma8452_set_runtime_pm_state()succeeds,mma8452_read()returns 0.As a result, the caller
mma8452_read_raw()assumes the read was successful and proceeds to use a buffer containing uninitialized stack memory.
Quoted 5 lines
Add proper checking of the I2C read return value and propagate errors to the caller.
Fixes 96c0cb2bbfe0 ("iio: mma8452: add support for runtime power management")Signed-off-by Sanjay Chitroda <[email protected]>
Given we don't have reports of this causing trouble and the load of patches queued up for the driver, I'll take this the slow way
Applied to the testing branch of iio.git.
Quoted 17 lines
--- drivers/iio/accel/mma8452.c | 2 ++ 1 file changed, 2 insertions(+)drivers/iio/accel/mma8452.c +2
-0@@ -252,6 +252,8 @@ static int mma8452_read(struct mma8452_data *data, __be16 buf[3]) ret =i2c_smbus_read_i2c_block_data (data->client,MMA8452_OUT_X ,3 *sizeof (__be16), (u8 *)buf); +if (ret <0 ) +return ret; ret =mma8452_set_runtime_pm_state (data->client, false);
PATCH v3 2/10 iio: accel: mma8452: switch to non-devm request_threaded_irq()
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
Avoid using devm_request_threaded_irq() as the driver requires explicit error-handling path(s). Using devm_* API together with goto-based unwinding breaks the expected LIFO resource release model.
Add explicit IRQ cleanup in the driver teardown paths to follow kernel resource management conventions.
--- drivers/iio/accel/mma8452.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/iio/accel/mma8452.c +12 -7
@@ -1682,18 +1682,16 @@ static int mma8452_probe(struct i2c_client *client) goto trigger_cleanup;if (client->irq) { - ret =devm_request_threaded_irq (&client->dev, - client->irq, -NULL , mma8452_interrupt, -IRQF_TRIGGER_LOW |IRQF_ONESHOT , - client->name, indio_dev); + ret =request_threaded_irq (client->irq,NULL , mma8452_interrupt, +IRQF_TRIGGER_LOW |IRQF_ONESHOT , + client->name, indio_dev);if (ret) goto buffer_cleanup; } ret =pm_runtime_set_active (&client->dev);if (ret <0 ) - goto buffer_cleanup; + goto free_irq;pm_runtime_enable (&client->dev); pm_runtime_set_autosuspend_delay(&client->dev,
@@ -1702,7 +1700,7 @@ static int mma8452_probe(struct i2c_client *client) ret =iio_device_register (indio_dev);if (ret <0 ) - goto buffer_cleanup; + goto free_irq; ret =mma8452_set_freefall_mode (data, false);if (ret <0 )
@@ -1713,6 +1711,10 @@ static int mma8452_probe(struct i2c_client *client) unregister_device:iio_device_unregister (indio_dev); +free_irq: +if (client->irq) +free_irq (client->irq, indio_dev); + buffer_cleanup:iio_triggered_buffer_cleanup (indio_dev);
@@ -1738,6 +1740,9 @@ static void mma8452_remove(struct i2c_client *client)pm_runtime_disable (&client->dev);pm_runtime_set_suspended (&client->dev); +if (client->irq) +free_irq (client->irq, indio_dev); +iio_triggered_buffer_cleanup (indio_dev);mma8452_trigger_cleanup (indio_dev);mma8452_standby (iio_priv (indio_dev));
Signature · 1 line
2.34.1
Jonathan Cameron
maintainerRe: [PATCH v3 02/10] iio: accel: mma8452: switch to non-devm request_threaded_irq()
Quoted 10 lines · On Tue, 5 May 2026 23:16:32 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Avoid using
devm_request_threaded_irq()as the driver requires explicit error-handling path(s). Using devm_* API together with goto-based unwinding breaks the expected LIFO resource release model.Add explicit IRQ cleanup in the driver teardown paths to follow kernel resource management conventions.
Fixes 28e3427824cc ("iio: mma8452: Basic support for transient events.")
For a fixes tag we need to have an explicit issue rather than it not following best practice. Patch itself is correct, and if all else is good and you don't have a specific ordering problem in mind I'll just drop the fixes tag whilst applying.
Quoted 62 lines
Signed-off-by Sanjay Chitroda <[email protected]>--- drivers/iio/accel/mma8452.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)drivers/iio/accel/mma8452.c +12
-7@@ -1682,18 +1682,16 @@ static int mma8452_probe(struct i2c_client *client) goto trigger_cleanup;if (client->irq) { - ret =devm_request_threaded_irq (&client->dev, - client->irq, -NULL , mma8452_interrupt, -IRQF_TRIGGER_LOW |IRQF_ONESHOT , - client->name, indio_dev); + ret =request_threaded_irq (client->irq,NULL , mma8452_interrupt, +IRQF_TRIGGER_LOW |IRQF_ONESHOT , + client->name, indio_dev);if (ret) goto buffer_cleanup; } ret =pm_runtime_set_active (&client->dev);if (ret <0 ) - goto buffer_cleanup; + goto free_irq;pm_runtime_enable (&client->dev); pm_runtime_set_autosuspend_delay(&client->dev,@@ -1702,7 +1700,7 @@ static int mma8452_probe(struct i2c_client *client) ret =iio_device_register (indio_dev);if (ret <0 ) - goto buffer_cleanup; + goto free_irq; ret =mma8452_set_freefall_mode (data, false);if (ret <0 )@@ -1713,6 +1711,10 @@ static int mma8452_probe(struct i2c_client *client) unregister_device:iio_device_unregister (indio_dev); +free_irq: +if (client->irq) +free_irq (client->irq, indio_dev); + buffer_cleanup:iio_triggered_buffer_cleanup (indio_dev);@@ -1738,6 +1740,9 @@ static void mma8452_remove(struct i2c_client *client)pm_runtime_disable (&client->dev);pm_runtime_set_suspended (&client->dev); +if (client->irq) +free_irq (client->irq, indio_dev); +iio_triggered_buffer_cleanup (indio_dev);mma8452_trigger_cleanup (indio_dev);mma8452_standby (iio_priv (indio_dev));
Jonathan Cameron
maintainerRe: [PATCH v3 02/10] iio: accel: mma8452: switch to non-devm request_threaded_irq()
Quoted 9 lines · On Wed, 6 May 2026 18:47:49 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 6 lines · On Tue, 5 May 2026 23:16:32 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Avoid using
devm_request_threaded_irq()as the driver requires explicit error-handling path(s). Using devm_* API together with goto-based unwinding breaks the expected LIFO resource release model.
Quoted 8 lines
Quoted 4 lines
Add explicit IRQ cleanup in the driver teardown paths to follow kernel resource management conventions.
Fixes 28e3427824cc ("iio: mma8452: Basic support for transient events.")For a fixes tag we need to have an explicit issue rather than it not following best practice. Patch itself is correct, and if all else is good and you don't have a specific ordering problem in mind I'll just drop the fixes tag whilst applying.
Applied to testing with the fixes tag dropped.
Thanks,
J
PATCH v3 3/10 iio: accel: mma8452: cleanup codestyle warning
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
Reported by checkpatch:
FILE: drivers/iio/accel/mma8452.c
CHECK: Alignment should match open parenthesis
--- drivers/iio/accel/mma8452.c | 47 +++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 23 deletions(-)
drivers/iio/accel/mma8452.c +24 -23
@@ -706,8 +706,8 @@ static int mma8452_set_hp_filter_frequency(struct mma8452_data *data, }static int __mma8452_write_raw (struct iio_dev *indio_dev, -struct iio_chan_spec const *chan, -int val,int val2,long mask) +struct iio_chan_spec const *chan, +int val,int val2,long mask) {struct mma8452_data *data =iio_priv (indio_dev);int i, j, ret;
@@ -788,8 +788,9 @@ static int mma8452_write_raw(struct iio_dev *indio_dev, }static int mma8452_get_event_regs (struct mma8452_data *data, -const struct iio_chan_spec *chan,enum iio_event_direction dir, -const struct mma8452_event_regs **ev_reg) +const struct iio_chan_spec *chan, +enum iio_event_direction dir, +const struct mma8452_event_regs **ev_reg) {if (!chan)return -EINVAL ;
@@ -818,11 +819,11 @@ static int mma8452_get_event_regs(struct mma8452_data *data, }static int mma8452_read_event_value (struct iio_dev *indio_dev, -const struct iio_chan_spec *chan, -enum iio_event_type type, -enum iio_event_direction dir, -enum iio_event_info info, -int *val,int *val2) +const struct iio_chan_spec *chan, +enum iio_event_type type, +enum iio_event_direction dir, +enum iio_event_info info, +int *val,int *val2) {struct mma8452_data *data =iio_priv (indio_dev);int ret, us, power_mode;
@@ -881,11 +882,11 @@ static int mma8452_read_event_value(struct iio_dev *indio_dev, }static int mma8452_write_event_value (struct iio_dev *indio_dev, -const struct iio_chan_spec *chan, -enum iio_event_type type, -enum iio_event_direction dir, -enum iio_event_info info, -int val,int val2) +const struct iio_chan_spec *chan, +enum iio_event_type type, +enum iio_event_direction dir, +enum iio_event_info info, +int val,int val2) {struct mma8452_data *data =iio_priv (indio_dev);int ret, reg, steps;
@@ -955,8 +956,7 @@ static int mma8452_read_event_config(struct iio_dev *indio_dev,case IIO_EV_DIR_FALLING :return mma8452_freefall_mode_enabled (data);case IIO_EV_DIR_RISING : - ret =i2c_smbus_read_byte_data (data->client, - ev_regs->ev_cfg); + ret =i2c_smbus_read_byte_data (data->client, ev_regs->ev_cfg);if (ret <0 )return ret;
@@ -1193,7 +1193,7 @@ static const struct attribute_group mma8452_event_attribute_group = {static const struct iio_mount_matrix *mma8452_get_mount_matrix (const struct iio_dev *indio_dev, -const struct iio_chan_spec *chan) +const struct iio_chan_spec *chan) {struct mma8452_data *data =iio_priv (indio_dev);
@@ -1516,8 +1516,9 @@ static int mma8452_reset(struct i2c_client *client)* The following code will read the reset register, and check whether * this reset works. */ -i2c_smbus_write_byte_data (client,MMA8452_CTRL_REG2 , -MMA8452_CTRL_REG2_RST ); +i2c_smbus_write_byte_data (client, +MMA8452_CTRL_REG2 , +MMA8452_CTRL_REG2_RST );for (i =0 ; i <10 ; i++) {usleep_range (100 ,200 );
@@ -1647,8 +1648,8 @@ static int mma8452_probe(struct i2c_client *client)dev_dbg (&client->dev,"using interrupt line INT2\n" ); }else { ret =i2c_smbus_write_byte_data (client, -MMA8452_CTRL_REG5 , - data->chip_info->all_events); +MMA8452_CTRL_REG5 , + data->chip_info->all_events);if (ret <0 ) goto disable_regulators;
@@ -1656,8 +1657,8 @@ static int mma8452_probe(struct i2c_client *client) } ret =i2c_smbus_write_byte_data (client, -MMA8452_CTRL_REG4 , - data->chip_info->enabled_events); +MMA8452_CTRL_REG4 , + data->chip_info->enabled_events);if (ret <0 ) goto disable_regulators;
Signature · 1 line
2.34.1
Re: [PATCH v3 03/10] iio: accel: mma8452: cleanup codestyle warning
Quoted 18 lines · Sanjay Chitroda
From: Sanjay Chitroda <[email protected]>
Reported by checkpatch:
FILE:drivers/iio/accel/mma8452.cCHECK: Alignment should match open parenthesis
Signed-off-by Sanjay Chitroda <[email protected]>--- drivers/iio/accel/mma8452.c | 47 +++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 23 deletions(-)drivers/iio/accel/mma8452.c +0
-0
drivers/iio/accel/mma8452.c static int mma8452_set_hp_filter_frequency(struct mma8452_data *data, · line 710
Quoted 7 lines
drivers/iio/accel/mma8452.c +2
-2@@ -706,8 +706,8 @@ static int mma8452_set_hp_filter_frequency(struct mma8452_data *data, }static int __mma8452_write_raw (struct iio_dev *indio_dev, -struct iio_chan_spec const *chan, -int val,int val2,long mask) +struct iio_chan_spec const *chan, +int val,int val2,long mask)
This is still not aligned by 1 character, it should be aligned with the first character after the opening parenthesis.
drivers/iio/accel/mma8452.c static int mma8452_write_raw(struct iio_dev *indio_dev, · line 793
Quoted 12 lines
drivers/iio/accel/mma8452.c +3
-2{struct mma8452_data *data =iio_priv (indio_dev);int i, j, ret;@@ -788,8 +788,9 @@ static int mma8452_write_raw(struct iio_dev *indio_dev, }static int mma8452_get_event_regs (struct mma8452_data *data, -const struct iio_chan_spec *chan,enum iio_event_direction dir, -const struct mma8452_event_regs **ev_reg) +const struct iio_chan_spec *chan, +enum iio_event_direction dir, +const struct mma8452_event_regs **ev_reg)
Same here.
Quoted 7 lines
drivers/iio/accel/mma8452.c +0
-0{if (!chan)return -EINVAL ;@@ -818,11 +819,11 @@ static int mma8452_get_event_regs(struct mma8452_data *data, } static int mma8452_read_event_value(struct iio_dev *indio_dev,
drivers/iio/accel/mma8452.c static int mma8452_get_event_regs(struct mma8452_data *data, · line 826
Quoted 10 lines
drivers/iio/accel/mma8452.c +5
-5-const struct iio_chan_spec *chan, - enum iio_event_type type, - enum iio_event_direction dir, - enum iio_event_info info, - int *val, int *val2) +const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, + int *val, int *val2)
Same here.
Quoted 7 lines
drivers/iio/accel/mma8452.c +0
-0{struct mma8452_data *data =iio_priv (indio_dev);int ret, us, power_mode;@@ -881,11 +882,11 @@ static int mma8452_read_event_value(struct iio_dev *indio_dev, } static int mma8452_write_event_value(struct iio_dev *indio_dev,
drivers/iio/accel/mma8452.c static int mma8452_read_event_value(struct iio_dev *indio_dev, · line 889
Quoted 10 lines
drivers/iio/accel/mma8452.c +5
-5-const struct iio_chan_spec *chan, - enum iio_event_type type, - enum iio_event_direction dir, - enum iio_event_info info, - int val, int val2) +const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, + int val, int val2)
Same here.
The rest is correct though.
Signature · 3 lines
Kind regards CJD
Jonathan Cameron
maintainerRe: [PATCH v3 03/10] iio: accel: mma8452: cleanup codestyle warning
Quoted 21 lines · On Wed, 6 May 2026 11:24:25 +0200 Joshua Crofts <[email protected]>…
Quoted 20 lines · Sanjay Chitroda
From: Sanjay Chitroda <[email protected]>
Reported by checkpatch:
FILE:drivers/iio/accel/mma8452.cCHECK: Alignment should match open parenthesis
Signed-off-by Sanjay Chitroda <[email protected]>--- drivers/iio/accel/mma8452.c | 47 +++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 23 deletions(-)drivers/iio/accel/mma8452.c +0
-0@@ -706,8 +706,8 @@ static int mma8452_set_hp_filter_frequency(struct mma8452_data *data, }
Quoted 8 lines
drivers/iio/accel/mma8452.c static int mma8452_set_hp_filter_frequency(struct mma8452_data *data, · line 710
Quoted 5 lines
drivers/iio/accel/mma8452.c +2
-2static int __mma8452_write_raw (struct iio_dev *indio_dev, -struct iio_chan_spec const *chan, -int val,int val2,long mask) +struct iio_chan_spec const *chan, +int val,int val2,long mask)This is still not aligned by 1 character, it should be aligned with the first character after the opening parenthesis.
Hi Joshua,
Trap of reading patches in emails is that tabs and space combinations don't always look correct. Also your email client replaced them all with spaces to add more confusion ;)
From origin patch
static int __mma8452_write_raw(struct iio_dev *indio_dev,
- struct iio_chan_spec const *chan,
- int val, int val2, long mask)
+ struct iio_chan_spec const *chan,
+ int val, int val2, long mask)
{
With the leading chars removed removes one space from top line but nothing from the following ones as they have leading tabs.
So you get:
static int __mma8452_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int val, int val2, long mask)
{
So this is fine. I haven't checked the others but guess they are the same.
I frequently end up testing this by hand when I think indents are off and often turns out I'm wrong!
...
Quoted 2 lines
The rest is correct though.
They all have leading tabs on all lines.
Jonathan
Re: [PATCH v3 03/10] iio: accel: mma8452: cleanup codestyle warning
Quoted 30 lines · Jonathan Cameron
Quoted 2 lines
This is still not aligned by 1 character, it should be aligned with the first character after the opening parenthesis.
Hi Joshua,
Trap of reading patches in emails is that tabs and space combinations don't always look correct. Also your email client replaced them all with spaces to add more confusion ;)
From origin patch
static int __mma8452_write_raw(struct
iio_dev*indio_dev,drivers/iio/accel/mma8452.c +2
-2-struct iio_chan_spec const *chan, - int val, int val2, long mask) +struct iio_chan_spec const *chan, + int val, int val2, long mask) {With the leading chars removed removes one space from top line but nothing from the following ones as they have leading tabs.
So you get:
static int __mma8452_write_raw(struct
iio_dev*indio_dev,
structiio_chan_specconst *chan, int val, int val2, long mask)
{So this is fine. I haven't checked the others but guess they are the same.
Quoted 8 lines
I frequently end up testing this by hand when I think indents are off and often turns out I'm wrong!
...
Quoted 2 lines
The rest is correct though.
They all have leading tabs on all lines.
I guess nothing beats just applying the patch manually and checking in an editor. Thanks for the clarification - gmail really does mangle formatting horribly.
Signature · 3 lines
Kind regards CJD
Re: [PATCH v3 03/10] iio: accel: mma8452: cleanup codestyle warning
In reply to Sanjay ChitrodaQuoted 8 lines · On Tue, 5 May 2026 23:16:33 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Reported by checkpatch:
FILE:drivers/iio/accel/mma8452.cCHECK: Alignment should match open parenthesis
Signed-off-by Sanjay Chitroda <[email protected]>
Applied.
PATCH v3 4/10 iio: accel: mma8452: sort headers alphabetically
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
Sort include headers alphabetically to improve readability.
---
Changes in v3:
- Grouped regulator header with common linux header group
- Link to v2: https://lore.kernel.org/all/[email protected]/
--- drivers/iio/accel/mma8452.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/iio/accel/mma8452.c +9 -8
@@ -18,21 +18,22 @@* TODO: orientation events */ -#include <linux/module.h> +#include <linux/delay.h> +#include <linux/i2c.h> #include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/pm_runtime.h> #include <linux/property.h> -#include <linux/i2c.h> +#include <linux/types.h> +#include <linux/regulator/consumer.h> + +#include <linux/iio/buffer.h> +#include <linux/iio/events.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> -#include <linux/iio/buffer.h> #include <linux/iio/trigger.h> #include <linux/iio/trigger_consumer.h> #include <linux/iio/triggered_buffer.h> -#include <linux/iio/events.h> -#include <linux/delay.h> -#include <linux/pm_runtime.h> -#include <linux/regulator/consumer.h> -#include <linux/types.h> #define MMA8452_STATUS 0x00#define MMA8452_STATUS_DRDY (BIT(2) | BIT(1) | BIT(0))
Signature · 1 line
2.34.1
Re: [PATCH v3 04/10] iio: accel: mma8452: sort headers alphabetically
Quoted 6 lines · Sanjay Chitroda
From: Sanjay Chitroda <[email protected]>
Sort include headers alphabetically to improve readability.
Signed-off-by Sanjay Chitroda <[email protected]>
Signature · 3 lines
Kind regards CJD
Re: [PATCH v3 04/10] iio: accel: mma8452: sort headers alphabetically
Quoted 10 lines · On Wed, 6 May 2026 11:29:59 +0200 Joshua Crofts <[email protected]>…
Quoted 6 lines · Sanjay Chitroda
From: Sanjay Chitroda <[email protected]>
Sort include headers alphabetically to improve readability.
Signed-off-by Sanjay Chitroda <[email protected]>Reviewed-by Joshua Crofts <[email protected]>
Applied.
PATCH v3 5/10 iio: accel: mma8452: 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/mma8452.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/iio/accel/mma8452.c +4 -5
@@ -1548,6 +1548,7 @@ MODULE_DEVICE_TABLE(of, mma8452_dt_ids);static int mma8452_probe (struct i2c_client *client) { +struct device *dev = &client->dev;struct mma8452_data *data;struct iio_dev *indio_dev;int ret;
@@ -1580,14 +1581,12 @@ static int mma8452_probe(struct i2c_client *client) "failed to get VDDIO regulator!\n"); ret =regulator_enable (data->vdd_reg); -if (ret) { -dev_err (&client->dev,"failed to enable VDD regulator!\n" ); -return ret; - } +if (ret) +return dev_err_probe (dev, ret,"failed to enable VDD regulator!\n" ); ret =regulator_enable (data->vddio_reg);if (ret) { -dev_err (&client->dev,"failed to enable VDDIO regulator!\n" ); +dev_err_probe (dev, ret,"failed to enable VDDIO regulator!\n" ); goto disable_regulator_vdd; }
Signature · 1 line
2.34.1
Re: [PATCH v3 05/10] iio: accel: mma8452: Use dev_err_probe()
Quoted 16 lines · Sanjay Chitroda
From: Sanjay Chitroda <[email protected]>
dev_err_probe()makes error code handling simpler and handle deferred probe nicely (avoid spamming logs).Signed-off-by Sanjay Chitroda <[email protected]>--- drivers/iio/accel/mma8452.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/iio/accel/mma8452.c +0
-0
drivers/iio/accel/mma8452.c MODULE_DEVICE_TABLE(of, mma8452_dt_ids); · line 1551
Quoted 4 lines
drivers/iio/accel/mma8452.c +1
-0@@ -1548,6 +1548,7 @@ MODULE_DEVICE_TABLE(of, mma8452_dt_ids);static int mma8452_probe (struct i2c_client *client) { +struct device *dev = &client->dev;
Stray change, I assume this belongs to patch 7 ("use local struct device") of your series.
Signature · 3 lines
Kind regards CJD
Re: [PATCH v3 05/10] iio: accel: mma8452: Use dev_err_probe()
Quoted 1 line · Joshua Crofts
On Tue, 5 May 2026 at 19:49, Sanjay Chitroda <[email protected]> wrote:
...
Quoted 6 lines
Quoted 3 lines
static int
mma8452_probe(struct i2c_client *client){
+ struct device *dev =&client->dev;Stray change, I assume this belongs to patch 7 ("use local struct device") of your series.
Not really. It switches to dev_err_probe() that uses it.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 05/10] iio: accel: mma8452: Use dev_err_probe()
Quoted 6 lines · Andy Shevchenko
Quoted 1 line · Joshua Crofts
On Tue, 5 May 2026 at 19:49, Sanjay Chitroda <[email protected]> wrote:
...
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
static int
mma8452_probe(struct i2c_client *client){
+ struct device *dev =&client->dev;Stray change, I assume this belongs to patch 7 ("use local struct device") of your series.
Not really. It switches to
dev_err_probe()that uses it.
Perhaps I used stray change incorrectly. The series has a patch that adds instances of struct device, so I'm not sure why this patch is adding it as well. It took me a solid minute to realize what happened when reviewing patch 7 of the series, I was ready to say it wouldn't compile (see my comment in patch 7).
Signature · 3 lines
Kind regards CJD
Re: [PATCH v3 05/10] iio: accel: mma8452: Use dev_err_probe()
Quoted 4 lines · Joshua Crofts
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Joshua Crofts
On Tue, 5 May 2026 at 19:49, Sanjay Chitroda <[email protected]> wrote:
...
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
static int
mma8452_probe(struct i2c_client *client){
+ struct device *dev =&client->dev;
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Stray change, I assume this belongs to patch 7 ("use local struct device") of your series.
Not really. It switches to
dev_err_probe()that uses it.Perhaps I used stray change incorrectly. The series has a patch that adds instances of struct device, so I'm not sure why this patch is adding it as well.
Because it makes sense here. OTOH, we only change a couple of lines, worth it having the temporary variable or not is a good question.
Quoted 3 lines
It took me a solid minute to realize what happened when reviewing patch 7 of the series, I was ready to say it wouldn't compile (see my comment in patch 7).
Yep, but it's okay for patches that have dependencies. These two doesn't seem like backporting material, they are in the bucket of "cleaning up the things", which may have dependencies and it's fine.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 05/10] iio: accel: mma8452: Use dev_err_probe()
In reply to Sanjay ChitrodaQuoted 6 lines · On Tue, 5 May 2026 23:16:35 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
dev_err_probe()makes error code handling simpler and handle deferred probe nicely (avoid spamming logs).Signed-off-by Sanjay Chitroda <[email protected]>
Applied.
PATCH v3 6/10 iio: accel: mma8452: convert to bulk regulator usage
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
The "vdd" and "vddio" regulators are always controlled together. Switch to the regulator bulk API to handle setup, enable, and disable paths in a single call.
No functional change intended.
--- drivers/iio/accel/mma8452.c | 59 ++++++++++--------------------------- 1 file changed, 15 insertions(+), 44 deletions(-)
drivers/iio/accel/mma8452.c +15 -44
@@ -111,8 +111,7 @@ struct mma8452_data {u8 data_cfg;const struct mma_chip_info *chip_info;int sleep_val; -struct regulator *vdd_reg; -struct regulator *vddio_reg; +struct regulator_bulk_data regs[2 ];/* Ensure correct alignment of time stamp when present */ struct {
@@ -1570,25 +1569,15 @@ static int mma8452_probe(struct i2c_client *client)if (ret)return ret; - data->vdd_reg =devm_regulator_get (&client->dev,"vdd" ); -if (IS_ERR (data->vdd_reg)) -return dev_err_probe (&client->dev,PTR_ERR (data->vdd_reg), -"failed to get VDD regulator!\n" ); - - data->vddio_reg =devm_regulator_get (&client->dev,"vddio" ); -if (IS_ERR (data->vddio_reg)) -return dev_err_probe (&client->dev,PTR_ERR (data->vddio_reg), -"failed to get VDDIO regulator!\n" ); - - ret =regulator_enable (data->vdd_reg); + data->regs[0 ].supply ="vdd" ; + data->regs[1 ].supply ="vddio" ; + ret =devm_regulator_bulk_get (dev,ARRAY_SIZE (data->regs), data->regs);if (ret) -return dev_err_probe (dev, ret,"failed to enable VDD regulator!\n" ); +return dev_err_probe (dev, ret,"failed to get regulators\n" ); - ret =regulator_enable (data->vddio_reg); -if (ret) { -dev_err_probe (dev, ret,"failed to enable VDDIO regulator!\n" ); - goto disable_regulator_vdd; - } + ret =regulator_bulk_enable (ARRAY_SIZE (data->regs), data->regs); +if (ret) +return dev_err_probe (dev, ret,"failed to enable regulators\n" ); ret =i2c_smbus_read_byte_data (client,MMA8452_WHO_AM_I );if (ret <0 )
@@ -1723,10 +1712,7 @@ static int mma8452_probe(struct i2c_client *client)mma8452_trigger_cleanup (indio_dev); disable_regulators: -regulator_disable (data->vddio_reg); - -disable_regulator_vdd: -regulator_disable (data->vdd_reg); +regulator_bulk_disable (ARRAY_SIZE (data->regs), data->regs);return ret; }
@@ -1748,8 +1734,7 @@ static void mma8452_remove(struct i2c_client *client)mma8452_trigger_cleanup (indio_dev);mma8452_standby (iio_priv (indio_dev)); -regulator_disable (data->vddio_reg); -regulator_disable (data->vdd_reg); +regulator_bulk_disable (ARRAY_SIZE (data->regs), data->regs); }#ifdef CONFIG_PM
@@ -1767,15 +1752,9 @@ static int mma8452_runtime_suspend(struct device *dev)return -EAGAIN ; } - ret =regulator_disable (data->vddio_reg); -if (ret) { -dev_err (dev,"failed to disable VDDIO regulator\n" ); -return ret; - } - - ret =regulator_disable (data->vdd_reg); + ret =regulator_bulk_disable (ARRAY_SIZE (data->regs), data->regs);if (ret) { -dev_err (dev,"failed to disable VDD regulator\n" ); +dev_err (dev,"failed to disable regulators\n" );return ret; }
@@ -1788,16 +1767,9 @@ static int mma8452_runtime_resume(struct device *dev)struct mma8452_data *data =iio_priv (indio_dev);int ret, sleep_val; - ret =regulator_enable (data->vdd_reg); -if (ret) { -dev_err (dev,"failed to enable VDD regulator\n" ); -return ret; - } - - ret =regulator_enable (data->vddio_reg); + ret =regulator_bulk_enable (ARRAY_SIZE (data->regs), data->regs);if (ret) { -dev_err (dev,"failed to enable VDDIO regulator\n" ); -regulator_disable (data->vdd_reg); +dev_err (dev,"failed to enable regulators\n" );return ret; }
@@ -1815,8 +1787,7 @@ static int mma8452_runtime_resume(struct device *dev)return 0 ; runtime_resume_failed: -regulator_disable (data->vddio_reg); -regulator_disable (data->vdd_reg); +regulator_bulk_disable (ARRAY_SIZE (data->regs), data->regs);return ret; }
Signature · 1 line
2.34.1
Re: [PATCH v3 06/10] iio: accel: mma8452: convert to bulk regulator usage
Quoted 37 lines · Sanjay Chitroda
From: Sanjay Chitroda <[email protected]>
The "vdd" and "vddio" regulators are always controlled together. Switch to the regulator bulk API to handle setup, enable, and disable paths in a single call.
No functional change intended.
Suggested-by Jonathan Cameron <[email protected]>Signed-off-by Sanjay Chitroda <[email protected]>--- drivers/iio/accel/mma8452.c | 59 ++++++++++--------------------------- 1 file changed, 15 insertions(+), 44 deletions(-)drivers/iio/accel/mma8452.c +1
-6@@ -111,8 +111,7 @@ struct mma8452_data {u8 data_cfg;const struct mma_chip_info *chip_info;int sleep_val; -struct regulator *vdd_reg; -struct regulator *vddio_reg; +struct regulator_bulk_data regs[2 ];/* Ensure correct alignment of time stamp when present */ struct {@@ -1570,25 +1569,15 @@ static int mma8452_probe(struct i2c_client *client)if (ret)return ret; - data->vdd_reg =devm_regulator_get (&client->dev,"vdd" ); -if (IS_ERR (data->vdd_reg)) -return dev_err_probe (&client->dev,PTR_ERR (data->vdd_reg), -"failed to get VDD regulator!\n" );
drivers/iio/accel/mma8452.c static int mma8452_probe(struct i2c_client *client) · line 1574
Quoted 10 lines
drivers/iio/accel/mma8452.c +3
-7- - data->vddio_reg =devm_regulator_get (&client->dev,"vddio" ); -if (IS_ERR (data->vddio_reg)) -return dev_err_probe (&client->dev,PTR_ERR (data->vddio_reg), -"failed to get VDDIO regulator!\n" ); - - ret =regulator_enable (data->vdd_reg); + data->regs[0 ].supply ="vdd" ; + data->regs[1 ].supply ="vddio" ; + ret =devm_regulator_bulk_get (dev,ARRAY_SIZE (data->regs), data->regs);
Since you're using ARRAY_SIZE(), it would be good to add a <linux/array_size.h> include, as it's currently pulling the macro from elsewhere. Perhaps run the IWYU
tool to check (any header additions/removals stemming from IWYU would go in a separate patch however).
Signature · 3 lines
Kind regards CJD
Jonathan Cameron
maintainerRe: [PATCH v3 06/10] iio: accel: mma8452: convert to bulk regulator usage
Quoted 46 lines · On Wed, 6 May 2026 00:34:22 +0200 Joshua Crofts <[email protected]>…
Quoted 45 lines · Sanjay Chitroda
From: Sanjay Chitroda <[email protected]>
The "vdd" and "vddio" regulators are always controlled together. Switch to the regulator bulk API to handle setup, enable, and disable paths in a single call.
No functional change intended.
Suggested-by Jonathan Cameron <[email protected]>Signed-off-by Sanjay Chitroda <[email protected]>--- drivers/iio/accel/mma8452.c | 59 ++++++++++--------------------------- 1 file changed, 15 insertions(+), 44 deletions(-)drivers/iio/accel/mma8452.c +2
-13@@ -111,8 +111,7 @@ struct mma8452_data {u8 data_cfg;const struct mma_chip_info *chip_info;int sleep_val; -struct regulator *vdd_reg; -struct regulator *vddio_reg; +struct regulator_bulk_data regs[2 ];/* Ensure correct alignment of time stamp when present */ struct {@@ -1570,25 +1569,15 @@ static int mma8452_probe(struct i2c_client *client)if (ret)return ret; - data->vdd_reg =devm_regulator_get (&client->dev,"vdd" ); -if (IS_ERR (data->vdd_reg)) -return dev_err_probe (&client->dev,PTR_ERR (data->vdd_reg), -"failed to get VDD regulator!\n" ); - - data->vddio_reg =devm_regulator_get (&client->dev,"vddio" ); -if (IS_ERR (data->vddio_reg)) -return dev_err_probe (&client->dev,PTR_ERR (data->vddio_reg), -"failed to get VDDIO regulator!\n" ); - - ret =regulator_enable (data->vdd_reg); + data->regs[0 ].supply ="vdd" ;
Quoted 8 lines
drivers/iio/accel/mma8452.c static int mma8452_probe(struct i2c_client *client) · line 1574
Quoted 2 lines
drivers/iio/accel/mma8452.c +2
-0+ data->regs[1 ].supply ="vddio" ; + ret =devm_regulator_bulk_get (dev,ARRAY_SIZE (data->regs), data->regs);Since you're using
ARRAY_SIZE(), it would be good to add a <linux/array_size.h> include, as it's currently pulling the macro from elsewhere. Perhaps run the IWYU
tool to check (any header additions/removals stemming from IWYU would go in a separate patch however).
Fully agree that there are missing includes in the file. ARRAY_SIZE() is already in use so ideally an IWYU header additions patch should precede this one that adds another user.
Given Andy's comments as well need addressing I'll stop here in picking up the series. Jonathan
Quoted 1 line
Re: [PATCH v3 06/10] iio: accel: mma8452: convert to bulk regulator usage
In reply to Sanjay ChitrodaQuoted 5 lines · Sanjay Chitroda
The "vdd" and "vddio" regulators are always controlled together. Switch to the regulator bulk API to handle setup, enable, and disable paths in a single call.
No functional change intended.
...
drivers/iio/accel/mma8452.c struct mma8452_data { · line 114
Quoted 8 lines
struct
mma8452_data{drivers/iio/accel/mma8452.c +1
-2u8 data_cfg;const struct mma_chip_info *chip_info;int sleep_val; -struct regulator *vdd_reg; -struct regulator *vddio_reg; +struct regulator_bulk_data regs[2 ];
When touching data structures, always confirm with pahole that the chosen layout suits well. You can also consider doing another patch to rearrange the members for that. But be careful about the code generation, rearrange of such a data needs confirmation from both pahole and bloat-o-meter.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 7/10 iio: accel: mma8452: use local struct device
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
Introduce a local struct device pointer derived from &client->dev. This avoids repeated &client->dev usage and improves readability.
--- drivers/iio/accel/mma8452.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-)
drivers/iio/accel/mma8452.c +19 -18
@@ -222,15 +222,15 @@ static int mma8452_drdy(struct mma8452_data *data)static int mma8452_set_runtime_pm_state (struct i2c_client *client,bool on) {#ifdef CONFIG_PM +struct device *dev = &client->dev;int ret;if (on) - ret =pm_runtime_resume_and_get (&client->dev); + ret =pm_runtime_resume_and_get (dev);else - ret =pm_runtime_put_autosuspend (&client->dev); + ret =pm_runtime_put_autosuspend (dev);if (ret <0 ) { -dev_err (&client->dev, -"failed to change power state to %d\n" , on); +dev_err (dev,"failed to change power state to %d\n" , on);return ret; }
@@ -1552,7 +1552,7 @@ static int mma8452_probe(struct i2c_client *client)struct iio_dev *indio_dev;int ret; - indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data)); + indio_dev =devm_iio_device_alloc (dev,sizeof (*data));if (!indio_dev)return -ENOMEM ;
@@ -1562,10 +1562,10 @@ static int mma8452_probe(struct i2c_client *client) data->chip_info =i2c_get_match_data (client);if (!data->chip_info) -return dev_err_probe (&client->dev, -ENODEV , +return dev_err_probe (dev, -ENODEV ,"unknown device model\n" ); - ret =iio_read_mount_matrix (&client->dev, &data->orientation); + ret =iio_read_mount_matrix (dev, &data->orientation);if (ret)return ret;
@@ -1598,7 +1598,7 @@ static int mma8452_probe(struct i2c_client *client) goto disable_regulators; } -dev_info (&client->dev,"registering %s accelerometer; ID 0x%x\n" , +dev_info (dev,"registering %s accelerometer; ID 0x%x\n" , data->chip_info->name, data->chip_info->chip_id);i2c_set_clientdata (client, indio_dev);
@@ -1631,10 +1631,10 @@ static int mma8452_probe(struct i2c_client *client)if (client->irq) {int irq2; - irq2 =fwnode_irq_get_byname (dev_fwnode (&client->dev),"INT2" ); + irq2 =fwnode_irq_get_byname (dev_fwnode (dev),"INT2" );if (irq2 == client->irq) { -dev_dbg (&client->dev,"using interrupt line INT2\n" ); +dev_dbg (dev,"using interrupt line INT2\n" ); }else { ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG5,
@@ -1642,7 +1642,7 @@ static int mma8452_probe(struct i2c_client *client)if (ret <0 ) goto disable_regulators; -dev_dbg (&client->dev,"using interrupt line INT1\n" ); +dev_dbg (dev,"using interrupt line INT1\n" ); } ret = i2c_smbus_write_byte_data(client,
@@ -1679,14 +1679,14 @@ static int mma8452_probe(struct i2c_client *client) goto buffer_cleanup; } - ret =pm_runtime_set_active (&client->dev); + ret =pm_runtime_set_active (dev);if (ret <0 ) goto free_irq; -pm_runtime_enable (&client->dev); -pm_runtime_set_autosuspend_delay (&client->dev, +pm_runtime_enable (dev); +pm_runtime_set_autosuspend_delay (dev,MMA8452_AUTO_SUSPEND_DELAY_MS ); -pm_runtime_use_autosuspend (&client->dev); +pm_runtime_use_autosuspend (dev); ret =iio_device_register (indio_dev);if (ret <0 )
@@ -1721,11 +1721,12 @@ static void mma8452_remove(struct i2c_client *client) {struct iio_dev *indio_dev =i2c_get_clientdata (client);struct mma8452_data *data =iio_priv (indio_dev); +struct device *dev = &client->dev;iio_device_unregister (indio_dev); -pm_runtime_disable (&client->dev); -pm_runtime_set_suspended (&client->dev); +pm_runtime_disable (dev); +pm_runtime_set_suspended (dev);if (client->irq)free_irq (client->irq, indio_dev);
@@ -1748,7 +1749,7 @@ static int mma8452_runtime_suspend(struct device *dev) ret =mma8452_standby (data);mutex_unlock (&data->lock);if (ret <0 ) { -dev_err (&data->client->dev,"powering off device failed\n" ); +dev_err (dev,"powering off device failed\n" );return -EAGAIN ; }
Signature · 1 line
2.34.1
Re: [PATCH v3 07/10] iio: accel: mma8452: use local struct device
drivers/iio/accel/mma8452.c static int mma8452_probe(struct i2c_client *client) · line 1553
Quoted 3 lines · Sanjay Chitroda
drivers/iio/accel/mma8452.c +0
-0@@ -1552,7 +1552,7 @@ static int mma8452_probe(struct i2c_client *client)struct iio_dev *indio_dev;int ret;
As mentioned, you added the local struct device in patch 5, making this really confusing (and potentially breaking if only a partial set of the patches would be picked up). Please add it here.
Signature · 3 lines
Kind regards CJD
Re: [PATCH v3 07/10] iio: accel: mma8452: use local struct device
Quoted 8 lines · Joshua Crofts
drivers/iio/accel/mma8452.c static int mma8452_probe(struct i2c_client *client) · line 1553
Quoted 3 lines · Sanjay Chitroda
drivers/iio/accel/mma8452.c +0
-0@@ -1552,7 +1552,7 @@ static int mma8452_probe(struct i2c_client *client)struct iio_dev *indio_dev;int ret;As mentioned, you added the local struct device in patch 5, making this really confusing (and potentially breaking if only a partial set of the patches would be picked up). Please add it here.
Hi Joshua,
Thank you for the review.
I have prepared series as there is some dependency on earlier change with respect to current. If we pick random change it has high changes to fail.
FYI, compilation is validated on each change so if someone take few initial patch then hopefully nothing would break. Additionally, if we plan to take random patches from series based on some review comment or requirement then I would resend new series specific to that patches to avoid any break.
Quoted 1 line
Re: [PATCH v3 07/10] iio: accel: mma8452: use local struct device
In reply to Sanjay ChitrodaQuoted 2 lines · Sanjay Chitroda
Introduce a local struct device pointer derived from
&client->dev. This avoids repeated&client->devusage and improves readability.
...
drivers/iio/accel/mma8452.c static int mma8452_probe(struct i2c_client *client) · line 1566
Quoted 5 lines
drivers/iio/accel/mma8452.c +1
-1data->chip_info =i2c_get_match_data (client);if (!data->chip_info) -return dev_err_probe (&client->dev, -ENODEV , +return dev_err_probe (dev, -ENODEV ,"unknown device model\n" );
Now it's a single line.
...
drivers/iio/accel/mma8452.c static int mma8452_probe(struct i2c_client *client) · line 1688
Quoted 2 lines
drivers/iio/accel/mma8452.c +1
-0+pm_runtime_set_autosuspend_delay (dev,MMA8452_AUTO_SUSPEND_DELAY_MS );
Ditto.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 8/10 iio: accel: mma8452: use pm_ptr() and direct runtime PM calls
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
Use pm_ptr() together with DEFINE_RUNTIME_DEV_PM_OPS() so the PM ops pointer is automatically handled when CONFIG_PM is enabled or disabled.
Switch to direct PM runtime calls and drop mma8452_set_runtime_pm_state() wrapper, which is no longer needed. This follows modern kernel power-management conventions.
---
Changes in v3:
- Use direct PM runtime calls and drop redundant wrapper along with CONFIG_PM
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Use DEFINE_RUNTIME_DEV_PM_OPS to address review comment and resolve 0-day bot warning
- Link to v1: https://lore.kernel.org/all/[email protected]/
--- drivers/iio/accel/mma8452.c | 55 +++++++++++++------------------------ 1 file changed, 19 insertions(+), 36 deletions(-)
drivers/iio/accel/mma8452.c +19 -36
@@ -219,34 +219,15 @@ static int mma8452_drdy(struct mma8452_data *data)return -EIO ; } -static int mma8452_set_runtime_pm_state (struct i2c_client *client,bool on) -{ -#ifdef CONFIG_PM -struct device *dev = &client->dev; -int ret; - -if (on) - ret =pm_runtime_resume_and_get (dev); -else - ret =pm_runtime_put_autosuspend (dev); -if (ret <0 ) { -dev_err (dev,"failed to change power state to %d\n" , on); - -return ret; - } -#endif - -return 0 ; -} -static int mma8452_read (struct mma8452_data *data,__be16 buf[3 ]) { +struct device *dev = &data->client->dev;int ret =mma8452_drdy (data);if (ret <0 )return ret; - ret =mma8452_set_runtime_pm_state (data->client, true); + ret =pm_runtime_resume_and_get (dev);if (ret)return ret;
@@ -255,9 +236,7 @@ static int mma8452_read(struct mma8452_data *data, __be16 buf[3])if (ret <0 )return ret; - ret =mma8452_set_runtime_pm_state (data->client, false); - -return ret; +return pm_runtime_put_autosuspend (dev); } static ssize_t mma8452_show_int_plus_micros(char *buf, const int (*vals)[2],
@@ -974,6 +953,7 @@ static int mma8452_write_event_config(struct iio_dev *indio_dev, bool state) {struct mma8452_data *data =iio_priv (indio_dev); +struct device *dev = &data->client->dev;int val, ret;const struct mma8452_event_regs *ev_regs;
@@ -981,8 +961,11 @@ static int mma8452_write_event_config(struct iio_dev *indio_dev,if (ret)return ret; - ret =mma8452_set_runtime_pm_state (data->client, state); -if (ret) +if (state) + ret =pm_runtime_resume_and_get (dev); +else + ret =pm_runtime_put_autosuspend (dev); +if (ret <0 )return ret;switch (dir) {
@@ -1452,10 +1435,15 @@ static int mma8452_data_rdy_trigger_set_state(struct iio_trigger *trig, {struct iio_dev *indio_dev =iio_trigger_get_drvdata (trig);struct mma8452_data *data =iio_priv (indio_dev); +struct device *dev = &data->client->dev; +int reg, ret; - ret =mma8452_set_runtime_pm_state (data->client, state); -if (ret) +if (state) + ret =pm_runtime_resume_and_get (dev); +else + ret =pm_runtime_put_autosuspend (dev); +if (ret <0 )return ret; reg =i2c_smbus_read_byte_data (data->client,MMA8452_CTRL_REG4 );
@@ -1738,7 +1726,6 @@ static void mma8452_remove(struct i2c_client *client)regulator_bulk_disable (ARRAY_SIZE (data->regs), data->regs); } -#ifdef CONFIG_PM static int mma8452_runtime_suspend (struct device *dev) {struct iio_dev *indio_dev =i2c_get_clientdata (to_i2c_client (dev));
@@ -1792,13 +1779,9 @@ static int mma8452_runtime_resume(struct device *dev)return ret; } -#endif -static const struct dev_pm_ops mma8452_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) -SET_RUNTIME_PM_OPS (mma8452_runtime_suspend, - mma8452_runtime_resume,NULL ) -}; +static DEFINE_RUNTIME_DEV_PM_OPS(mma8452_pm_ops, mma8452_runtime_suspend, + mma8452_runtime_resume, NULL);static const struct i2c_device_id mma8452_id[] = { {"fxls8471" , (kernel_ulong_t)&mma_chip_info_table[fxls8471] },
@@ -1815,7 +1798,7 @@ static struct i2c_driver mma8452_driver = { .driver = { .name = "mma8452", .of_match_table = mma8452_dt_ids, - .pm = &mma8452_pm_ops, + .pm = pm_ptr(&mma8452_pm_ops), }, .probe = mma8452_probe, .remove = mma8452_remove,
Signature · 1 line
2.34.1
Re: [PATCH v3 08/10] iio: accel: mma8452: use pm_ptr() and direct runtime PM calls
Quoted 6 lines · Sanjay Chitroda
Use
pm_ptr()together withDEFINE_RUNTIME_DEV_PM_OPS()so the PM ops pointer is automatically handled whenCONFIG_PMis enabled or disabled.Switch to direct PM runtime calls and drop
mma8452_set_runtime_pm_state()wrapper, which is no longer needed. This follows modern kernel power-management conventions.
...
drivers/iio/accel/mma8452.c static int mma8452_data_rdy_trigger_set_state(struct iio_trigger *trig,
Quoted 8 lines
static int mma8452_data_rdy_trigger_set_state(struct
iio_trigger*trig,{
drivers/iio/accel/mma8452.c +2
-0struct iio_dev *indio_dev =iio_trigger_get_drvdata (trig);struct mma8452_data *data =iio_priv (indio_dev); +struct device *dev = &data->client->dev; +
Stray blank line.
drivers/iio/accel/mma8452.c static int mma8452_data_rdy_trigger_set_state(struct iio_trigger *trig, · line 1445
Quoted 8 lines
drivers/iio/accel/mma8452.c +4
-2int reg, ret; - ret =mma8452_set_runtime_pm_state (data->client, state); -if (ret) +if (state) + ret =pm_runtime_resume_and_get (dev); +else + ret =pm_runtime_put_autosuspend (dev);
Hmm... Do we care about autosuspend returned value? What is its meaning?
Quoted 2 lines
(quoted diff) +1
-0+ if (ret < 0) return ret;
...
drivers/iio/accel/mma8452.c static int mma8452_runtime_resume(struct device *dev) · line 1784
Quoted 2 lines
drivers/iio/accel/mma8452.c +2
-0+static DEFINE_RUNTIME_DEV_PM_OPS(mma8452_pm_ops, mma8452_runtime_suspend, + mma8452_runtime_resume, NULL);
Use logical split
static DEFINE_RUNTIME_DEV_PM_OPS(mma8452_pm_ops,
mma8452_runtime_suspend, mma8452_runtime_resume, NULL);
OR
static DEFINE_RUNTIME_DEV_PM_OPS(mma8452_pm_ops,
mma8452_runtime_suspend, mma8452_runtime_resume, NULL);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH v3 08/10] iio: accel: mma8452: use pm_ptr() and direct runtime PM calls
In reply to Sanjay ChitrodaQuoted 10 lines · On Tue, 5 May 2026 23:16:38 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Use
pm_ptr()together withDEFINE_RUNTIME_DEV_PM_OPS()so the PM ops pointer is automatically handled whenCONFIG_PMis enabled or disabled.Switch to direct PM runtime calls and drop
mma8452_set_runtime_pm_state()wrapper, which is no longer needed. This follows modern kernel power-management conventions.Signed-off-by Sanjay Chitroda <[email protected]>
Hi Sanjay,
The cleanup you have in here has made what i think are two nasty race conditions much more obvious. I think we need to fix those (and that fix needs to go at the start of this series)
Thanks for you work on this driver - this problem has been there a long time!
Jonathan
Quoted 25 lines
---
Changes in v3:
- Use direct PM runtime calls and drop redundant wrapper along withCONFIG_PM
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- UseDEFINE_RUNTIME_DEV_PM_OPSto address review comment and resolve 0-day bot warning
- Link to v1: https://lore.kernel.org/all/[email protected]/--- drivers/iio/accel/mma8452.c | 55 +++++++++++++------------------------ 1 file changed, 19 insertions(+), 36 deletions(-)drivers/iio/accel/mma8452.c +1
-0static ssize_t mma8452_show_int_plus_micros(char *buf, const int (*vals)[2],@@ -974,6 +953,7 @@ static int mma8452_write_event_config(struct iio_dev *indio_dev, bool state) {struct mma8452_data *data =iio_priv (indio_dev); +struct device *dev = &data->client->dev;int val, ret;const struct mma8452_event_regs *ev_regs;
drivers/iio/accel/mma8452.c static int mma8452_write_event_config(struct iio_dev *indio_dev, · line 984
Quoted 4 lines
drivers/iio/accel/mma8452.c +0
-1@@ -981,8 +961,11 @@ static int mma8452_write_event_config(struct iio_dev *indio_dev,if (ret)return ret; - ret =mma8452_set_runtime_pm_state (data->client, state);
This smells like the same bug as below.
Quoted 10 lines
drivers/iio/accel/mma8452.c +5
-1-if (ret) +if (state) + ret =pm_runtime_resume_and_get (dev); +else + ret =pm_runtime_put_autosuspend (dev); +if (ret <0 )return ret;switch (dir) {
drivers/iio/accel/mma8452.c static int mma8452_data_rdy_trigger_set_state(struct iio_trigger *trig, · line 1457
Quoted 8 lines
drivers/iio/accel/mma8452.c +2
-1@@ -1452,10 +1435,15 @@ static int mma8452_data_rdy_trigger_set_state(struct iio_trigger *trig, {struct iio_dev *indio_dev =iio_trigger_get_drvdata (trig);struct mma8452_data *data =iio_priv (indio_dev); +struct device *dev = &data->client->dev; +int reg, ret; - ret =mma8452_set_runtime_pm_state (data->client, state);
This functions makes me very suspicious and I think has a nasty existing race condition. If the auto suspend were to suspend immediately vddio would be powered down. Unless they supplies have odd naming on this device that means the bus would be down before the write that follows.
As such I think this needs s rewrite to makes sure we only call pm_runtime_put_autosuspend() after the bus writes in this function are done.
I think that is safe to do without testing as all it will do is delay when the power gets turned off a tiny bit.
Quoted 12 lines
drivers/iio/accel/mma8452.c +5
-1-if (ret) +if (state) + ret =pm_runtime_resume_and_get (dev); +else + ret =pm_runtime_put_autosuspend (dev); +if (ret <0 )return ret; reg =i2c_smbus_read_byte_data (data->client,MMA8452_CTRL_REG4 );@@ -1738,7 +1726,6 @@ static void mma8452_remove(struct i2c_client *client)regulator_bulk_disable (ARRAY_SIZE (data->regs), data->regs); }
Re: [PATCH v3 08/10] iio: accel: mma8452: use pm_ptr() and direct runtime PM calls
Quoted 16 lines · Jonathan Cameron
Quoted 10 lines · On Tue, 5 May 2026 23:16:38 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Use
pm_ptr()together withDEFINE_RUNTIME_DEV_PM_OPS()so the PM ops pointer is automatically handled whenCONFIG_PMis enabled or disabled.Switch to direct PM runtime calls and drop
mma8452_set_runtime_pm_state()wrapper, which is no longer needed. This follows modern kernel power-management conventions.Signed-off-by Sanjay Chitroda <[email protected]>Hi Sanjay,
Quoted 9 lines
The cleanup you have in here has made what i think are two nasty race conditions much more obvious. I think we need to fix those (and that fix needs to go at the start of this series)
Thanks for you work on this driver - this problem has been there a long time!
Jonathan
Hi Jonathan,
Thank you for your review and kind words.
Your guidance and feedback are very motivating and help contributors stay consistent and improve their work.
It is an honor to collaborate and learn from experienced maintainers like you.
Also, I would like to know if there are any opportunities in other IIO drivers or within the kernel framework where contributions would be helpful, especially around fixes, resource management, power management, or general code cleanup and coding style improvements. I would be glad to work on such areas and continue contributing.
Thanks,
Sanjay Chitroda
Quoted 54 lines
Quoted 25 lines
---
Changes in v3:
- Use direct PM runtime calls and drop redundant wrapper along withCONFIG_PM
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- UseDEFINE_RUNTIME_DEV_PM_OPSto address review comment and resolve 0-day bot warning
- Link to v1: https://lore.kernel.org/all/[email protected]/--- drivers/iio/accel/mma8452.c | 55 +++++++++++++------------------------ 1 file changed, 19 insertions(+), 36 deletions(-)drivers/iio/accel/mma8452.c +1
-0static ssize_t mma8452_show_int_plus_micros(char *buf, const int (*vals)[2],@@ -974,6 +953,7 @@ static int mma8452_write_event_config(struct iio_dev *indio_dev, bool state) {struct mma8452_data *data =iio_priv (indio_dev); +struct device *dev = &data->client->dev;int val, ret;const struct mma8452_event_regs *ev_regs;drivers/iio/accel/mma8452.c static int mma8452_write_event_config(struct iio_dev *indio_dev, · line 984
Quoted 4 lines
drivers/iio/accel/mma8452.c +0
-1@@ -981,8 +961,11 @@ static int mma8452_write_event_config(struct iio_dev *indio_dev,if (ret)return ret; - ret =mma8452_set_runtime_pm_state (data->client, state);This smells like the same bug as below.
Quoted 10 lines
drivers/iio/accel/mma8452.c +5
-1-if (ret) +if (state) + ret =pm_runtime_resume_and_get (dev); +else + ret =pm_runtime_put_autosuspend (dev); +if (ret <0 )return ret;switch (dir) {drivers/iio/accel/mma8452.c static int mma8452_data_rdy_trigger_set_state(struct iio_trigger *trig, · line 1457
Quoted 8 lines
drivers/iio/accel/mma8452.c +2
-1@@ -1452,10 +1435,15 @@ static int mma8452_data_rdy_trigger_set_state(struct iio_trigger *trig, {struct iio_dev *indio_dev =iio_trigger_get_drvdata (trig);struct mma8452_data *data =iio_priv (indio_dev); +struct device *dev = &data->client->dev; +int reg, ret; - ret =mma8452_set_runtime_pm_state (data->client, state);This functions makes me very suspicious and I think has a nasty existing race condition. If the auto suspend were to suspend immediately vddio would be powered down. Unless they supplies have odd naming on this device that means the bus would be down before the write that follows.
Quoted 6 lines
As such I think this needs s rewrite to makes sure we only call
pm_runtime_put_autosuspend()after the bus writes in this function are done.I think that is safe to do without testing as all it will do is delay when the power gets turned off a tiny bit.
While in-corporating direct PM runtime call; I also observed that this is against the expectation and design as per my knowledge.
However, I assume that thisust be well tested and something which I may not aware specific to driver. So I done changes as per requirement and waited for input from reviewer and potentially guidance on the same.
Now, this is clear issue and will handle same in next series.
Quoted 13 lines
Quoted 12 lines
drivers/iio/accel/mma8452.c +5
-1-if (ret) +if (state) + ret =pm_runtime_resume_and_get (dev); +else + ret =pm_runtime_put_autosuspend (dev); +if (ret <0 )return ret; reg =i2c_smbus_read_byte_data (data->client,MMA8452_CTRL_REG4 );@@ -1738,7 +1726,6 @@ static void mma8452_remove(struct i2c_client *client)regulator_bulk_disable (ARRAY_SIZE (data->regs), data->regs); }
Jonathan Cameron
maintainerRe: [PATCH v3 08/10] iio: accel: mma8452: use pm_ptr() and direct runtime PM calls
Quoted 28 lines · On Thu, 07 May 2026 08:16:40 +0530 Sanjay Chitroda…
Quoted 16 lines · Jonathan Cameron
Quoted 10 lines · On Tue, 5 May 2026 23:16:38 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Use
pm_ptr()together withDEFINE_RUNTIME_DEV_PM_OPS()so the PM ops pointer is automatically handled whenCONFIG_PMis enabled or disabled.Switch to direct PM runtime calls and drop
mma8452_set_runtime_pm_state()wrapper, which is no longer needed. This follows modern kernel power-management conventions.Signed-off-by Sanjay Chitroda <[email protected]>Hi Sanjay,
Quoted 9 lines
The cleanup you have in here has made what i think are two nasty race conditions much more obvious. I think we need to fix those (and that fix needs to go at the start of this series)
Thanks for you work on this driver - this problem has been there a long time!
Jonathan
Hi Jonathan,
Quoted 8 lines
Thank you for your review and kind words.
Your guidance and feedback are very motivating and help contributors stay consistent and improve their work.
It is an honor to collaborate and learn from experienced maintainers like you.
Also, I would like to know if there are any opportunities in other IIO drivers or within the kernel framework where contributions would be helpful, especially around fixes, resource management, power management, or general code cleanup and coding style improvements. I would be glad to work on such areas and continue contributing.
Hi Sanjay.
Right now the best thing you could do is to help with review of what others are posting to the list. Do some of that before diving in to make more code improvements.
Jonathan
Quoted 82 lines
Thanks,
Sanjay ChitrodaQuoted 54 lines
Quoted 25 lines
---
Changes in v3:
- Use direct PM runtime calls and drop redundant wrapper along withCONFIG_PM
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- UseDEFINE_RUNTIME_DEV_PM_OPSto address review comment and resolve 0-day bot warning
- Link to v1: https://lore.kernel.org/all/[email protected]/--- drivers/iio/accel/mma8452.c | 55 +++++++++++++------------------------ 1 file changed, 19 insertions(+), 36 deletions(-)drivers/iio/accel/mma8452.c +1
-0static ssize_t mma8452_show_int_plus_micros(char *buf, const int (*vals)[2],@@ -974,6 +953,7 @@ static int mma8452_write_event_config(struct iio_dev *indio_dev, bool state) {struct mma8452_data *data =iio_priv (indio_dev); +struct device *dev = &data->client->dev;int val, ret;const struct mma8452_event_regs *ev_regs;drivers/iio/accel/mma8452.c static int mma8452_write_event_config(struct iio_dev *indio_dev, · line 984
Quoted 4 lines
drivers/iio/accel/mma8452.c +0
-1@@ -981,8 +961,11 @@ static int mma8452_write_event_config(struct iio_dev *indio_dev,if (ret)return ret; - ret =mma8452_set_runtime_pm_state (data->client, state);This smells like the same bug as below.
Quoted 10 lines
drivers/iio/accel/mma8452.c +5
-1-if (ret) +if (state) + ret =pm_runtime_resume_and_get (dev); +else + ret =pm_runtime_put_autosuspend (dev); +if (ret <0 )return ret;switch (dir) {drivers/iio/accel/mma8452.c static int mma8452_data_rdy_trigger_set_state(struct iio_trigger *trig, · line 1457
Quoted 8 lines
drivers/iio/accel/mma8452.c +2
-1@@ -1452,10 +1435,15 @@ static int mma8452_data_rdy_trigger_set_state(struct iio_trigger *trig, {struct iio_dev *indio_dev =iio_trigger_get_drvdata (trig);struct mma8452_data *data =iio_priv (indio_dev); +struct device *dev = &data->client->dev; +int reg, ret; - ret =mma8452_set_runtime_pm_state (data->client, state);This functions makes me very suspicious and I think has a nasty existing race condition. If the auto suspend were to suspend immediately vddio would be powered down. Unless they supplies have odd naming on this device that means the bus would be down before the write that follows.
Quoted 6 lines
As such I think this needs s rewrite to makes sure we only call
pm_runtime_put_autosuspend()after the bus writes in this function are done.I think that is safe to do without testing as all it will do is delay when the power gets turned off a tiny bit.
While in-corporating direct PM runtime call; I also observed that this is against the expectation and design as per my knowledge.
However, I assume that thisust be well tested and something which I may not aware specific to driver. So I done changes as per requirement and waited for input from reviewer and potentially guidance on the same.
Now, this is clear issue and will handle same in next series.
Quoted 13 lines
Quoted 12 lines
drivers/iio/accel/mma8452.c +5
-1-if (ret) +if (state) + ret =pm_runtime_resume_and_get (dev); +else + ret =pm_runtime_put_autosuspend (dev); +if (ret <0 )return ret; reg =i2c_smbus_read_byte_data (data->client,MMA8452_CTRL_REG4 );@@ -1738,7 +1726,6 @@ static void mma8452_remove(struct i2c_client *client)regulator_bulk_disable (ARRAY_SIZE (data->regs), data->regs); }
PATCH v3 9/10 iio: accel: mma8452: Use IIO cleanup helpers
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
Use IIO_DEV_ACQUIRE_DIRECT_MODE() helper to automatically release direct mode.
--- drivers/iio/accel/mma8452.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/iio/accel/mma8452.c +7 -9
@@ -474,14 +474,14 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,int i, ret;switch (mask) { -case IIO_CHAN_INFO_RAW : -if (!iio_device_claim_direct (indio_dev)) +case IIO_CHAN_INFO_RAW : { +IIO_DEV_ACQUIRE_DIRECT_MODE (indio_dev, claim); +if (IIO_DEV_ACQUIRE_FAILED (claim))return -EBUSY ;mutex_lock (&data->lock); ret =mma8452_read (data, buffer);mutex_unlock (&data->lock); -iio_device_release_direct (indio_dev);if (ret <0 )return ret;
@@ -490,6 +490,7 @@ static int mma8452_read_raw(struct iio_dev *indio_dev, chan->scan_type.realbits - 1);return IIO_VAL_INT ; + }case IIO_CHAN_INFO_SCALE : i = data->data_cfg &MMA8452_DATA_CFG_FS_MASK ; *val = data->chip_info->mma_scales[i][0 ];
@@ -756,14 +757,11 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,struct iio_chan_spec const *chan, int val, int val2, long mask) { - int ret; - -if (!iio_device_claim_direct (indio_dev)) +IIO_DEV_ACQUIRE_DIRECT_MODE (indio_dev ,claim ); +if (IIO_DEV_ACQUIRE_FAILED (claim))return -EBUSY ; - ret =__mma8452_write_raw (indio_dev, chan, val, val2, mask); -iio_device_release_direct (indio_dev); -return ret; +return __mma8452_write_raw (indio_dev, chan, val, val2, mask); } static int mma8452_get_event_regs(struct mma8452_data *data,
Signature · 1 line
2.34.1
PATCH v3 10/10 iio: accel: mma8452: use guard() to release mutexes
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
Replace explicit mutex_lock() and mutex_unlock() with the guard() and scoped_guard() macro for cleaner and safer mutex handling.
---
Changes in v3:
- Following input from Jonathan extended mutex scope for
IIO_CHAN_INFO_RAW case to include math operation under lock
- Link to v2: https://lore.kernel.org/all/[email protected]/
--- drivers/iio/accel/mma8452.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-)
drivers/iio/accel/mma8452.c +11 -18
@@ -18,6 +18,7 @@* TODO: orientation events */ +#include <linux/cleanup.h> #include <linux/delay.h> #include <linux/i2c.h> #include <linux/mod_devicetable.h>
@@ -478,10 +479,9 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,IIO_DEV_ACQUIRE_DIRECT_MODE (indio_dev, claim);if (IIO_DEV_ACQUIRE_FAILED (claim))return -EBUSY ; +guard (mutex)(&data->lock); -mutex_lock (&data->lock); ret =mma8452_read (data, buffer); -mutex_unlock (&data->lock);if (ret <0 )return ret;
@@ -579,36 +579,30 @@ static int mma8452_change_config(struct mma8452_data *data, u8 reg, u8 val)int ret;int is_active; -mutex_lock (&data->lock); +guard (mutex)(&data->lock); is_active =mma8452_is_active (data); -if (is_active <0 ) { - ret = is_active; - goto fail; - } +if (is_active <0 ) +return is_active;/* config can only be changed when in standby */ if (is_active >0 ) { ret =mma8452_standby (data);if (ret <0 ) - goto fail; +return ret; } ret =i2c_smbus_write_byte_data (data->client, reg, val);if (ret <0 ) - goto fail; +return ret;if (is_active >0 ) { ret =mma8452_active (data);if (ret <0 ) - goto fail; +return ret; } - ret =0 ; -fail: -mutex_unlock (&data->lock); - -return ret; +return 0 ; }static int mma8452_set_power_mode (struct mma8452_data *data,u8 mode)
@@ -1730,9 +1724,8 @@ static int mma8452_runtime_suspend(struct device *dev)struct mma8452_data *data =iio_priv (indio_dev);int ret; -mutex_lock (&data->lock); - ret =mma8452_standby (data); -mutex_unlock (&data->lock); +scoped_guard (mutex, &data->lock) + ret = mma8452_standby(data);if (ret <0 ) {dev_err (dev,"powering off device failed\n" );return -EAGAIN ;
Signature · 1 line
2.34.1
Re: [PATCH v3 10/10] iio: accel: mma8452: use guard() to release mutexes
Quoted 2 lines · Sanjay Chitroda
Replace explicit
mutex_lock()andmutex_unlock()with theguard()andscoped_guard()macro for cleaner and safer mutex handling.
...
drivers/iio/accel/mma8452.c static int mma8452_read_raw(struct iio_dev *indio_dev, · line 481
Quoted 5 lines
static int mma8452_read_raw(struct
iio_dev*indio_dev,drivers/iio/accel/mma8452.c +0
-0IIO_DEV_ACQUIRE_DIRECT_MODE (indio_dev, claim);if (IIO_DEV_ACQUIRE_FAILED (claim))return -EBUSY ;
+ Blank line here.
drivers/iio/accel/mma8452.c static int mma8452_read_raw(struct iio_dev *indio_dev, · line 484
Quoted 5 lines
drivers/iio/accel/mma8452.c +1
-2+guard (mutex)(&data->lock); -mutex_lock (&data->lock); ret =mma8452_read (data, buffer); -mutex_unlock (&data->lock);
Perhaps okay, also scoped_guard() can be used, but I have no strong opinion.
Quoted 2 lines
drivers/iio/accel/mma8452.c +0
-0if (ret <0 )return ret;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 5 lines · Sanjay Chitroda
This series contains a small fixes, cleanup and improvements to use modern kernel helper API and coding style for mma8452 accel driver.
The changes modernize mutex with
guard(),dev_err_probeusage, resolve checkpatch CHECKS andpm_ptrmacro usage.
...
Quoted 1 line
Feedback and reviews are very welcome.
Sorry I haven't asked this previously. Is any part of this analysis / commit messages / et cetera AI assisted?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Sanjay Chitroda
This series contains a small fixes, cleanup and improvements to use modern kernel helper API and coding style for mma8452 accel driver.
The changes modernize mutex with
guard(),dev_err_probeusage, resolve checkpatch CHECKS andpm_ptrmacro usage.
Quoted 6 lines
...
Quoted 1 line
Feedback and reviews are very welcome.
Sorry I haven't asked this previously. Is any part of this analysis / commit messages / et cetera AI assisted?
I have used AI assistance to prepare initial templates for cover letter and commit message guidelines.
However development is done by me and I refer git history of similar contribution to prepare commit message.
Additionally, contribution and development is done as part of LFX mentorship program under the guidance of Shuah Khan and Brigham Campbell where AI usage is strictly restricted to commit message templates and review.
Quoted 1 line
Quoted 35 lines · Sanjay Chitroda
From: Sanjay Chitroda <[email protected]>
Hi all,
This series contains a small fixes, cleanup and improvements to use modern kernel helper API and coding style for mma8452 accel driver.
The changes modernize mutex with
guard(),dev_err_probeusage, resolve checkpatch CHECKS andpm_ptrmacro usage.Changes in v3:
- Following input from Andy and Jonathan added new changes as following 0001: handle return value to have proper error propagation
0002: use non-devm API to maintain resource management LIFO order
0006: convert individual regulator using bulk regulator API
0009: use IIO cleanup helper forDIRECT_MODE
- Address kernel coding stype specific review comment
- Reorder local struct device anddev_err_probechange
v2 series -> https://lore.kernel.org/all/[email protected]/
Changes in v2:
- 0005: address review comment from Andy and Geert
and useDEFINE_RUNTIME_DEV_PM_OPSmacro
- Added new cleanup channges in mma8452 driverNo functional behavior changes are intended.
Testing:
- Compiled with W=1
- Build-tested on QEMUx86_64Feedback and reviews are very welcome.
Thanks,
Sanjay Chitroda
Quoted 11 lines
Sanjay Chitroda (10):
iio: accel: mma8452: handle I2C read error(s) inmma8452_read()
iio: accel: mma8452: switch to non-devmrequest_threaded_irq()
iio: accel: mma8452: cleanup codestyle warning
iio: accel: mma8452: sort headers alphabetically
iio: accel: mma8452: Usedev_err_probe()
iio: accel: mma8452: convert to bulk regulator usage
iio: accel: mma8452: use local struct device
iio: accel: mma8452: usepm_ptr()and direct runtime PM calls
iio: accel: mma8452: Use IIO cleanup helpers
iio: accel: mma8452: useguard()to release mutexes
Hi Jonathan,
It's been about two weeks since the latest posting, and it looks like there haven't been any major comments so far atleast on initial changes of series. I also don't see any progress on the iio/tesing branch yet.
Could you please guide me on how you'd like me to take this series forward? I'm happy to rework/resend partial/full if needed or wait further.
Thanks, Sanjay
Quoted 9 lines
drivers/iio/accel/mma8452.c | 278 +++++++++++++++--------------------- 1 file changed, 116 insertions(+), 162 deletions(-)base-commit:
39b80c5c9830d12d2d6531059001301c4265322aSignature · 1 line
2.34.1
Quoted 28 lines · Sanjay Chitroda
Quoted 27 lines · Sanjay Chitroda
This series contains a small fixes, cleanup and improvements to use modern kernel helper API and coding style for mma8452 accel driver.
The changes modernize mutex with
guard(),dev_err_probeusage, resolve checkpatch CHECKS andpm_ptrmacro usage.Changes in v3:
- Following input from Andy and Jonathan added new changes as following 0001: handle return value to have proper error propagation
0002: use non-devm API to maintain resource management LIFO order
0006: convert individual regulator using bulk regulator API
0009: use IIO cleanup helper forDIRECT_MODE
- Address kernel coding stype specific review comment
- Reorder local struct device anddev_err_probechange
v2 series -> https://lore.kernel.org/all/[email protected]/
Changes in v2:
- 0005: address review comment from Andy and Geert
and useDEFINE_RUNTIME_DEV_PM_OPSmacro
- Added new cleanup channges in mma8452 driverNo functional behavior changes are intended.
Testing:
- Compiled with W=1
- Build-tested on QEMUx86_64
Quoted 8 lines
Quoted 1 line
Feedback and reviews are very welcome.
It's been about two weeks since the latest posting, and it looks like there haven't been any major comments so far atleast on initial changes of series. I also don't see any progress on the iio/tesing branch yet.
Could you please guide me on how you'd like me to take this series forward? I'm happy to rework/resend partial/full if needed or wait further.
The recent flood of the patches in IIO makes maintainers and reviewers overloaded. If you want to help, be a good citizen, start reviewing others' work. Otherwise, wait when we have time (it make take a few weeks or more).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 35 lines · On Mon, 18 May 2026 10:20:25 +0300 Andy Shevchenko…
Quoted 34 lines · Sanjay Chitroda
Quoted 21 lines · Sanjay Chitroda
This series contains a small fixes, cleanup and improvements to use modern kernel helper API and coding style for mma8452 accel driver.
The changes modernize mutex with
guard(),dev_err_probeusage, resolve checkpatch CHECKS andpm_ptrmacro usage.Changes in v3:
- Following input from Andy and Jonathan added new changes as following 0001: handle return value to have proper error propagation
0002: use non-devm API to maintain resource management LIFO order
0006: convert individual regulator using bulk regulator API
0009: use IIO cleanup helper forDIRECT_MODE
- Address kernel coding stype specific review comment
- Reorder local struct device anddev_err_probechange
v2 series -> https://lore.kernel.org/all/[email protected]/
Changes in v2:
- 0005: address review comment from Andy and Geert
and useDEFINE_RUNTIME_DEV_PM_OPSmacro
- Added new cleanup channges in mma8452 driverQuoted 7 lines
No functional behavior changes are intended.
Testing:
- Compiled with W=1
- Build-tested on QEMUx86_64Feedback and reviews are very welcome.
It's been about two weeks since the latest posting, and it looks like there haven't been any major comments so far atleast on initial changes of series. I also don't see any progress on the iio/tesing branch yet.
Quoted 7 lines
Quoted 2 lines
Could you please guide me on how you'd like me to take this series forward? I'm happy to rework/resend partial/full if needed or wait further.
The recent flood of the patches in IIO makes maintainers and reviewers overloaded. If you want to help, be a good citizen, start reviewing others' work. Otherwise, wait when we have time (it make take a few weeks or more).
Just to add a bit more info. Whether I pick up partial sets is often dependent on what else is going on at the time. So generally unless I say I'm doing it, just assume that a full new version of the series is needed.
Just to keep my own tracking simple I tend to make that decision at time of review (rather than coming back later to see if I can grab them).
Anyhow, today it was fine to pick some up so I picked up 1-5.
Thanks,
Jonathan