Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Amber Kao" <amber.kao@ite.com.tw>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 2/2] usb: typec: ucsi: Add ITE IT885x Type-C PD controller driver
Date: Thu, 09 Jul 2026 08:49:12 +0000	[thread overview]
Message-ID: <20260709084913.570DE1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260710-ucsi-itepd-feature-v2-2-41943fd5df38@ite.com.tw>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Race condition during driver removal causing a use-after-free on the `ucsi->connector` array.
- [High] Infinite IRQ storm and CPU lockup due to silently ignored I2C write or memory allocation failures.
--

--- Patch [2]: [PATCH v2 2/2] usb: typec: ucsi: Add ITE IT885x Type-C PD controller driver ---
commit a72e407ddecce41bb76245d04b0009fb6795ba01
Author: Amber Kao <amber.kao@ite.com.tw>

usb: typec: ucsi: Add ITE IT885x Type-C PD controller driver

This commit adds core UCSI support for the ITE IT885x USB Type-C Power
Delivery controller over I2C. It provides port and partner registration,
deferring Alternate Mode support and command translation to future patches.

> diff --git a/drivers/usb/typec/ucsi/ucsi_itepd.c b/drivers/usb/typec/ucsi/ucsi_itepd.c
> new file mode 100644
> index 0000000000000..e364a3bd7df4e
> --- /dev/null
> +++ b/drivers/usb/typec/ucsi/ucsi_itepd.c

[ ... ]

> +static int itepd_write_reg(struct itepd *itepd, u8 reg, const void *data, u32 len)
> +{
> +	struct i2c_client *client = itepd->client;
> +	struct i2c_msg msg[1];
> +	u8 *buf;
> +	int ret;
> +
> +	buf = kzalloc(len + 1, GFP_KERNEL);
> +	if (!buf)
> +		return -ENOMEM;

[ ... ]

> +static irqreturn_t itepd_irq_process(struct itepd *itepd)
> +{
> +	u8 msg_in[ITEPD_MSG_IN_MAX_LEN] = {};
> +	__le32 le_cci;
> +	u32 cci = 0;
> +	u8 event;
> +	u8 len;
> +	int ret;

[ ... ]

> +out_clear:
> +	itepd_write_reg(itepd, ITEPD_VENDOR_WC_INT, &event, sizeof(event));
> +
> +	if (!ret && (event & ITEPD_ALERT_UCSI_EVENT))
> +		ucsi_notify_common(itepd->ucsi, cci);
> +
> +	return IRQ_HANDLED;
> +}

[Severity: High]
Could a failure to clear the interrupt result in an infinite IRQ storm?

Looking at itepd_write_reg(), it dynamically allocates memory via kzalloc().
If this allocation fails with -ENOMEM, or if the underlying I2C transfer
fails, the hardware interrupt is not actually cleared on the device.

Because itepd_irq_process() ignores the return value of itepd_write_reg()
and unconditionally returns IRQ_HANDLED, the kernel IRQ subsystem will unmask
the line and immediately trigger the handler again, potentially causing a CPU
lockup under memory pressure or I2C bus errors.

[ ... ]

> +static void itepd_remove(struct i2c_client *client)
> +{
> +	struct itepd *itepd = i2c_get_clientdata(client);
> +
> +	ucsi_unregister(itepd->ucsi);
> +	free_irq(client->irq, itepd);
> +	ucsi_destroy(itepd->ucsi);
> +}

[Severity: High]
Is there a race condition during driver removal that could lead to a
use-after-free?

This teardown sequence calls ucsi_unregister() before free_irq().

When ucsi_unregister() is called, it frees the ucsi->connector array. If a
pending hardware interrupt is processed by the threaded IRQ handler
after ucsi_unregister() completes but before free_irq() is called,
itepd_irq_process() will call ucsi_notify_common().

This sequence would result in ucsi_notify_common() accessing the freed
connector array.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260710-ucsi-itepd-feature-v2-0-41943fd5df38@ite.com.tw?part=2

      reply	other threads:[~2026-07-09  8:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09 16:34 [PATCH v2 0/2] usb: typec: ucsi: Add ITE IT885x Type-C PD controller driver Amber Kao
2026-07-09 16:34 ` [PATCH v2 1/2] dt-bindings: usb: Add ITE IT885x support Amber Kao
2026-07-09 16:34 ` [PATCH v2 2/2] usb: typec: ucsi: Add ITE IT885x Type-C PD controller driver Amber Kao
2026-07-09  8:49   ` 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=20260709084913.570DE1F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amber.kao@ite.com.tw \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox