Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ryan Chen" <ryan_chen@aspeedtech.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v31 2/5] i2c: aspeed: Read clock-frequency via i2c_parse_fw_timings()
Date: Wed, 03 Jun 2026 06:12:22 +0000	[thread overview]
Message-ID: <20260603061222.EE6BC1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260603-upstream_i2c-v31-2-ba7a02714f22@aspeedtech.com>

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

Pre-existing issues:
- [High] Kernel panic via division by zero when bus frequency is configured to 0 in device tree.
--

commit 7def856c61d40b684f656602f5cf38ffd5745272
Author: Ryan Chen <ryan_chen@aspeedtech.com>

i2c: aspeed: Read clock-frequency via i2c_parse_fw_timings()

This commit transitions the driver to use i2c_parse_fw_timings() for parsing
the standard clock-frequency property. It maintains backward compatibility by
falling back to the legacy bus-frequency property if the standard one is
missing.

> diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c
> --- a/drivers/i2c/busses/i2c-aspeed.c
> +++ b/drivers/i2c/busses/i2c-aspeed.c
> @@ -1025,12 +1026,18 @@ static int aspeed_i2c_probe_bus(struct platform_device *pdev)
>  	}
>  	reset_control_deassert(bus->rst);
>  
> -	ret = of_property_read_u32(pdev->dev.of_node,
> -				   "bus-frequency", &bus->bus_frequency);
> -	if (ret < 0) {
> -		dev_err(&pdev->dev,
> -			"Could not read bus-frequency property\n");
> -		bus->bus_frequency = I2C_MAX_STANDARD_MODE_FREQ;
> +	i2c_parse_fw_timings(&pdev->dev, &timings, false);
> +	if (timings.bus_freq_hz) {
> +		bus->bus_frequency = timings.bus_freq_hz;
> +	} else {
> +		ret = of_property_read_u32(pdev->dev.of_node,
> +					   "bus-frequency",
> +					   &bus->bus_frequency);

[Severity: High]
This isn't a bug introduced by this patch, but is it possible for a malformed
device tree to cause a kernel panic here?

If the device tree specifies bus-frequency = <0> and clock-frequency is
absent or also 0, of_property_read_u32() successfully reads 0 into
bus->bus_frequency.

Since the frequency is not validated to be strictly positive, wouldn't this
later trigger a division by zero exception in aspeed_i2c_init_clk() when
calculating the divisor?

drivers/i2c/busses/i2c-aspeed.c:aspeed_i2c_init_clk() {
    ...
    divisor = DIV_ROUND_UP(bus->parent_clk_frequency, bus->bus_frequency);
    ...
}

Should we add a check to handle a 0 hz configuration gracefully rather than
crashing during device probe?

> +		if (ret < 0) {
> +			dev_err(&pdev->dev,
> +				"Could not read clock-frequency or bus-frequency property\n");
> +			bus->bus_frequency = I2C_MAX_STANDARD_MODE_FREQ;
> +		}
>  	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260603-upstream_i2c-v31-0-ba7a02714f22@aspeedtech.com?part=2

  reply	other threads:[~2026-06-03  6:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03  5:50 [PATCH v31 0/5] Add ASPEED AST2600 I2C controller driver Ryan Chen
2026-06-03  5:50 ` [PATCH v31 1/5] dt-bindings: i2c: Split AST2600 binding into a new YAML Ryan Chen
2026-06-03  6:04   ` sashiko-bot
2026-06-03  5:50 ` [PATCH v31 2/5] i2c: aspeed: Read clock-frequency via i2c_parse_fw_timings() Ryan Chen
2026-06-03  6:12   ` sashiko-bot [this message]
2026-06-03  5:50 ` [PATCH v31 3/5] dt-bindings: i2c: ast2600-i2c.yaml: Add global-regs properties Ryan Chen
2026-06-03  5:50 ` [PATCH v31 4/5] i2c: ast2600: Add controller driver for AST2600 new register set Ryan Chen
2026-06-03  6:25   ` sashiko-bot
2026-06-03  5:50 ` [PATCH v31 5/5] i2c: ast2600: Add target mode support Ryan Chen
2026-06-03  6:38   ` 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=20260603061222.EE6BC1F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=ryan_chen@aspeedtech.com \
    --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