Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jonas Jelonek" <jelonek.jonas@gmail.com>
Cc: robh@kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v5 3/4] net: pse-pd: realtek-pse-mcu: add I2C transport
Date: Tue, 07 Jul 2026 11:24:51 +0000	[thread overview]
Message-ID: <20260707112452.2840A1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260706112425.3149226-4-jelonek.jonas@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unsafe DMA on stack-allocated buffers in native I2C transport.
--

commit 0cfb33bb6548fde90d8e33161d69d564f969591e
Author: Jonas Jelonek <jelonek.jonas@gmail.com>

net: pse-pd: realtek-pse-mcu: add I2C transport

Add the I2C/SMBus transport for the Realtek/Broadcom PSE MCU core. It
registers the MCU on an I2C bus and provides the send/recv callbacks the
core uses to exchange the 12-byte frames.

> diff --git a/drivers/net/pse-pd/realtek-pse-mcu-i2c.c b/drivers/net/pse-pd/realtek-pse-mcu-i2c.c
> new file mode 100644
> index 0000000000000..6e6e3645c5090
> --- /dev/null
> +++ b/drivers/net/pse-pd/realtek-pse-mcu-i2c.c

[ ... ]

> +static int rtpse_mcu_i2c_native_send(struct rtpse_mcu_ctrl *pse, const struct rtpse_mcu_msg *req)
> +{
> +	struct i2c_client *client = to_i2c_client(pse->dev);
> +	int ret;
> +
> +	ret = i2c_master_send(client, (const u8 *)req, RTPSE_MCU_MSG_SIZE);

[Severity: High]
Does this code pass a stack-allocated buffer to i2c_master_send()?

If the underlying I2C bus master driver uses DMA for this 12-byte transfer,
passing a stack address can trigger a BUG/WARN on systems with
CONFIG_VMAP_STACK=y, or corrupt memory due to cache line sharing.

It looks like the req buffer is allocated on the stack in the core driver,
for example in rtpse_mcu_port_query():

drivers/net/pse-pd/realtek-pse-mcu-core.c:rtpse_mcu_port_query() {
	...
	struct rtpse_mcu_msg req;
	...
}

> +	if (ret < 0)
> +		return ret;
> +	return ret == RTPSE_MCU_MSG_SIZE ? 0 : -EIO;
> +}
> +
> +static int rtpse_mcu_i2c_native_recv(struct rtpse_mcu_ctrl *pse, const struct rtpse_mcu_msg *req,
> +				     struct rtpse_mcu_msg *resp)
> +{
> +	struct i2c_client *client = to_i2c_client(pse->dev);
> +	int tries, ret;
> +
> +	for (tries = 0; tries < RTPSE_MCU_I2C_MAX_TRIES; tries++) {
> +		if (tries > 0)
> +			msleep(RTPSE_MCU_I2C_RETRY_MS);
> +
> +		ret = i2c_master_recv(client, (u8 *)resp, RTPSE_MCU_MSG_SIZE);

[Severity: High]
Can this code also pass a stack-allocated buffer to i2c_master_recv()
for the resp pointer?

Like with req, resp also seems to be allocated on the stack in the core driver.

> +		if (ret < 0)
> +			return ret;
> +		if (ret == RTPSE_MCU_MSG_SIZE && rtpse_mcu_resp_is_final(req, resp))
> +			return 0;
> +	}
> +
> +	return -ETIMEDOUT;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260706112425.3149226-1-jelonek.jonas@gmail.com?part=3

  reply	other threads:[~2026-07-07 11:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-06 11:24 [PATCH net-next v5 0/4] net: pse-pd: add Realtek/Broadcom PSE MCU support Jonas Jelonek
2026-07-06 11:24 ` [PATCH net-next v5 1/4] dt-bindings: net: pse-pd: add bindings for Realtek/Broadcom PSE MCU Jonas Jelonek
2026-07-06 17:35   ` Conor Dooley
2026-07-06 20:30     ` Jonas Jelonek
2026-07-07 17:25       ` Conor Dooley
2026-07-07 20:50         ` Jonas Jelonek
2026-07-08 16:56           ` Conor Dooley
2026-07-08 19:44             ` Jonas Jelonek
2026-07-06 11:24 ` [PATCH net-next v5 2/4] net: pse-pd: add Realtek/Broadcom PSE MCU core Jonas Jelonek
2026-07-06 17:12   ` Uwe Kleine-König
2026-07-07 12:00     ` Jonas Jelonek
2026-07-06 11:24 ` [PATCH net-next v5 3/4] net: pse-pd: realtek-pse-mcu: add I2C transport Jonas Jelonek
2026-07-07 11:24   ` sashiko-bot [this message]
2026-07-06 11:24 ` [PATCH net-next v5 4/4] net: pse-pd: realtek-pse-mcu: add UART transport Jonas Jelonek

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=20260707112452.2840A1F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jelonek.jonas@gmail.com \
    --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