Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lakshay Piplani" <lakshay.piplani@nxp.com>
Cc: robh@kernel.org, devicetree@vger.kernel.org,
	linux-i3c@lists.infradead.org, conor+dt@kernel.org,
	Frank.Li@kernel.org
Subject: Re: [PATCH v11 9/9] i3c: hub: p3h2x4x: Add SMBus slave mode support
Date: Fri, 12 Jun 2026 11:41:54 +0000	[thread overview]
Message-ID: <20260612114155.081851F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260612111816.3688240-10-lakshay.piplani@nxp.com>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

New issues:
- [High] Unconditional dereference of `tp_smbus_client` prior to its NULL check in `p3h2x4x_read_smbus_agent_rx_buf`.
- [High] Failure to clear `tp_smbus_client` on hardware error in `p3h2x4x_tp_i2c_unreg_slave` leads to Use-After-Free.
- [High] IBI requests are not cleaned up on the `probe` error path, leaving active interrupts pointing to freed device memory.
- [High] Early return on `regmap_read` failure in `p3h2x4x_ibi_handler` aborts processing for other ports, risking an interrupt storm.

Pre-existing issues:
- [High] I2C adapters registered in `p3h2x4x_tp_smbus_algo` are leaked on subsequent probe errors, leading to Use-After-Free.
--

commit c3438427374cdabfa4f0a09443f69b5b076d009a
Author: Lakshay Piplani <lakshay.piplani@nxp.com>

i3c: hub: p3h2x4x: Add SMBus slave mode support

Add SMBus slave mode support for the P3H2x4x hub SMBus target ports,
allowing the hub to receive downstream payloads into target buffers and
report receive events through IBI to registered I2C slave clients.

> diff --git a/drivers/i3c/hub/p3h2840_i3c_hub_i3c.c b/drivers/i3c/hub/p3h2840_i3c_hub_i3c.c
> --- a/drivers/i3c/hub/p3h2840_i3c_hub_i3c.c
> +++ b/drivers/i3c/hub/p3h2840_i3c_hub_i3c.c
[ ... ]
> @@ -120,5 +128,24 @@ int p3h2x4x_tp_i3c_algo(struct p3h2x4x_i3c_hub_dev *p3h2x4x_hub)
>  		p3h2x4x_hub->tp_bus[tp].is_registered = true;
>  		p3h2x4x_hub->hub_config.tp_config[tp].always_enable = true;
>  	}
> -	return regmap_write(p3h2x4x_hub->regmap, P3H2X4X_TP_NET_CON_CONF, ntwk_mask);
> +#if IS_ENABLED(CONFIG_I2C_SLAVE)
> +	ret = i3c_device_request_ibi(p3h2x4x_hub->i3cdev, &p3h2x4x_ibireq);
> +	if (ret)
> +		return ret;
> +
> +	ret = i3c_device_enable_ibi(p3h2x4x_hub->i3cdev);

[Severity: High]
Because these IBI functions are not devres-managed, do we need to manually
clean them up on a probe failure?

If a subsequent step in p3h2x4x_i3c_hub_probe() fails after this completes,
probe will abort and devres will free the p3h2x4x_i3c_hub structure. Since
the I3C core isn't informed to free the IBI, the hardware remains
configured. If an IBI fires later, could p3h2x4x_ibi_handler() try to
dereference the freed driver data?

[ ... ]
> diff --git a/drivers/i3c/hub/p3h2840_i3c_hub_smbus.c b/drivers/i3c/hub/p3h2840_i3c_hub_smbus.c
> --- a/drivers/i3c/hub/p3h2840_i3c_hub_smbus.c
> +++ b/drivers/i3c/hub/p3h2840_i3c_hub_smbus.c
[ ... ]
> @@ -15,6 +15,146 @@ enum p3h2x4x_smbus_desc_idx {
>  	P3H2X4X_DESC_READ_LEN,
>  };
>  
> +#if IS_ENABLED(CONFIG_I2C_SLAVE)
> +static void p3h2x4x_read_smbus_agent_rx_buf(struct i3c_device *i3cdev, enum p3h2x4x_rcv_buf rfbuf,
> +					    enum p3h2x4x_tp tp, bool is_of)
> +{
[ ... ]
> +	/* notify slave driver about received data */
> +	if ((p3h2x4x_i3c_hub->tp_bus[tp].tp_smbus_client->addr & 0x7f) == (slave_address >> 1)) {
> +		client = p3h2x4x_i3c_hub->tp_bus[tp].tp_smbus_client;
> +		if (!client)
> +			goto ibi_err;

[Severity: High]
Can this code cause a panic if an In-Band Interrupt occurs for a port
without a bound SMBus slave client?

We dereference tp_smbus_client->addr unconditionally here, right before
the NULL check happens.

[ ... ]
> +void p3h2x4x_ibi_handler(struct i3c_device *i3cdev,
> +			 const struct i3c_ibi_payload *payload)
> +{
[ ... ]
> +	for (i = 0; i < P3H2X4X_TP_MAX_COUNT; ++i) {
> +		if (p3h2x4x_i3c_hub->tp_bus[i].is_registered && (payload_byte_two >> i) & 0x01) {
> +			ret = regmap_read(p3h2x4x_i3c_hub->regmap, P3H2X4X_TP0_SMBUS_AGNT_STS + i,
> +					  &target_port_status);
> +			if (ret) {
> +				dev_err(&i3cdev->dev, "target port read status failed %d\n", ret);
> +				return;
> +			}

[Severity: High]
If regmap_read() fails for one port, this return statement prematurely
exits the handler.

Does this skip clearing the hardware status of the current port and prevent
servicing other ports with pending events? If the underlying hardware
interrupt conditions are not cleared, could the device immediately re-assert
the IBI line and cause an interrupt storm?

[ ... ]
> +static int p3h2x4x_tp_i2c_unreg_slave(struct i2c_client *slave)
> +{
[ ... ]
> +	ret = regmap_clear_bits(hub->regmap,
> +				P3H2X4X_TP_SMBUS_AGNT_IBI_CONFIG,
> +				bus->tp_mask);
> +	if (ret)
> +		return ret;
> +
> +	bus->tp_smbus_client = NULL;

[Severity: High]
If regmap_clear_bits() fails, we return the error without clearing
bus->tp_smbus_client.

Since the client driver might still free its i2c_client structure during
removal despite the unregistration failure, could this leave a dangling
pointer that gets dereferenced if an IBI fires later?

[ ... ]
> @@ -205,11 +345,63 @@ static u32 p3h2x4x_tp_smbus_funcs(struct i2c_adapter *adapter)
>  	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_BLOCK_DATA;
>  }
>  
[ ... ]
>  /*
>  * I2C algorithm Structure
>  */
>  static struct i2c_algorithm p3h2x4x_tp_i2c_algorithm = {
>  	.master_xfer    = p3h2x4x_tp_i2c_xfer,
> +#if IS_ENABLED(CONFIG_I2C_SLAVE)
> +	.reg_slave = p3h2x4x_tp_i2c_reg_slave,
> +	.unreg_slave = p3h2x4x_tp_i2c_unreg_slave,
> +#endif
>  	.functionality  = p3h2x4x_tp_smbus_funcs,
>  };

[Severity: High]
This is a pre-existing issue, but I2C adapters registered in
p3h2x4x_tp_smbus_algo() lack a devres action for automatic cleanup.

If p3h2x4x_i3c_hub_probe() encounters an error after adapters are added
with i2c_add_adapter(), devres will free the memory backing the adapters,
but they remain registered with the I2C subsystem.

Could this lead to a use-after-free if the I2C core accesses these ghost
adapters?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260612111816.3688240-1-lakshay.piplani@nxp.com?part=9

      reply	other threads:[~2026-06-12 11:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-12 11:18 [PATCH v11 0/9] Add support for NXP P3H2x4x I3C hub driver Lakshay Piplani
2026-06-12 11:18 ` [PATCH v11 1/9] i3c: master: rename i3c_master_reattach_i3c_dev() to *_locked Lakshay Piplani
2026-06-12 11:41   ` sashiko-bot
2026-06-12 11:18 ` [PATCH v11 2/9] i3c: master: Expose the APIs to support I3C hub Lakshay Piplani
2026-06-12 11:44   ` sashiko-bot
2026-06-12 11:18 ` [PATCH v11 3/9] i3c: master: Add APIs for I3C hub support Lakshay Piplani
2026-06-12 11:48   ` sashiko-bot
2026-06-12 11:18 ` [PATCH v11 4/9] dt-bindings: i3c: Add NXP P3H2x4x i3c-hub support Lakshay Piplani
2026-06-12 11:33   ` sashiko-bot
2026-06-12 11:18 ` [PATCH v11 5/9] mfd: p3h2x4x: Add driver for NXP P3H2x4x i3c hub and on-die regulator Lakshay Piplani
2026-06-12 11:41   ` sashiko-bot
2026-06-12 11:18 ` [PATCH v11 6/9] regulator: p3h2x4x: Add driver for on-die regulators in NXP P3H2x4x i3c hub Lakshay Piplani
2026-06-12 11:37   ` sashiko-bot
2026-06-12 11:18 ` [PATCH v11 7/9] i3c: hub: Add support for the I3C interface in the I3C hub Lakshay Piplani
2026-06-12 11:41   ` sashiko-bot
2026-06-12 12:09   ` Julian Braha
2026-06-12 11:18 ` [PATCH v11 8/9] i3c: hub: p3h2x4x: Add support for NXP P3H2x4x I3C hub functionality Lakshay Piplani
2026-06-12 11:39   ` sashiko-bot
2026-06-12 11:18 ` [PATCH v11 9/9] i3c: hub: p3h2x4x: Add SMBus slave mode support Lakshay Piplani
2026-06-12 11:41   ` 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=20260612114155.081851F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=lakshay.piplani@nxp.com \
    --cc=linux-i3c@lists.infradead.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