Devicetree
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: sashiko-reviews@lists.linux.dev
Cc: Junyi Zhao <junyi.zhao@amlogic.com>,
	linux-i3c@lists.infradead.org, devicetree@vger.kernel.org,
	linux-amlogic@lists.infradead.org, imx@lists.linux.dev,
	robh@kernel.org, conor+dt@kernel.org, Frank.Li@kernel.org,
	neil.armstrong@linaro.org,
	Alexandre Belloni <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH v4 2/2] i3c: master: svc: Add amlogic a9 support
Date: Mon, 16 Nov 2026 10:28:53 -0600	[thread overview]
Message-ID: <avsvRS6ADfbzQkpn@SMW015318> (raw)
In-Reply-To: <sashiko-outbox-216859@kernel.org>

On Mon, Nov 16, 2026 at 11:12:37AM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential
> issues to consider:
> - [Medium] i3c: master: svc: NULL dereference of clks[0].id in
>   aml_i3c_init()
> - [Medium] i3c: master: svc: clocks left enabled in
>   svc_i3c_master_remove()
> - [Low] i3c: master: svc: duplicate fast_clk lookup in aml_i3c_init()
> --
>
> commit 260aeb5a4d5c58d3bea32674062960231e4d4d2c
> Author: Junyi Zhao <junyi.zhao@amlogic.com>
>
> i3c: master: svc: Add amlogic a9 support
>
> This commit adds support for the Amlogic A9 EE-domain and AO-domain Silvaco
> I3C controllers, introducing a vendor_init callback to register the AO
> variant's internal clock divider chain and configure the fast_clk rate.
>
> > diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c
> > index e700392f0801f..0268fc713afdf 100644
> > --- a/drivers/i3c/master/svc-i3c-master.c
> > +++ b/drivers/i3c/master/svc-i3c-master.c
>
> [ ... ]
>
> > @@ -2163,9 +2209,215 @@ static const struct svc_i3c_drvdata npcm845_drvdata = {
>
> [ ... ]
>
> > +	/*
> > +	 * Keep the clk bulk state balanced for the following
> > +	 * clk_bulk_disable_unprepare() calls (error paths and runtime PM).
> > +	 */
> > +	ret = clk_prepare_enable(fclk);
> > +	if (ret)
> > +		return dev_err_probe(dev, ret, "can't enable fast_clk\n");
> > +
> > +	new_clks = devm_kcalloc(dev, master->num_clks + 1, sizeof(*new_clks),
> > +				GFP_KERNEL);
> > +	if (!new_clks) {
> > +		clk_disable_unprepare(fclk);
> > +		return -ENOMEM;
> > +	}
> > +
> > +	memcpy(new_clks, master->clks,
> > +	       master->num_clks * sizeof(*master->clks));
> > +	new_clks[master->num_clks].id = "fast_clk";
> > +	new_clks[master->num_clks].clk = fclk;
> > +	master->clks = new_clks;
> > +	master->num_clks++;
> > +
> > +	return 0;
> > +}
>
> [Severity: Medium]
> Can unbinding the driver leave fclk and the input clocks enabled when the
> device is not runtime-suspended?
>
> svc_i3c_master_remove() calls pm_runtime_dont_use_autosuspend() and
> pm_runtime_disable(), relying on svc_i3c_runtime_suspend() to call
> clk_bulk_disable_unprepare().  If CONFIG_PM is disabled, runtime PM is
> forbidden via sysfs, or hotjoin is enabled (which holds a runtime PM
> reference not released by i3c_master_unregister()), runtime suspend does
> not run during remove.  When devres then unregisters ao->gate.hw,
> ao->div.hw, and ao->div_en.hw while they are still prepared and enabled,
> clk_unregister() triggers a kernel warning and leaks the prepare and
> enable counts on the parent pclk.

Suppose it is existing problem.

>
> > +
> > +/**
> > + * aml_i3c_init - Amlogic A9 specific init, called with the clocks enabled
> > + * @master: I3C master controller
> > + *
> > + * Register the AO variant's internal divider chain and round/set the fast
> > + * clock rate for both variants.
> > + *
> > + * Return: 0 on success, or a negative error code.
> > + */
> > +static int aml_i3c_init(struct svc_i3c_master *master)
> > +{
> > +	struct device *dev = master->dev;
> > +	struct clk *fclk;
> > +	long fin_freq;
> > +	int ret, i;
> > +
> > +	if (svc_has_quirk(master, AML_I3C_QUIRK_AO)) {
> > +		/*
> > +		 * clk_bulk_get_all() preserves the DT order, and the
> > +		 * binding restricts the AO variant to exactly one clock,
> > +		 * which is always "pclk".  So clks[0] is the input of the
> > +		 * internal divider chain.
> > +		 */
> > +		if (strcmp(master->clks[0].id, "pclk"))
> > +			return dev_err_probe(dev, -EINVAL,
> > +					     "invalid AO input clock\n");
>
> [Severity: Medium]
> Can this trigger a NULL pointer dereference on master->clks or
> master->clks[0].id?
>
> When a device tree node has no clocks, devm_clk_bulk_get_all() returns 0
> and leaves master->clks as NULL, which passes the master->num_clks < 0
> check in svc_i3c_master_probe().  Previously, the fast_clk loop in probe
> ran zero iterations and returned -EINVAL, but aml_i3c_init() now runs
> first and indexes master->clks[0] without checking that master->num_clks
> is at least 1 (or equal to 1 as required by the AO binding).  In addition,
> of_clk_bulk_get() leaves clks[i].id as NULL if clock-names is missing or
> shorter than clocks, which would cause strcmp() here and in the fast_clk
> loop below to dereference NULL.

This one need check.

Frank

>
> > +
> > +		ret = aml_ao_i3c_tail_clocks(master, master->clks[0].clk);
> > +		if (ret)
> > +			return ret;
> > +	}
> > +
> > +	for (i = 0; i < master->num_clks; i++) {
> > +		if (!strcmp(master->clks[i].id, "fast_clk"))
> > +			break;
> > +	}
> > +
> > +	if (i == master->num_clks)
> > +		return dev_err_probe(dev, -EINVAL,
> > +				     "can't get I3C fast clock\n");
> > +
> > +	fclk = master->clks[i].clk;
> > +	if (IS_ERR(fclk))
> > +		return PTR_ERR(fclk);
>
> [Severity: Low]
> This isn't a bug, but this fast_clk lookup and validation duplicates the
> identical loop in svc_i3c_master_probe() that runs right after
> vendor_init() returns.  Could a shared helper or resolving master->fclk
> once avoid repeating the lookup?
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261116-a9_i3c-v4-0-3d3222b7128d@amlogic.com?part=2

      reply	other threads:[~2026-11-16 16:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 10:49 [PATCH v4 0/2] Add Amlogic A9 I3C support Junyi Zhao via B4 Relay
2026-11-16 10:49 ` [PATCH v4 1/2] dt-bindings: i3c: silvaco,i3c-master: Add Amlogic A9 support Junyi Zhao via B4 Relay
2026-11-16 11:00   ` sashiko-bot
2026-11-16 16:08   ` Frank Li
2026-11-16 10:49 ` [PATCH v4 2/2] i3c: master: svc: Add amlogic a9 support Junyi Zhao via B4 Relay
2026-11-16 11:12   ` sashiko-bot
2026-11-16 16:28     ` Frank Li [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=avsvRS6ADfbzQkpn@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=junyi.zhao@amlogic.com \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-i3c@lists.infradead.org \
    --cc=neil.armstrong@linaro.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