Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alex Elder" <elder@riscstar.com>
Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v4 2/4] clk: toshiba: introduce a TC9564 clock driver
Date: Tue, 01 Dec 2026 16:21:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-243673@kernel.org> (raw)
In-Reply-To: <20261201160810.2422466-3-elder@riscstar.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] clk: tc9564: conflicting OF clock providers registered on
  same DT node
- [Medium] clk: tc9564: premature kfree() of reset_aux outside
  reset_dev_release()
- [Medium] clk: tc9564: missing select AUXILIARY_BUS in Kconfig for
  COMMON_CLK_TC9564
- [Low] clk: tc9564: hardcoded adev->id in devm_reset_setup() breaks
  multi-instance
- [Low] clk: tc9564: unused lock field, write-only gate_data, and reset
  header
--

commit 36b5909afe8d085c12caff8d18e2b1828c4c5a70
Author: Alex Elder <elder@kernel.org>

clk: toshiba: introduce a TC9564 clock driver

This commit adds a platform driver for the Toshiba TC9564 SoC clock
controller and registers an auxiliary device for the SoC reset controller.

> diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
> index 6bfa2c8fffe1b..a3d89c55f17a5 100644
> --- a/drivers/clk/Kconfig
> +++ b/drivers/clk/Kconfig
> @@ -185,6 +185,14 @@ config COMMON_CLK_CDCE706
>  	help
>  	  This driver supports TI CDCE706 programmable 3-PLL clock synthesizer.
>  
> +config COMMON_CLK_TC9564
> +	tristate "Toshiba TC9564 clock support"
> +	help
> +	  This enables support for the clock controller embedded in the
> +	  Toshiba TC9564 SoC.  It is also required to support the embedded
> +	  reset device, which is represented as an auxiliary device created
> +	  by the clock controller driver.

[Severity: Medium]
Should COMMON_CLK_TC9564 select AUXILIARY_BUS?  devm_reset_setup() calls
auxiliary_device_init() and auxiliary_device_add(), which are only built
when CONFIG_AUXILIARY_BUS is enabled, so linking fails with undefined
references when no other enabled driver selects AUXILIARY_BUS.

> diff --git a/drivers/clk/clk-tc9564.c b/drivers/clk/clk-tc9564.c
> new file mode 100644
> index 0000000000000..ec72a0207fd87
> --- /dev/null
> +++ b/drivers/clk/clk-tc9564.c
> @@ -0,0 +1,401 @@
[ ... ]
> +#include <linux/platform_device.h>
> +#include <linux/reset-controller.h>
> +#include <linux/slab.h>
[ ... ]
> +struct tc9564_clock {
> +	void __iomem *ioaddr;	/* Mapped clock/reset registers */
> +	spinlock_t lock;	/* Protects reset register updates */
> +	struct clk_hw *pll_hw;
> +	struct clk_hw_onecell_data *fixed_data;
> +	struct clk_hw_onecell_data *gate_data;
> +};

[Severity: Low]
This isn't a bug, but <linux/reset-controller.h> and clock->lock appear to
be unused leftovers from splitting out the reset driver, and
clock->gate_data is only written in gate_clock_setup() and never read.

[ ... ]

> +/* Initialize the PLL (parent is the input oscillator); called from probe */
> +static int pll_setup(struct device *dev)
> +{
> +	const char *name __free(kfree) = clock_name_alloc(dev, "pll");
> +	struct tc9564_clock *clock = dev_get_drvdata(dev);
> +	struct clk_hw *hw;
> +	int ret;
> +
> +	if (!name)
> +		return -ENOMEM;
> +
> +	hw = devm_clk_hw_register_fixed_factor_index(dev, name, 0, 0, 50, 1);
> +	if (IS_ERR(hw))
> +		return dev_err_probe(dev, PTR_ERR(hw),
> +				     "failed to register pll\n");
> +
> +	ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, hw);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "failed to add pll provider\n");
> +
> +	clock->pll_hw = hw;
> +
> +	return 0;
> +}
> +
> +/* Initialize the fixed rate clocks (PLL is parent); called from probe */
> +static int fixed_clock_setup(struct device *dev)
> +{
[ ... ]
> +	ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
> +					  fixed_data);
> +	if (ret)
> +		return dev_err_probe(dev, ret,
> +				     "failed to add fixed clock provider\n");
> +
> +	clock->fixed_data = fixed_data;
> +
> +	return 0;
> +}
> +
> +/* Initialize the gate clocks; called from probe */
> +static int gate_clock_setup(struct device *dev)
> +{
[ ... ]
> +	ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
> +					  gate_data);
> +	if (ret)
> +		return dev_err_probe(dev, ret,
> +				     "failed to add gate clock provider\n");
> +
> +	clock->gate_data = gate_data;
> +
> +	return 0;
> +}

[Severity: Medium]
Should only gate_clock_setup() call devm_of_clk_add_hw_provider()?

Calling devm_of_clk_add_hw_provider() in pll_setup(), fixed_clock_setup(),
and gate_clock_setup() registers three OF clock providers on the same
dev->of_node.  Because the PLL and fixed-factor clocks are wired as
internal parents via clk_hw pointers and the DT binding only exports the
gate clocks, the extra providers mark the DT node initialized and run
of_clk_set_defaults() before the gate clocks exist.  Also, in
of_clk_get_hw_from_clkspec(), any out-of-range clock index falls through
gate_data and fixed_data to of_clk_hw_simple_get(), returning pll_hw
instead of -EINVAL.

> +
> +
> +static void reset_dev_release(struct device *dev)
> +{
> +	of_node_put(dev->of_node);
> +}
> +
> +static struct reset_aux *adev_to_reset_aux(struct auxiliary_device *adev)
> +{
> +	return container_of(adev, struct reset_aux, adev);
> +}
> +
> +static void reset_adev_remove(void *data)
> +{
> +	struct auxiliary_device *adev = data;
> +
> +	auxiliary_device_delete(adev);
> +	auxiliary_device_uninit(adev);
> +	kfree(adev_to_reset_aux(adev));
> +}
> +
> +/* Create the TC9564 reset auxiliary device */
> +static int devm_reset_setup(struct device *dev)
> +{
> +	struct tc9564_clock *clock = dev_get_drvdata(dev);
> +	struct tc9564_aux_data *aux_data;
> +	struct auxiliary_device *adev;
> +	struct reset_aux *reset_aux;
> +	int ret;
> +
> +	reset_aux = kzalloc_obj(*reset_aux);
> +	if (!reset_aux)
> +		return -ENOMEM;
> +	adev = &reset_aux->adev;
> +
> +	aux_data = &reset_aux->aux_data;
> +	aux_data->reg = clock->ioaddr;
> +
> +	adev->id = 0;
> +	adev->name = TC9564_RESET_DEV_NAME;

[Severity: Low]
Will hardcoding adev->id = 0 fail when a system has more than one TC9564
instance?  A second instance registers the same
"clk_tc9564.tc9564-reset.0" name on the auxiliary bus and fails in
auxiliary_device_add() with -EEXIST.

> +	adev->dev.parent = dev;
> +	adev->dev.platform_data = aux_data;
> +	adev->dev.release = reset_dev_release;
> +	device_set_of_node_from_dev(&adev->dev, dev);
> +
> +	ret = auxiliary_device_init(adev);
> +	if (ret) {
> +		of_node_put(adev->dev.of_node);
> +		kfree(reset_aux);
> +		return ret;
> +	}
> +
> +	ret = auxiliary_device_add(adev);
> +	if (ret) {
> +		auxiliary_device_uninit(adev);
> +		kfree(reset_aux);
> +
> +		return ret;
> +	}

[Severity: Medium]
Can freeing reset_aux right after auxiliary_device_uninit(adev) in
devm_reset_setup() and reset_adev_remove() cause a use-after-free on
adev->dev?

Once auxiliary_device_init() succeeds, adev->dev is a reference-counted
device whose memory must be freed in its release callback.  If another
reference to adev->dev is still held when auxiliary_device_uninit() calls
put_device() (or when CONFIG_DEBUG_KOBJECT_RELEASE delays release),
kfree() frees reset_aux before reset_dev_release() runs.  Moving
kfree(adev_to_reset_aux(to_auxiliary_dev(dev))) into reset_dev_release()
and dropping the kfree() calls after auxiliary_device_uninit() avoids this.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201160810.2422466-1-elder@riscstar.com?part=2

  reply	other threads:[~2026-12-01 16:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 16:08 [PATCH v4 0/4] clk: tc9564: introduce clock and reset drivers Alex Elder
2026-12-01 16:08 ` [PATCH v4 1/4] dt-bindings: toshiba: introduce toshiba,tc9564-clock.yaml Alex Elder
2026-12-01 16:08 ` [PATCH v4 2/4] clk: toshiba: introduce a TC9564 clock driver Alex Elder
2026-12-01 16:21   ` sashiko-bot [this message]
2026-12-01 16:08 ` [PATCH v4 3/4] reset: toshiba: introduce a TC9564 reset driver Alex Elder
2026-12-01 16:16   ` sashiko-bot
2026-12-01 16:08 ` [PATCH v4 4/4] arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node Alex Elder

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-243673@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=elder@riscstar.com \
    --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