* [PATCH] iio: gyro: bmg160: reject duplicate event disable
@ 2026-09-25 14:09 Jiale Yao
2026-09-25 14:18 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Jiale Yao @ 2026-09-25 14:09 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Stepan Ionichev, linux-iio, linux-kernel
Cc: Jiale Yao
The IIO core does not filter duplicate writes to the event enable
attribute. bmg160_write_event_config() already ignores repeated enable
requests, but a repeated disable request still calls
bmg160_set_power_state(data, false), dropping a runtime PM reference
that was not acquired for this request. This can underflow the runtime
PM usage count and trigger a "Runtime PM usage count underflow" warning.
Return early when the requested state already matches ev_enable_state.
Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
drivers/iio/gyro/bmg160_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/gyro/bmg160_core.c b/drivers/iio/gyro/bmg160_core.c
index d611341a0e2a..0b5621455216 100644
--- a/drivers/iio/gyro/bmg160_core.c
+++ b/drivers/iio/gyro/bmg160_core.c
@@ -761,7 +761,7 @@ static int bmg160_write_event_config(struct iio_dev *indio_dev,
struct bmg160_data *data = iio_priv(indio_dev);
int ret;
- if (state && data->ev_enable_state)
+ if (state == data->ev_enable_state)
return 0;
mutex_lock(&data->mutex);
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: gyro: bmg160: reject duplicate event disable
2026-09-25 14:09 [PATCH] iio: gyro: bmg160: reject duplicate event disable Jiale Yao
@ 2026-09-25 14:18 ` Andy Shevchenko
2026-09-25 14:33 ` jiale yao
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2026-09-25 14:18 UTC (permalink / raw)
To: Jiale Yao
Cc: Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Stepan Ionichev, linux-iio, linux-kernel
On Fri, Sep 25, 2026 at 10:09:54PM +0800, Jiale Yao wrote:
> The IIO core does not filter duplicate writes to the event enable
> attribute.
Can it be done there once for all?
> bmg160_write_event_config() already ignores repeated enable
> requests, but a repeated disable request still calls
> bmg160_set_power_state(data, false), dropping a runtime PM reference
> that was not acquired for this request. This can underflow the runtime
> PM usage count and trigger a "Runtime PM usage count underflow" warning.
>
> Return early when the requested state already matches ev_enable_state.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re:Re: [PATCH] iio: gyro: bmg160: reject duplicate event disable
2026-09-25 14:18 ` Andy Shevchenko
@ 2026-09-25 14:33 ` jiale yao
0 siblings, 0 replies; 3+ messages in thread
From: jiale yao @ 2026-09-25 14:33 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Stepan Ionichev, linux-iio, linux-kernel
At 2026-09-25 22:18:05, "Andy Shevchenko" <andriy.shevchenko@intel.com> wrote:
>On Fri, Sep 25, 2026 at 10:09:54PM +0800, Jiale Yao wrote:
>> The IIO core does not filter duplicate writes to the event enable
>> attribute.
>
>Can it be done there once for all?
I don't think the core can safely do this generically, since it doesn't own
the per-event state and read_event_config() may reflect shared hardware state.
The runtime PM accounting is driver-specific, so handling duplicate writes in
the driver seems safer. gp2ap002 does the same in commit 579c049b4cb6,
refer https://lore.kernel.org/all/20260720193911.74919-2-nikhilgtr@gmail.com/
>
>> bmg160_write_event_config() already ignores repeated enable
>> requests, but a repeated disable request still calls
>> bmg160_set_power_state(data, false), dropping a runtime PM reference
>> that was not acquired for this request. This can underflow the runtime
>> PM usage count and trigger a "Runtime PM usage count underflow" warning.
>>
>> Return early when the requested state already matches ev_enable_state.
>
>--
>With Best Regards,
>Andy Shevchenko
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-25 14:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-25 14:09 [PATCH] iio: gyro: bmg160: reject duplicate event disable Jiale Yao
2026-09-25 14:18 ` Andy Shevchenko
2026-09-25 14:33 ` jiale yao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®