Linux clock framework development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>,
	linux-clk@vger.kernel.org, devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v14 5/5] clk: en7523: add support for Airoha AN7583 clock
Date: Fri, 20 Nov 2026 23:42:20 +0000	[thread overview]
Message-ID: <sashiko-outbox-226349@kernel.org> (raw)
In-Reply-To: <20261120233535.164885-6-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] clk: en7523: out-of-bounds read in en7581_register_clocks() on
  AN7583
- [Medium] clk: en7523: AN7583 MDIO clocks lack rate ops in
  en7581_register_clocks()
--

commit d321ffe6fe44430a284c1d8c5334df8f429f0678
Author: Christian Marangi <ansuelsmth@gmail.com>

clk: en7523: add support for Airoha AN7583 clock

This commit adds clock and reset controller support for the Airoha AN7583
SoC to the en7523 driver, including base clock descriptors, MDIO clocks,
and a reset mapping table.

> diff --git a/drivers/clk/clk-en7523.c b/drivers/clk/clk-en7523.c
> index a4a75b8063a58..71ed5d3362701 100644
> --- a/drivers/clk/clk-en7523.c
> +++ b/drivers/clk/clk-en7523.c

[ ... ]

> +	}, {
> +		.id = AN7583_CLK_MDIO0,
> +		.name = "mdio0",
> +
> +		.base_reg = REG_CRYPTO_CLKSRC2,
> +
> +		.base_value = 25000000,
> +
> +		.div_bits = 4,
> +		.div_shift = 15,
> +		.div_step = 1,
> +		.div_offset = 1,
> +	}, {
> +		.id = AN7583_CLK_MDIO1,
> +		.name = "mdio1",
> +
> +		.base_reg = REG_CRYPTO_CLKSRC2,
> +
> +		.base_value = 25000000,
> +
> +		.div_bits = 4,
> +		.div_shift = 19,
> +		.div_step = 1,
> +		.div_offset = 1,
> +	}
> +};

[Severity: Medium]
As reported by Brian Masney on v13 [1], does registering AN7583_CLK_MDIO0
and AN7583_CLK_MDIO1 through en7581_register_clocks() prevent consumers
from configuring the MDIO divider?

en7581_register_clocks() registers every entry in soc_data->base_clks via
devm_clk_hw_register_fixed_rate(), which lacks .set_rate, .round_rate, and
.determine_rate callbacks.  When airoha_mdio_probe() calls clk_set_rate()
to divide the 25 MHz default down to 2.5 MHz, clk_set_rate() returns 0
without writing the 4-bit divider in REG_CRYPTO_CLKSRC2, leaving the MDIO
bus running at 25 MHz.

[ ... ]

> @@ -1300,6 +1536,18 @@ static const struct en_clk_soc_data en7581_data = {
>  	.hw_init = en7581_clk_hw_init,
>  };
>  
> +static const struct en_clk_soc_data an7583_data = {
> +	.base_clks = an7583_base_clks,
> +	/* We increment num_clocks by 1 to account for additional PCIe clock */
> +	.num_clocks = ARRAY_SIZE(an7583_base_clks) + 1,
> +	.pcie_ops = {
> +		.is_enabled = en7581_pci_is_enabled,
> +		.enable = en7581_pci_enable,
> +		.disable = en7581_pci_disable,
> +	},
> +	.hw_init = an7583_clk_hw_init,
> +};

[Severity: High]
Does setting .num_clocks to ARRAY_SIZE(an7583_base_clks) + 1 cause an
out-of-bounds read past an7583_base_clks[] in en7581_register_clocks()?

Earlier in the series, commit "clk: en7523: generalize register clocks
function" updated en7523_clk_probe() to add 1 to num_clocks when
soc_data->pcie_ops.is_enabled is set, and changed en7581_register_clocks()
to loop up to soc_data->num_clocks over soc_data->base_clks[] before
registering the PCIe clock separately:

drivers/clk/clk-en7523.c:en7581_register_clocks() {
	...
	for (i = 0; i < soc_data->num_clocks; i++) {
		const struct en_clk_desc *desc = &soc_data->base_clks[i];
	...
}

With + 1 here, the final iteration reads one element past the end of
an7583_base_clks[], dereferencing an invalid descriptor during probe and
double-counting the PCIe clock in clk_data->num.  Like en7581_data,
.num_clocks should be ARRAY_SIZE(an7583_base_clks).

[1] https://lore.kernel.org/r/179513295004.301584.12820965897975670200.b4-review@b4

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120233535.164885-1-ansuelsmth@gmail.com?part=5

      reply	other threads:[~2026-11-20 23:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 23:35 [PATCH v14 0/5] clk: add support for Airoha AN7583 clock Christian Marangi
2026-11-20 23:35 ` [PATCH v14 1/5] dt-bindings: clock: airoha: Document support for " Christian Marangi
2026-11-20 23:35 ` [PATCH v14 2/5] clk: en7523: use devm variant for clk_hw_register and fixed clock Christian Marangi
2026-11-20 23:35 ` [PATCH v14 3/5] clk: en7523: protect concurrent access to reset and PCI register Christian Marangi
2026-11-20 23:35 ` [PATCH v14 4/5] clk: en7523: generalize register clocks function Christian Marangi
2026-11-20 23:35 ` [PATCH v14 5/5] clk: en7523: add support for Airoha AN7583 clock Christian Marangi
2026-11-20 23:42   ` 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=sashiko-outbox-226349@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ansuelsmth@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-clk@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