* [PATCH v7 1/8] dt-bindings: iio: accel: mma8452: Add drive-open-drain
2026-08-31 12:17 [PATCH v7 0/8] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
@ 2026-08-31 12:17 ` Esben Haabendal
2026-08-31 12:17 ` [PATCH v7 2/8] iio: accel: mma8452: Optimize struct mma8452_data member orders Esben Haabendal
` (6 subsequent siblings)
7 siblings, 0 replies; 17+ messages in thread
From: Esben Haabendal @ 2026-08-31 12:17 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá, Andy Shevchenko,
Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel
Add new boolean to configure selected interrupt pin to open drain instead
of the default push-pull mode.
Acked-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
Documentation/devicetree/bindings/iio/accel/fsl,mma8452.yaml | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/Documentation/devicetree/bindings/iio/accel/fsl,mma8452.yaml b/Documentation/devicetree/bindings/iio/accel/fsl,mma8452.yaml
index b0dd2b4e116a..20701aa725d0 100644
--- a/Documentation/devicetree/bindings/iio/accel/fsl,mma8452.yaml
+++ b/Documentation/devicetree/bindings/iio/accel/fsl,mma8452.yaml
@@ -39,6 +39,12 @@ properties:
minItems: 1
maxItems: 2
+ drive-open-drain:
+ $ref: /schemas/types.yaml#/definitions/flag
+ description: the interrupt line will be configured as open drain, which is
+ useful if several sensors share the same interrupt line. (This binding is
+ taken from pinctrl.)
+
vdd-supply: true
vddio-supply: true
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH v7 2/8] iio: accel: mma8452: Optimize struct mma8452_data member orders
2026-08-31 12:17 [PATCH v7 0/8] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
2026-08-31 12:17 ` [PATCH v7 1/8] dt-bindings: iio: accel: mma8452: Add drive-open-drain Esben Haabendal
@ 2026-08-31 12:17 ` Esben Haabendal
2026-08-31 12:17 ` [PATCH v7 3/8] iio: accel: mma8452: Only apply trigger type when not set by firmware Esben Haabendal
` (5 subsequent siblings)
7 siblings, 0 replies; 17+ messages in thread
From: Esben Haabendal @ 2026-08-31 12:17 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá, Andy Shevchenko,
Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
Joshua Crofts, Andy Shevchenko
Reorder struct mma8452_data members to avoid holes.
Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/accel/mma8452.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 7d683686dd9d..f645a5c6fd1c 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -106,10 +106,7 @@ struct mma8452_data {
struct i2c_client *client;
struct mutex lock;
struct iio_mount_matrix orientation;
- u8 ctrl_reg1;
- u8 data_cfg;
const struct mma_chip_info *chip_info;
- int sleep_val;
struct regulator *vdd_reg;
struct regulator *vddio_reg;
@@ -118,6 +115,10 @@ struct mma8452_data {
__be16 channels[3];
aligned_s64 ts;
} buffer;
+
+ int sleep_val;
+ u8 ctrl_reg1;
+ u8 data_cfg;
};
/**
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH v7 3/8] iio: accel: mma8452: Only apply trigger type when not set by firmware
2026-08-31 12:17 [PATCH v7 0/8] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
2026-08-31 12:17 ` [PATCH v7 1/8] dt-bindings: iio: accel: mma8452: Add drive-open-drain Esben Haabendal
2026-08-31 12:17 ` [PATCH v7 2/8] iio: accel: mma8452: Optimize struct mma8452_data member orders Esben Haabendal
@ 2026-08-31 12:17 ` Esben Haabendal
2026-08-31 12:17 ` [PATCH v7 4/8] iio: accel: mma8452: Support interrupt sharing Esben Haabendal
` (4 subsequent siblings)
7 siblings, 0 replies; 17+ messages in thread
From: Esben Haabendal @ 2026-08-31 12:17 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá, Andy Shevchenko,
Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
Andy Shevchenko
Instead of unconditionally overriding the trigger type, it is better to
only apply a default when no trigger type is set by firmware. This should
be reasonably backward compatible, and should only potentially cause
problems if systems exist where firmware specifies an incorrect trigger
type. With a bit of luck, there are no such systems.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/accel/mma8452.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index f645a5c6fd1c..1fb43c5b0b72 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -1683,9 +1683,16 @@ static int mma8452_probe(struct i2c_client *client)
goto trigger_cleanup;
if (client->irq) {
+ unsigned long irq_flags;
+
+ irq_flags = irq_get_trigger_type(client->irq);
+ if (irq_flags == IRQ_TYPE_NONE) {
+ dev_info(dev, "invalid irq type, setting default active low\n");
+ irq_flags = IRQF_TRIGGER_LOW;
+ }
+ irq_flags |= IRQF_ONESHOT;
ret = request_threaded_irq(client->irq, NULL, mma8452_interrupt,
- IRQF_TRIGGER_LOW | IRQF_ONESHOT,
- client->name, indio_dev);
+ irq_flags, client->name, indio_dev);
if (ret)
goto buffer_cleanup;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH v7 4/8] iio: accel: mma8452: Support interrupt sharing
2026-08-31 12:17 [PATCH v7 0/8] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
` (2 preceding siblings ...)
2026-08-31 12:17 ` [PATCH v7 3/8] iio: accel: mma8452: Only apply trigger type when not set by firmware Esben Haabendal
@ 2026-08-31 12:17 ` Esben Haabendal
2026-08-31 13:56 ` Andy Shevchenko
2026-08-31 12:17 ` [PATCH v7 5/8] iio: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
` (3 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Esben Haabendal @ 2026-08-31 12:17 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá, Andy Shevchenko,
Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel
Adding handling of rutnime PM suspension in the interrupt handler allows
sharing interrupt with other devices.
Keep in mind that the device by default is using push-pull for the irq pin,
which might require additional hardware design to allow interrupt sharing.
The suspended flag is added together with synchronize_irq() in order to
protect against race conditions when doing runtime suspend and device
removal. This way we ensure that interrupt handler does not try to access
the device while regulators are disabled.
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/accel/mma8452.c | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 1fb43c5b0b72..936eeb2efb2d 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -119,6 +119,7 @@ struct mma8452_data {
int sleep_val;
u8 ctrl_reg1;
u8 data_cfg;
+ bool suspended;
};
/**
@@ -1056,14 +1057,24 @@ static irqreturn_t mma8452_interrupt(int irq, void *p)
struct iio_dev *indio_dev = p;
struct mma8452_data *data = iio_priv(indio_dev);
irqreturn_t ret = IRQ_NONE;
+ int pm_status;
int src;
+ pm_status = pm_runtime_get_if_active(&data->client->dev);
+ if (pm_status == 0)
+ return IRQ_NONE; /* device is powered down */
+ if (READ_ONCE(data->suspended)) {
+ /* device is being removed */
+ ret = IRQ_NONE;
+ goto out_runtime_put;
+ }
+
src = i2c_smbus_read_byte_data(data->client, MMA8452_INT_SRC);
if (src < 0)
- return IRQ_NONE;
+ goto out_runtime_put;
if (!(src & (data->chip_info->enabled_events | MMA8452_INT_DRDY)))
- return IRQ_NONE;
+ goto out_runtime_put;
if (src & MMA8452_INT_DRDY) {
iio_trigger_poll_nested(indio_dev->trig);
@@ -1089,6 +1100,10 @@ static irqreturn_t mma8452_interrupt(int irq, void *p)
ret = IRQ_HANDLED;
}
+out_runtime_put:
+ if (pm_status > 0)
+ pm_runtime_put_autosuspend(&data->client->dev);
+
return ret;
}
@@ -1690,7 +1705,7 @@ static int mma8452_probe(struct i2c_client *client)
dev_info(dev, "invalid irq type, setting default active low\n");
irq_flags = IRQF_TRIGGER_LOW;
}
- irq_flags |= IRQF_ONESHOT;
+ irq_flags |= IRQF_ONESHOT | IRQF_SHARED;
ret = request_threaded_irq(client->irq, NULL, mma8452_interrupt,
irq_flags, client->name, indio_dev);
if (ret)
@@ -1762,7 +1777,8 @@ static void mma8452_remove(struct i2c_client *client)
#ifdef CONFIG_PM
static int mma8452_runtime_suspend(struct device *dev)
{
- struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+ struct i2c_client *client = to_i2c_client(dev);
+ struct iio_dev *indio_dev = i2c_get_clientdata(client);
struct mma8452_data *data = iio_priv(indio_dev);
int ret;
@@ -1774,6 +1790,10 @@ static int mma8452_runtime_suspend(struct device *dev)
return -EAGAIN;
}
+ WRITE_ONCE(data->suspended, true);
+
+ synchronize_irq(client->irq);
+
ret = regulator_disable(data->vddio_reg);
if (ret) {
dev_err(dev, "failed to disable VDDIO regulator\n");
@@ -1808,6 +1828,8 @@ static int mma8452_runtime_resume(struct device *dev)
return ret;
}
+ WRITE_ONCE(data->suspended, false);
+
ret = mma8452_active(data);
if (ret < 0)
goto runtime_resume_failed;
@@ -1822,6 +1844,7 @@ static int mma8452_runtime_resume(struct device *dev)
return 0;
runtime_resume_failed:
+ WRITE_ONCE(data->suspended, true);
regulator_disable(data->vddio_reg);
regulator_disable(data->vdd_reg);
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH v7 4/8] iio: accel: mma8452: Support interrupt sharing
2026-08-31 12:17 ` [PATCH v7 4/8] iio: accel: mma8452: Support interrupt sharing Esben Haabendal
@ 2026-08-31 13:56 ` Andy Shevchenko
2026-08-31 15:43 ` Esben Haabendal
0 siblings, 1 reply; 17+ messages in thread
From: Andy Shevchenko @ 2026-08-31 13:56 UTC (permalink / raw)
To: Esben Haabendal
Cc: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá, Andy Shevchenko,
Martin Kepplinger, Christoph Muellner, linux-iio, devicetree,
linux-kernel
On Mon, Aug 31, 2026 at 02:17:07PM +0200, Esben Haabendal wrote:
> Adding handling of rutnime PM suspension in the interrupt handler allows
> sharing interrupt with other devices.
>
> Keep in mind that the device by default is using push-pull for the irq pin,
> which might require additional hardware design to allow interrupt sharing.
>
> The suspended flag is added together with synchronize_irq() in order to
> protect against race conditions when doing runtime suspend and device
> removal. This way we ensure that interrupt handler does not try to access
> the device while regulators are disabled.
...
> static int mma8452_runtime_resume(struct device *dev)
> return ret;
> }
>
> + WRITE_ONCE(data->suspended, false);
> +
> ret = mma8452_active(data);
> if (ret < 0)
> goto runtime_resume_failed;
> return 0;
>
> runtime_resume_failed:
> + WRITE_ONCE(data->suspended, true);
> regulator_disable(data->vddio_reg);
> regulator_disable(data->vdd_reg);
But with this, what's the point in having WRITE_ONCE()? It can be read
just in the middle as true and be immediately changed afterwards. It
may be that I am missing something, but I think WRITE_ONCE() should be
done once in this function.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v7 4/8] iio: accel: mma8452: Support interrupt sharing
2026-08-31 13:56 ` Andy Shevchenko
@ 2026-08-31 15:43 ` Esben Haabendal
2026-09-01 7:13 ` Andy Shevchenko
0 siblings, 1 reply; 17+ messages in thread
From: Esben Haabendal @ 2026-08-31 15:43 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá, Andy Shevchenko,
Martin Kepplinger, Christoph Muellner, linux-iio, devicetree,
linux-kernel
"Andy Shevchenko" <andriy.shevchenko@intel.com> writes:
> On Mon, Aug 31, 2026 at 02:17:07PM +0200, Esben Haabendal wrote:
>> Adding handling of rutnime PM suspension in the interrupt handler allows
>> sharing interrupt with other devices.
>>
>> Keep in mind that the device by default is using push-pull for the irq pin,
>> which might require additional hardware design to allow interrupt sharing.
>>
>> The suspended flag is added together with synchronize_irq() in order to
>> protect against race conditions when doing runtime suspend and device
>> removal. This way we ensure that interrupt handler does not try to access
>> the device while regulators are disabled.
>
> ...
>
>> static int mma8452_runtime_resume(struct device *dev)
>
>> return ret;
>> }
>>
>> + WRITE_ONCE(data->suspended, false);
>> +
>> ret = mma8452_active(data);
>> if (ret < 0)
>> goto runtime_resume_failed;
>
>> return 0;
>>
>> runtime_resume_failed:
>> + WRITE_ONCE(data->suspended, true);
>> regulator_disable(data->vddio_reg);
>> regulator_disable(data->vdd_reg);
>
> But with this, what's the point in having WRITE_ONCE()? It can be read
> just in the middle as true and be immediately changed afterwards. It
> may be that I am missing something, but I think WRITE_ONCE() should be
> done once in this function.
Yes, there does look like there is still a race condition after adding
this data->suspended flag. An irq handler could just have read
data->suspended, gotten false, and thereafter proceeeded with handling
the irq, and then we write data->suspended=true and the irq handler
would just continue with accessing the device, even though we are now
(if possible) powering down the device.
I did go through all the pre-existing runtime pm and other race
condition issues raised by sashiko-bot during this review, and worked
through it all. The result is a quite a bit larger than what I would
like to add on top of this series. Among other things, it converts the
driver to use regmap for accessing the i2c registers, and after various
fixes the data->suspended flag is removed again.
So I am a bit hesitant to pull all those changes into this series, the
combined series would blow up quite a bit. But if required, I guess I
can do that, although I fear that it will not make reviewing easier to
mix things more than maybe needed.
Could we find a way to merge this series first in some way, or should I
post a new version with all the other fixes added on top?
/Esben
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v7 4/8] iio: accel: mma8452: Support interrupt sharing
2026-08-31 15:43 ` Esben Haabendal
@ 2026-09-01 7:13 ` Andy Shevchenko
0 siblings, 0 replies; 17+ messages in thread
From: Andy Shevchenko @ 2026-09-01 7:13 UTC (permalink / raw)
To: Esben Haabendal
Cc: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá, Andy Shevchenko,
Martin Kepplinger, Christoph Muellner, linux-iio, devicetree,
linux-kernel
On Mon, Aug 31, 2026 at 05:43:06PM +0200, Esben Haabendal wrote:
> "Andy Shevchenko" <andriy.shevchenko@intel.com> writes:
> > On Mon, Aug 31, 2026 at 02:17:07PM +0200, Esben Haabendal wrote:
...
> >> + WRITE_ONCE(data->suspended, false);
> >> +
> >> ret = mma8452_active(data);
> >> if (ret < 0)
> >> goto runtime_resume_failed;
> >
> >> return 0;
> >>
> >> runtime_resume_failed:
> >> + WRITE_ONCE(data->suspended, true);
> >> regulator_disable(data->vddio_reg);
> >> regulator_disable(data->vdd_reg);
> >
> > But with this, what's the point in having WRITE_ONCE()? It can be read
> > just in the middle as true and be immediately changed afterwards. It
> > may be that I am missing something, but I think WRITE_ONCE() should be
> > done once in this function.
>
> Yes, there does look like there is still a race condition after adding
> this data->suspended flag. An irq handler could just have read
> data->suspended, gotten false, and thereafter proceeeded with handling
> the irq, and then we write data->suspended=true and the irq handler
> would just continue with accessing the device, even though we are now
> (if possible) powering down the device.
>
> I did go through all the pre-existing runtime pm and other race
> condition issues raised by sashiko-bot during this review, and worked
> through it all. The result is a quite a bit larger than what I would
> like to add on top of this series. Among other things, it converts the
> driver to use regmap for accessing the i2c registers, and after various
> fixes the data->suspended flag is removed again.
>
> So I am a bit hesitant to pull all those changes into this series, the
> combined series would blow up quite a bit. But if required, I guess I
> can do that, although I fear that it will not make reviewing easier to
> mix things more than maybe needed.
Personally I would go with it, or as a compromise, publish somewhere in Git
(like on GitHub) and share the link to the repo (in a format that one can run
with `git fetch ...`).
> Could we find a way to merge this series first in some way, or should I
> post a new version with all the other fixes added on top?
It's a Q to Jonathan.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v7 5/8] iio: accel: mma8452: Allow open drain interrupt pin configuration
2026-08-31 12:17 [PATCH v7 0/8] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
` (3 preceding siblings ...)
2026-08-31 12:17 ` [PATCH v7 4/8] iio: accel: mma8452: Support interrupt sharing Esben Haabendal
@ 2026-08-31 12:17 ` Esben Haabendal
2026-08-31 12:17 ` [PATCH v7 6/8] iio: accel: mma8452: Reuse existing dev pointer in mma8452_probe() Esben Haabendal
` (2 subsequent siblings)
7 siblings, 0 replies; 17+ messages in thread
From: Esben Haabendal @ 2026-08-31 12:17 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá, Andy Shevchenko,
Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
Andy Shevchenko
When designing systems sharing the interrupt for mma8452 chips, it is
helpful to be able to configure the irq pin in open-drain mode (default is
push-pull).
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/accel/mma8452.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 936eeb2efb2d..2ba6e2c44cb9 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -81,6 +81,8 @@
#define MMA8452_CTRL_REG2_RST BIT(6)
#define MMA8452_CTRL_REG2_MODS_SHIFT 3
#define MMA8452_CTRL_REG2_MODS_MASK 0x1b
+#define MMA8452_CTRL_REG3 0x2c
+#define MMA8452_CTRL_REG3_PP_OD BIT(0)
#define MMA8452_CTRL_REG4 0x2d
#define MMA8452_CTRL_REG5 0x2e
#define MMA8452_OFF_X 0x2f
@@ -120,6 +122,7 @@ struct mma8452_data {
u8 ctrl_reg1;
u8 data_cfg;
bool suspended;
+ bool open_drain;
};
/**
@@ -648,6 +651,22 @@ static int mma8452_set_power_mode(struct mma8452_data *data, u8 mode)
return mma8452_change_config(data, MMA8452_CTRL_REG2, reg);
}
+static int mma8452_set_interrupt_pin_mode(struct mma8452_data *data)
+{
+ int reg;
+
+ reg = i2c_smbus_read_byte_data(data->client, MMA8452_CTRL_REG3);
+ if (reg < 0)
+ return reg;
+
+ if (data->open_drain)
+ reg |= MMA8452_CTRL_REG3_PP_OD;
+ else
+ reg &= ~MMA8452_CTRL_REG3_PP_OD;
+
+ return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG3, reg);
+}
+
/* returns >0 if in freefall mode, 0 if not or <0 if an error occurred */
static int mma8452_freefall_mode_enabled(struct mma8452_data *data)
{
@@ -1682,6 +1701,11 @@ static int mma8452_probe(struct i2c_client *client)
goto disable_regulators;
}
+ data->open_drain = device_property_read_bool(dev, "drive-open-drain");
+ ret = mma8452_set_interrupt_pin_mode(data);
+ if (ret)
+ goto trigger_cleanup;
+
data->ctrl_reg1 = MMA8452_CTRL_ACTIVE |
(MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT);
@@ -1830,6 +1854,10 @@ static int mma8452_runtime_resume(struct device *dev)
WRITE_ONCE(data->suspended, false);
+ ret = mma8452_set_interrupt_pin_mode(data);
+ if (ret)
+ goto runtime_resume_failed;
+
ret = mma8452_active(data);
if (ret < 0)
goto runtime_resume_failed;
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH v7 6/8] iio: accel: mma8452: Reuse existing dev pointer in mma8452_probe()
2026-08-31 12:17 [PATCH v7 0/8] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
` (4 preceding siblings ...)
2026-08-31 12:17 ` [PATCH v7 5/8] iio: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
@ 2026-08-31 12:17 ` Esben Haabendal
2026-08-31 13:58 ` Andy Shevchenko
2026-08-31 12:17 ` [PATCH v7 7/8] iio: accel: mma8452: Fix use-after-free bug in error error path Esben Haabendal
2026-08-31 12:17 ` [PATCH v7 8/8] iio: accel: mma8452: Use proper error code when missing device model Esben Haabendal
7 siblings, 1 reply; 17+ messages in thread
From: Esben Haabendal @ 2026-08-31 12:17 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá, Andy Shevchenko,
Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
Joshua Crofts
In commit 32a5c04d4575 ("iio: accel: mma8452: Use dev_err_probe()") the
struct device * pointer was assigned to local variable dev, so we can just
as well reuse that throughout the function for sligthly more readable code.
Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/accel/mma8452.c | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 2ba6e2c44cb9..bf56ebd6e091 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -1587,7 +1587,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;
@@ -1597,21 +1597,20 @@ 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,
- "unknown device model\n");
+ 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;
- data->vdd_reg = devm_regulator_get(&client->dev, "vdd");
+ data->vdd_reg = devm_regulator_get(dev, "vdd");
if (IS_ERR(data->vdd_reg))
- return dev_err_probe(&client->dev, PTR_ERR(data->vdd_reg),
+ return dev_err_probe(dev, PTR_ERR(data->vdd_reg),
"failed to get VDD regulator!\n");
- data->vddio_reg = devm_regulator_get(&client->dev, "vddio");
+ data->vddio_reg = devm_regulator_get(dev, "vddio");
if (IS_ERR(data->vddio_reg))
- return dev_err_probe(&client->dev, PTR_ERR(data->vddio_reg),
+ return dev_err_probe(dev, PTR_ERR(data->vddio_reg),
"failed to get VDDIO regulator!\n");
ret = regulator_enable(data->vdd_reg);
@@ -1643,7 +1642,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);
@@ -1676,10 +1675,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,
@@ -1687,7 +1686,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,
@@ -1736,14 +1735,13 @@ 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,
- MMA8452_AUTO_SUSPEND_DELAY_MS);
- pm_runtime_use_autosuspend(&client->dev);
+ pm_runtime_enable(dev);
+ pm_runtime_set_autosuspend_delay(dev, MMA8452_AUTO_SUSPEND_DELAY_MS);
+ pm_runtime_use_autosuspend(dev);
ret = iio_device_register(indio_dev);
if (ret < 0)
@@ -1810,7 +1808,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;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH v7 6/8] iio: accel: mma8452: Reuse existing dev pointer in mma8452_probe()
2026-08-31 12:17 ` [PATCH v7 6/8] iio: accel: mma8452: Reuse existing dev pointer in mma8452_probe() Esben Haabendal
@ 2026-08-31 13:58 ` Andy Shevchenko
0 siblings, 0 replies; 17+ messages in thread
From: Andy Shevchenko @ 2026-08-31 13:58 UTC (permalink / raw)
To: Esben Haabendal
Cc: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá, Andy Shevchenko,
Martin Kepplinger, Christoph Muellner, linux-iio, devicetree,
linux-kernel, Joshua Crofts
On Mon, Aug 31, 2026 at 02:17:09PM +0200, Esben Haabendal wrote:
> In commit 32a5c04d4575 ("iio: accel: mma8452: Use dev_err_probe()") the
> struct device * pointer was assigned to local variable dev, so we can just
> as well reuse that throughout the function for sligthly more readable code.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v7 7/8] iio: accel: mma8452: Fix use-after-free bug in error error path
2026-08-31 12:17 [PATCH v7 0/8] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
` (5 preceding siblings ...)
2026-08-31 12:17 ` [PATCH v7 6/8] iio: accel: mma8452: Reuse existing dev pointer in mma8452_probe() Esben Haabendal
@ 2026-08-31 12:17 ` Esben Haabendal
2026-08-31 13:09 ` Joshua Crofts
2026-08-31 14:00 ` Andy Shevchenko
2026-08-31 12:17 ` [PATCH v7 8/8] iio: accel: mma8452: Use proper error code when missing device model Esben Haabendal
7 siblings, 2 replies; 17+ messages in thread
From: Esben Haabendal @ 2026-08-31 12:17 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá, Andy Shevchenko,
Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel, stable
If mma8452_probe() fails in iio_device_register() or later, we could end up
with runtime suspend callback being called with a now freed device pointer.
Fixes: 96c0cb2bbfe0 ("iio: mma8452: add support for runtime power management")
Cc: stable@vger.kernel.org
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/accel/mma8452.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index bf56ebd6e091..9619b200fa5a 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -1745,7 +1745,7 @@ static int mma8452_probe(struct i2c_client *client)
ret = iio_device_register(indio_dev);
if (ret < 0)
- goto free_irq;
+ goto runtime_suspend;
ret = mma8452_set_freefall_mode(data, false);
if (ret < 0)
@@ -1756,6 +1756,10 @@ static int mma8452_probe(struct i2c_client *client)
unregister_device:
iio_device_unregister(indio_dev);
+runtime_suspend:
+ pm_runtime_disable(dev);
+ pm_runtime_set_suspended(dev);
+
free_irq:
if (client->irq)
free_irq(client->irq, indio_dev);
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH v7 7/8] iio: accel: mma8452: Fix use-after-free bug in error error path
2026-08-31 12:17 ` [PATCH v7 7/8] iio: accel: mma8452: Fix use-after-free bug in error error path Esben Haabendal
@ 2026-08-31 13:09 ` Joshua Crofts
2026-08-31 14:00 ` Andy Shevchenko
1 sibling, 0 replies; 17+ messages in thread
From: Joshua Crofts @ 2026-08-31 13:09 UTC (permalink / raw)
To: Esben Haabendal
Cc: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá, Andy Shevchenko,
Martin Kepplinger, Christoph Muellner, linux-iio, devicetree,
linux-kernel, stable
On Mon, 31 Aug 2026 14:17:10 +0200
Esben Haabendal <esben@geanix.com> wrote:
> If mma8452_probe() fails in iio_device_register() or later, we could end up
> with runtime suspend callback being called with a now freed device pointer.
>
> Fixes: 96c0cb2bbfe0 ("iio: mma8452: add support for runtime power management")
> Cc: stable@vger.kernel.org
> Signed-off-by: Esben Haabendal <esben@geanix.com>
> ---
Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
--
Kind regards,
Joshua Crofts
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH v7 7/8] iio: accel: mma8452: Fix use-after-free bug in error error path
2026-08-31 12:17 ` [PATCH v7 7/8] iio: accel: mma8452: Fix use-after-free bug in error error path Esben Haabendal
2026-08-31 13:09 ` Joshua Crofts
@ 2026-08-31 14:00 ` Andy Shevchenko
2026-08-31 15:47 ` Esben Haabendal
1 sibling, 1 reply; 17+ messages in thread
From: Andy Shevchenko @ 2026-08-31 14:00 UTC (permalink / raw)
To: Esben Haabendal
Cc: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá, Andy Shevchenko,
Martin Kepplinger, Christoph Muellner, linux-iio, devicetree,
linux-kernel, stable
On Mon, Aug 31, 2026 at 02:17:10PM +0200, Esben Haabendal wrote:
> If mma8452_probe() fails in iio_device_register() or later, we could end up
> with runtime suspend callback being called with a now freed device pointer.
> Fixes: 96c0cb2bbfe0 ("iio: mma8452: add support for runtime power management")
Can this be popped up in the series? I think previous couple of patches are not
fixes...
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH v7 7/8] iio: accel: mma8452: Fix use-after-free bug in error error path
2026-08-31 14:00 ` Andy Shevchenko
@ 2026-08-31 15:47 ` Esben Haabendal
0 siblings, 0 replies; 17+ messages in thread
From: Esben Haabendal @ 2026-08-31 15:47 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá, Andy Shevchenko,
Martin Kepplinger, Christoph Muellner, linux-iio, devicetree,
linux-kernel, stable
"Andy Shevchenko" <andriy.shevchenko@intel.com> writes:
> On Mon, Aug 31, 2026 at 02:17:10PM +0200, Esben Haabendal wrote:
>> If mma8452_probe() fails in iio_device_register() or later, we could end up
>> with runtime suspend callback being called with a now freed device pointer.
>
>> Fixes: 96c0cb2bbfe0 ("iio: mma8452: add support for runtime power management")
>
> Can this be popped up in the series? I think previous couple of patches are not
> fixes...
Yes, popping it in front of all the other code patches in the series
does not seem to cause problems. I have scheduled that for v8.
/Esben
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v7 8/8] iio: accel: mma8452: Use proper error code when missing device model
2026-08-31 12:17 [PATCH v7 0/8] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
` (6 preceding siblings ...)
2026-08-31 12:17 ` [PATCH v7 7/8] iio: accel: mma8452: Fix use-after-free bug in error error path Esben Haabendal
@ 2026-08-31 12:17 ` Esben Haabendal
2026-08-31 13:59 ` Andy Shevchenko
7 siblings, 1 reply; 17+ messages in thread
From: Esben Haabendal @ 2026-08-31 12:17 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá, Andy Shevchenko,
Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
Joshua Crofts
Switch -ENODEV error on i2c_get_match_data() failure to -ENODATA to
satisfy the IIO coding style.
Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/accel/mma8452.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 9619b200fa5a..9eaced6bf242 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -1597,7 +1597,7 @@ static int mma8452_probe(struct i2c_client *client)
data->chip_info = i2c_get_match_data(client);
if (!data->chip_info)
- return dev_err_probe(dev, -ENODEV, "unknown device model\n");
+ return dev_err_probe(dev, -ENODATA, "unknown device model\n");
ret = iio_read_mount_matrix(dev, &data->orientation);
if (ret)
--
2.55.0
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH v7 8/8] iio: accel: mma8452: Use proper error code when missing device model
2026-08-31 12:17 ` [PATCH v7 8/8] iio: accel: mma8452: Use proper error code when missing device model Esben Haabendal
@ 2026-08-31 13:59 ` Andy Shevchenko
0 siblings, 0 replies; 17+ messages in thread
From: Andy Shevchenko @ 2026-08-31 13:59 UTC (permalink / raw)
To: Esben Haabendal
Cc: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá, Andy Shevchenko,
Martin Kepplinger, Christoph Muellner, linux-iio, devicetree,
linux-kernel, Joshua Crofts
On Mon, Aug 31, 2026 at 02:17:11PM +0200, Esben Haabendal wrote:
> Switch -ENODEV error on i2c_get_match_data() failure to -ENODATA to
> satisfy the IIO coding style.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 17+ messages in thread