All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sasha Finkelstein" <k@chaosmail.tech>
Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v10 2/2] usb: typec: tipd: Add sn201202x support
Date: Fri, 04 Dec 2026 11:10:19 +0000	[thread overview]
Message-ID: <sashiko-outbox-249658@kernel.org> (raw)
In-Reply-To: <20261204-tipd-ace3-v10-2-1b85a2c8501d@chaosmail.tech>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] usb: typec: tipd: leaked IRQ disable and wake state in
  sn201202x_resume()
- [Medium] usb: typec: tipd: missing reinit_completion() in
  sn201202x_probe()
- [Low] usb: typec: tipd: off-by-one retry loop in
  regmap_sn201202x_select_reg()
--

commit bb02d4985a811e3da44335c3016f25058f67a24e
Author: Sasha Finkelstein <k@chaosmail.tech>

usb: typec: tipd: Add sn201202x support

This commit adds support for the TI SN201202x (ACE3) USB Power Delivery
controller, exposing its register map over SPMI and wiring it into the
tipd core driver.

> diff --git a/drivers/usb/typec/tipd/spmi.c b/drivers/usb/typec/tipd/spmi.c
> new file mode 100644
> index 0000000000000..8c6c97b0b3e2f
> --- /dev/null
> +++ b/drivers/usb/typec/tipd/spmi.c
> @@ -0,0 +1,303 @@

[ ... ]

> +static int regmap_sn201202x_select_reg(struct spmi_device *sdev, u8 reg)
> +{
> +	int err;
> +	u8 val;
> +	bool warned = false;
> +	int attempts = 5;

[ ... ]

> +	while (--attempts) {
> +		err = spmi_register_read(sdev, 0, &val);
> +		if (err)
> +			return err;
> +		if (val == (reg | 0x80)) {
> +			if (!warned) {
> +				dev_warn(tps->dev,
> +					 "Got interrupt but selection not complete?\n");
> +				warned = true;
> +			}
> +			msleep(20);
> +			continue;
> +		}
> +		if (val == reg)
> +			return 0;
> +		return -EIO;
> +	}
> +
> +	return -EIO;
> +}

[Severity: Low]
Should this loop use attempts-- instead of --attempts?  With prefix
decrement, the loop only reads register 0 four times instead of five,
and on the last iteration it sleeps for 20 ms before returning -EIO
without checking register 0 again.

[ ... ]

> +	init_completion(&sn->select_completion);
> +	init_completion(&sn->sleep_completion);
> +	init_completion(&sn->wake_completion);
> +
> +	ret = devm_request_irq(&device->dev, irq_select, sn201202x_irq,
> +			       0, NULL, &sn->select_completion);
> +	if (ret)
> +		return ret;
> +	ret = devm_request_irq(&device->dev, irq_sleep, sn201202x_irq,
> +			       0, NULL, &sn->sleep_completion);
> +	if (ret)
> +		return ret;
> +	ret = devm_request_irq(&device->dev, irq_wake, sn201202x_irq,
> +			       0, NULL, &sn->wake_completion);
> +	if (ret)
> +		return ret;
> +
> +	spmi_device_set_drvdata(device, tps);
> +	tps->regmap = devm_regmap_init_sn201202x(device, &tps6598x_regmap_config);
> +	if (IS_ERR(tps->regmap))
> +		return PTR_ERR(tps->regmap);
> +
> +	ret = spmi_command_wakeup(device);
> +	if (ret)
> +		return ret;
> +	if (!wait_for_completion_timeout(&sn->wake_completion, msecs_to_jiffies(100)))
> +		return -ETIMEDOUT;
> +
> +	ret = tipd_init(tps);
> +	if (ret)
> +		if (!spmi_command_sleep(device))
> +			wait_for_completion_timeout(&sn->sleep_completion, msecs_to_jiffies(100));
> +	return ret;
> +}

[Severity: Medium]
Can wait_for_completion_timeout() consume a stale wake_completion or
sleep_completion here?

Both irq_sleep and irq_wake are enabled by devm_request_irq() before
the SPMI commands are sent.  If an edge-triggered IRQ is already
latched pending from boot firmware or a prior unbind, sn201202x_irq()
marks the completion done early.

Because sn201202x_probe() omits reinit_completion() before
spmi_command_wakeup() and spmi_command_sleep() (unlike the other
command sites in this file), tipd_init() can race against chip wakeup
and the error path can return before the chip finishes entering sleep.

[ ... ]

> +static int __maybe_unused sn201202x_resume(struct device *dev)
> +{
> +	struct tps6598x *tps = dev_get_drvdata(dev);
> +	struct sn201202x *sn = tps_to_sn(tps);
> +	int err;
> +
> +	reinit_completion(&sn->wake_completion);
> +	err = spmi_command_wakeup(sn->sdev);
> +	if (err)
> +		return err;
> +	if (!wait_for_completion_timeout(&sn->wake_completion, msecs_to_jiffies(100)))
> +		return -ETIMEDOUT;
> +	return tipd_resume(tps);
> +}

[Severity: Medium]
Do these early returns leak the disable_irq() and enable_irq_wake()
calls made by tipd_suspend()?

During suspend, sn201202x_suspend() calls tipd_suspend(), which calls
disable_irq(tps->irq) and, when wakeup-source is set,
enable_irq_wake(tps->irq).  Because tps->irq is requested with
IRQF_SHARED in tipd_init(), tipd_resume() explicitly unwinds both on
all error paths.

If spmi_command_wakeup() fails or wake_completion times out, returning
before tipd_resume() leaves the IRQ disable depth permanently
imbalanced, masking the shared line for every device on it with no
recovery on later resumes.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-tipd-ace3-v10-0-1b85a2c8501d@chaosmail.tech?part=2

      reply	other threads:[~2026-12-04 11:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 10:33 [PATCH v10 0/2] usb: typec: tipd: Add sn201202x (ACE3) support Sasha Finkelstein
2026-12-04 10:33 ` [PATCH v10 1/2] usb: typec: tipd: Factor out i2c specifics Sasha Finkelstein
2026-12-04 10:54   ` sashiko-bot
2026-12-04 10:33 ` [PATCH v10 2/2] usb: typec: tipd: Add sn201202x support Sasha Finkelstein
2026-12-04 11:10   ` sashiko-bot [this message]

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-249658@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=k@chaosmail.tech \
    --cc=linux-usb@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.