Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andy Chung" <Andy.Chung@amd.com>
Cc: conor+dt@kernel.org, robh@kernel.org,
	linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v3 3/4] hwmon: (kb9002) Add driver for Kandou KB9002 retimer
Date: Tue, 21 Jul 2026 06:43:15 +0000	[thread overview]
Message-ID: <20260721064315.DCD4B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260721-kb9002-upstream-v3-3-70563922be8d@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Stack-allocated buffers are passed to `i2c_transfer()`, which is unsafe if the underlying I2C adapter driver uses DMA.
--

--- Patch [3]: [PATCH v3 3/4] hwmon: (kb9002) Add driver for Kandou KB9002 retimer ---
commit 2acb53c63efe6bebfdbda9c58f2be139429caa78
Author: Andy Chung <Andy.Chung@amd.com>

hwmon: (kb9002) Add driver for Kandou KB9002 retimer

This commit adds a hwmon driver for the Kandou KB9002 8-lane PCIe 5.0
retimer. It exposes the firmware aggregated maximum die temperature as
temp1_input and adds debugfs entries for firmware version and boot status.

> diff --git a/drivers/hwmon/kb9002.c b/drivers/hwmon/kb9002.c
> new file mode 100644
> index 0000000000000..61a6e522e770d
> --- /dev/null
> +++ b/drivers/hwmon/kb9002.c

[ ... ]

> +static int kb9002_i2c_read(struct i2c_client *client, u32 reg, u32 *val)
> +{
> +	u8 addr[4];
> +	u8 rbuf[4];
> +	struct i2c_msg msgs[2] = {
> +		{
> +			.addr = client->addr,
> +			.flags = 0,
> +			.len = sizeof(addr),
> +			.buf = addr,
> +		},
> +		{
> +			.addr = client->addr,
> +			.flags = I2C_M_RD,
> +			.len = sizeof(rbuf),
> +			.buf = rbuf,
> +		},
> +	};
> +	int ret;
> +
> +	put_unaligned_be32(reg, addr);
> +
> +	ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));

[Severity: High]
Does this pass stack-allocated buffers (addr and rbuf) to i2c_transfer()?
Passing stack memory to the I2C API is unsafe if the underlying adapter uses
DMA, which can lead to mapping errors or stack memory corruption. Could these
buffers be allocated dynamically or placed in a device data structure instead?

> +	if (ret < 0)

[ ... ]

> +static int kb9002_i2c_write(struct i2c_client *client, u32 reg, u32 val)
> +{
> +	u8 buf[8];
> +	struct i2c_msg msg = {
> +		.addr = client->addr,
> +		.flags = 0,
> +		.len = sizeof(buf),
> +		.buf = buf,
> +	};
> +	int ret;
> +
> +	put_unaligned_be32(reg, &buf[0]);
> +	put_unaligned_be32(val, &buf[4]);
> +
> +	ret = i2c_transfer(client->adapter, &msg, 1);

[Severity: High]
Are we also passing the stack-allocated buf to i2c_transfer() here?
Similar to the read path, using stack memory for I2C transfers is unsafe
for adapters that use DMA.

> +	if (ret < 0)

[ ... ]

> +static int kb9002_read_revid(struct i2c_client *client, u32 *revid)
> +{
> +	u8 dummy;
> +	int ret;
> +	int i;
> +
> +	for (i = 0; i < KB9002_REVID_READ_RETRIES; i++) {
> +		ret = kb9002_i2c_read(client, KB9002_HW_REG_REVID, revid);
> +		if (ret)
> +			return ret;
> +		if ((*revid >> 24) != 0xff)
> +			return 0;
> +		/* Drain one byte from the chip to re-align the I2C FIFO. */
> +		i2c_master_recv(client, &dummy, 1);

[Severity: High]
Does i2c_master_recv() receive the stack-allocated dummy variable?
This function internally calls i2c_transfer(), which again risks DMA
mapping issues with stack memory.

> +	}
> +
> +	return -EIO;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260721-kb9002-upstream-v3-0-70563922be8d@amd.com?part=3

  reply	other threads:[~2026-07-21  6:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21  6:31 [PATCH v3 0/4] hwmon: Add Kandou KB9002 PCIe retimer driver Andy Chung via B4 Relay
2026-07-21  6:31 ` [PATCH v3 1/4] dt-bindings: Add vendor prefix for Kandou Andy Chung via B4 Relay
2026-07-21  6:34   ` sashiko-bot
2026-07-21  8:27   ` Krzysztof Kozlowski
2026-07-21  6:31 ` [PATCH v3 2/4] dt-bindings: hwmon: Add Kandou KB9002 Andy Chung via B4 Relay
2026-07-21  6:50   ` sashiko-bot
2026-07-21  6:31 ` [PATCH v3 3/4] hwmon: (kb9002) Add driver for Kandou KB9002 retimer Andy Chung via B4 Relay
2026-07-21  6:43   ` sashiko-bot [this message]
2026-07-21 14:43   ` Guenter Roeck
2026-07-21  6:31 ` [PATCH v3 4/4] hwmon: (kb9002) Add documentation Andy Chung via B4 Relay
2026-07-21  6:43   ` sashiko-bot

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=20260721064315.DCD4B1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Andy.Chung@amd.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-hwmon@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