All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Adil Hüsrev Tepe" <tadilhusrev@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v4 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver
Date: Sat, 05 Dec 2026 03:58:08 +0000	[thread overview]
Message-ID: <sashiko-outbox-251028@kernel.org> (raw)
In-Reply-To: <20261205-isg5320a-v4-2-a9bb8573c064@gmail.com>

Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [Medium] iio: proximity: isg5320a_events_off() clears state and PM ref
  on write error
- [Medium] iio: proximity: isg5320a_probe() skips client->irq validation
  before request
- [Medium] iio: proximity: isg5320a IRQ thread races with system suspend
  and events_off
- [Medium] iio: proximity: isg5320a leaves data->close stale after
  system resume
- [Medium] iio: proximity: isg5320a_irq_thread() races with events
  disable and sleep
- [Medium] iio: proximity: isg5320a unconditionally sleeps on suspend
  despite wakeup-source
- [Medium] iio: isg5320a: isg5320a_read_irq_status() skips IRQSRC on
  sample error
- [Low] iio: proximity: isg5320a_read_irq_status() skips IRQ ack on
  sample error
--

commit 73f01735ba874407aefe2dc455ca4c17ad756481
Author: Adil Hüsrev Tepe <tadilhusrev@gmail.com>

iio: proximity: add Imagis ISG5320A SAR sensor driver

This commit adds an IIO driver for the Imagis ISG5320A capacitive
SAR/grip sensor over I2C, exposing a single proximity channel and
rising/falling threshold events with runtime PM support.

> diff --git a/drivers/iio/proximity/isg5320a.c b/drivers/iio/proximity/isg5320a.c
> new file mode 100644
> index 0000000000000..407f2c7e2d8ab
> --- /dev/null
> +++ b/drivers/iio/proximity/isg5320a.c

[ ... ]

> +static int isg5320a_read_irq_status(struct isg5320a_data *data, bool *close)
> +{
> +	unsigned int val;
> +	int ret;
> +
> +	lockdep_assert_held(&data->lock);
> +
> +	ret = isg5320a_read_sample(data);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_read(data->regmap, ISG5320A_REG_IRQSTS, &val);
> +	if (ret)
> +		return ret;
> +
> +	*close = val & ISG5320A_IRQSTS_PROX;
> +
> +	return 0;
> +}

[Severity: Medium]
Can an I2C error in isg5320a_read_sample() leave the active-low INT line
stuck asserted?

If the 4-byte bulk read fails, isg5320a_read_irq_status() returns early
without reading ISG5320A_REG_IRQSRC to release INT, and
isg5320a_irq_thread() then returns IRQ_HANDLED.  Because
isg5320a_events_on() keeps runtime PM active, nothing else reads
ISG5320A_REG_IRQSRC, so falling-edge interrupts wedge until events are
toggled or the system suspends, and level-low interrupts re-trigger
immediately.

[Severity: Low]
Does isg5320a_read_irq_status() need to read the sample before
acknowledging the interrupt at all?

Neither isg5320a_read_irq_status() nor isg5320a_irq_thread() uses
data->cdc or data->base, and isg5320a_read_raw() calls
isg5320a_read_sample() itself.  Reading ISG5320A_REG_IRQSRC and
ISG5320A_REG_IRQSTS first (or dropping the unused sample read here) avoids
gating interrupt acknowledgment on an unrelated bulk transfer.

> +static irqreturn_t isg5320a_irq_thread(int irq, void *private)
> +{
> +	struct iio_dev *indio_dev = private;
> +	struct isg5320a_data *data = iio_priv(indio_dev);
> +	s64 timestamp = iio_get_time_ns(indio_dev);
> +	enum iio_event_direction dir;
> +	bool close;
> +	int ret;
> +
> +	guard(mutex)(&data->lock);
> +
> +	ret = isg5320a_read_irq_status(data, &close);
> +	if (ret) {
> +		dev_err_ratelimited(regmap_get_device(data->regmap),
> +				    "irq status read failed: %d\n", ret);
> +		return IRQ_HANDLED;
> +	}
> +
> +	if (close == data->close)
> +		return IRQ_HANDLED;
> +
> +	data->close = close;
> +
> +	dir = close ? IIO_EV_DIR_RISING : IIO_EV_DIR_FALLING;
> +	iio_push_event(indio_dev,
> +		       IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 0,
> +					    IIO_EV_TYPE_THRESH, dir),
> +		       timestamp);
> +
> +	return IRQ_HANDLED;
> +}

[Severity: Medium]
Can isg5320a_irq_thread() access a runtime-suspended chip or push events
after userspace disables them?

isg5320a_events_off() writes ISG5320A_IRQFUNC_DISABLE and drops the
runtime PM reference without calling synchronize_irq(), and
isg5320a_irq_thread() neither takes a runtime PM reference nor checks
data->ev_enabled:

CPU0                              CPU1
isg5320a_events_off()
  lock(&data->lock)
                                  isg5320a_irq_thread()
                                    lock(&data->lock)  (blocks)
  regmap_write(IRQFUNC_DISABLE)
  data->ev_enabled = false
  pm_runtime_put_autosuspend()
  unlock(&data->lock)
  ...
isg5320a_runtime_suspend()
  isg5320a_mode_sleep()
                                    isg5320a_read_irq_status() <-- sleeping
                                    iio_push_event()  <-- after disable

If an interrupt fires just before ISG5320A_IRQFUNC_DISABLE takes effect,
the pending thread can push a spurious event after write_event_config()
returns, or read registers after autosuspend has put the sensor to sleep
(for instance if autosuspend_delay_ms is set to 0).

[ ... ]

> +static int isg5320a_events_off(struct isg5320a_data *data)
> +{
> +	struct device *dev = regmap_get_device(data->regmap);
> +	int ret;
> +
> +	guard(mutex)(&data->lock);
> +
> +	ret = regmap_write(data->regmap, ISG5320A_REG_IRQFUNC,
> +			   ISG5320A_IRQFUNC_DISABLE);
> +
> +	data->ev_enabled = false;
> +
> +	/* Drop the reference kept by isg5320a_events_on(). */
> +	pm_runtime_put_autosuspend(dev);
> +
> +	return ret;
> +}

[Severity: Medium]
Should data->ev_enabled and the runtime PM reference stay intact when
regmap_write() fails here?

Clearing data->ev_enabled unconditionally causes a retry from
isg5320a_write_event_config() to hit the state == data->ev_enabled
shortcut and return 0 without disabling ISG5320A_REG_IRQFUNC, and
isg5320a_events_off_action() will also skip disabling it on unbind.
Meanwhile, dropping the runtime PM reference lets the sensor autosuspend
with hardware interrupts still enabled.

Keeping the sysfs disable path from clearing state or dropping the PM
reference on error (while still letting the unbind action drop the PM
reference unconditionally) avoids leaving hardware and driver state out
of sync.

[ ... ]

> +	ret = devm_request_threaded_irq(dev, client->irq, NULL,
> +					isg5320a_irq_thread, IRQF_ONESHOT,
> +					"isg5320a", indio_dev);
> +	if (ret)
> +		return ret;

[Severity: Medium]
What happens if the I2C device is instantiated without an interrupt?

Because the driver has an i2c_device_id table, a device created via sysfs
new_device or incomplete firmware gets client->irq == 0 from
i2c_device_probe().  request_threaded_irq() only rejects IRQ_NOTCONNECTED
and otherwise passes 0 to irq_to_desc(0), which on architectures with a
legacy IRQ 0 either fails with a misleading -EBUSY or binds the handler
to IRQ 0 after powering on and calibrating the sensor.

Checking client->irq <= 0 early in isg5320a_probe() avoids both the
invalid IRQ request and the unnecessary hardware startup.

[ ... ]

> +static int isg5320a_runtime_resume(struct device *dev)
> +{
> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +	struct isg5320a_data *data = iio_priv(indio_dev);
> +
> +	return isg5320a_mode_normal(data);
> +}

[Severity: Medium]
Can data->close become stale across system suspend and resume?

When proximity events are enabled, pm_runtime_force_suspend() puts the
sensor to sleep and pm_runtime_force_resume() restarts and recalibrates
it via isg5320a_mode_normal(), without refreshing data->close from
ISG5320A_REG_IRQSTS as isg5320a_events_on() does.  If the device was
gripped before suspend and released while suspended, the recalibrated
chip starts in the far state while data->close is still true, so
isg5320a_irq_thread() suppresses the next rising proximity event.

> +static DEFINE_RUNTIME_DEV_PM_OPS(isg5320a_pm_ops, isg5320a_runtime_suspend,
> +				 isg5320a_runtime_resume, NULL);

[Severity: Medium]
Does DEFINE_RUNTIME_DEV_PM_OPS() allow isg5320a_irq_thread() to race with
system suspend and resume?

pm_runtime_force_suspend() runs isg5320a_mode_sleep() during
dpm_suspend(), before dpm_suspend_noirq() calls suspend_device_irqs(),
and isg5320a_mode_sleep() does not disable ISG5320A_REG_IRQFUNC or
client->irq:

CPU0                              CPU1
dpm_suspend()
  pm_runtime_force_suspend()
    isg5320a_mode_sleep()
      lock(&data->lock)
                                  isg5320a_irq_thread()
                                    lock(&data->lock)  (blocks)
      regmap_multi_reg_write(sleep)
      unlock(&data->lock)
  <parent I2C adapter suspends>
                                    isg5320a_read_irq_status() <-- bus/chip
                                                                   suspended

Symmetrically, on resume dpm_resume_noirq() re-enables client->irq before
pm_runtime_force_resume() wakes and recalibrates the chip with IRQFUNC
still enabled.  Using explicit system sleep callbacks that disable/enable
client->irq around sleep would close both windows.

[Severity: Medium]
Does putting the sensor to sleep unconditionally on system suspend break
the wakeup-source property in the DT binding?

Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml
documents wakeup-source, which causes the I2C core to call
device_init_wakeup() and dev_pm_set_wake_irq() automatically.  Because
pm_runtime_force_suspend() always calls isg5320a_mode_sleep() without
checking device_may_wakeup(dev), the chip stops scanning during suspend
and can never wake the system.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-isg5320a-v4-0-a9bb8573c064@gmail.com?part=2

  reply	other threads:[~2026-12-05  3:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  3:35 [PATCH v4 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Adil Hüsrev Tepe
2026-12-05  3:35 ` [PATCH v4 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
2026-12-05 14:37   ` Krzysztof Kozlowski
2026-12-05  3:35 ` [PATCH v4 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
2026-12-05  3:58   ` sashiko-bot [this message]
2026-12-05 11:08 ` [PATCH v4 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-251028@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tadilhusrev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.