Skip to contentSkip to conversation

iio: proximity: sx9500: ignore event config writes that don't change state

PATCH In review Arnav Kapoor 2 participants 2 messages Oct 24 – Oct 25 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: proximity: sx9500: ignore event config writes that don't change state

sx9500_write_event_config() adjusts the channel and close/far user counts on every write, even when the event is already in the requested state. Writing 0 to a disabled event and then 1 leaves the counts at 0, so the channel and its interrupts stay off while the event reads as enabled. As channel_users[] is shared with raw reads, those can then wait forever for a conversion. Writing 1 twice and then 0 has the opposite effect.

Return early when the state doesn't change, as
sx_common_write_event_config() does.

Fixes 4193c0f1d863 ("iio: driver for Semtech SX9500 proximity solution")

---
Compile-tested only (W=1); I don't have SX9500 hardware. Both write sequences were checked with a userspace model of the user counting.

 drivers/iio/proximity/sx9500.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/iio/proximity/sx9500.c +6 -0
index dadce9b44227..26522b6c5a2d 100644
@@ -548,6 +548,12 @@ static int sx9500_write_event_config(struct iio_dev *indio_dev,
 
 	mutex_lock(&data->mutex);
 
+	/* The user counts must only change when the state does. */
+	if (data->event_enabled[chan->channel] == state) {
+		ret = 0;
+		goto out_unlock;
+	}
+
 	if (state) {
 		ret = sx9500_inc_chan_users(data, chan->channel);
 		if (ret < 0)

base-commit: 2ef6f5c4ee56e90c237c5f7687f09e635f7d30a9

Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 8 lines · On Sat, 24 Oct 2026 23:26:53 +0530 Arnav Kapoor <[email protected]> wrote:

sx9500_write_event_config() adjusts the channel and close/far user counts on every write, even when the event is already in the requested state. Writing 0 to a disabled event and then 1 leaves the counts at 0, so the channel and its interrupts stay off while the event reads as enabled. As channel_users[] is shared with raw reads, those can then wait forever for a conversion. Writing 1 twice and then 0 has the opposite effect.

Quoted 5 lines

Return early when the state doesn't change, as
sx_common_write_event_config() does.

Fixes 4193c0f1d863 ("iio: driver for Semtech SX9500 proximity solution")

Applied and marked for stable.

thanks

Jonathan