[PATCH v4 2/2] i3c: master: svc: Add amlogic a9 support
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Mon Nov 16 03:12:37 PST 2026
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 at 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.
> +
> +/**
> + * 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.
> +
> + 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
More information about the linux-i3c
mailing list