Linux clock framework development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kyle Hendry" <khendry@reliablecontrols.com>
Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org,
	wsa+renesas@sang-engineering.com
Subject: Re: [PATCH 2/6] clk: renesas: r9a06g032: Add reset controller
Date: Fri, 20 Nov 2026 17:58:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-225759@kernel.org> (raw)
In-Reply-To: <20261119-rzn1-miic-resets-v1-2-feee2bb28bb4@reliablecontrols.com>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] clk: renesas: r9a06g032: missing rcdev member in struct
  r9a06g032_priv
- [High] clk: renesas: r9a06g032: 0-based r9a06g032_resets[] mismatches
  1-based DT IDs
- [High] clk: renesas: r9a06g032: inverted reset polarity in
  r9a06g032_reset()
- [Medium] clk: renesas: r9a06g032: inverted return value in
  r9a06g032_reset_status()
- [Medium] clk: renesas: r9a06g032: dangling sysctrl_priv on reset
  registration error
- [Low] clk: renesas: r9a06g032: unused func parameter in
  r9a06g032_reset_set()
--

commit c1ea072ef200e955b9711c8cf6fa8c5c06a195de
Author: Kyle Hendry <khendry@reliablecontrols.com>

clk: renesas: r9a06g032: Add reset controller

This commit registers a reset controller in the r9a06g032 clock driver to
control the RSTN_CLK25 and RSTN_ETH active-low reset bits in the
PWRCTRL_SWITCHCTRL register.

> diff --git a/drivers/clk/renesas/r9a06g032-clocks.c b/drivers/clk/renesas/r9a06g032-clocks.c
> index 3df3f2b2c6de7..547e8d82f1cf1 100644
> --- a/drivers/clk/renesas/r9a06g032-clocks.c
> +++ b/drivers/clk/renesas/r9a06g032-clocks.c
[ ... ]
> @@ -675,6 +676,11 @@ static const struct r9a06g032_clkdesc r9a06g032_clocks[] = {
>  		RB(0xec, 16), RB(0xec, 17), RB(0xec, 18), RB(0xec, 19)),
>  };
>  
> +static const struct regbit r9a06g032_resets[] = {
> +	RB(0x188, 3),
> +	RB(0x188, 4),
> +};

[Severity: High]
Does the 0-based indexing of r9a06g032_resets[] mismatch the 1-based DT
binding definitions?

include/dt-bindings/clock/r9a06g032-sysctrl.h defines R9A06G032_RST_TS as
1 and R9A06G032_RST_MIIC as 2.  With clocks->rcdev.nr_resets set to
ARRAY_SIZE(r9a06g032_resets) (2) and the default
fwnode_reset_simple_xlate(), requesting R9A06G032_RST_MIIC (2) fails with
-EINVAL, and requesting R9A06G032_RST_TS (1) indexes r9a06g032_resets[1]
(bit 4, RSTN_ETH) instead of bit 3 (RSTN_CLK25).

> +
>  struct r9a06g032_priv {
>  	struct clk_onecell_data data;
>  	spinlock_t lock; /* protects concurrent access to gates */
> @@ -1307,6 +1313,56 @@ static void __init r9a06g032_init_h2mode(struct r9a06g032_priv *clocks)
>  	writel(usb, clocks->reg + R9A06G032_SYSCTRL_USB);
>  }
>  
> +
> +#define rcdev_to_priv(x)	container_of(x, struct r9a06g032_priv, rcdev)

[Severity: High]
Is struct r9a06g032_priv missing the struct reset_controller_dev rcdev
member?  Without it, rcdev_to_priv() and clocks->rcdev in
r9a06g032_clocks_probe() fail to compile when CONFIG_CLK_R9A06G032 is
enabled.

> +
> +static int r9a06g032_reset_set(struct reset_controller_dev *rcdev,
> +				  const char *func, bool set, unsigned long id)
> +{
> +	struct r9a06g032_priv *priv = rcdev_to_priv(rcdev);
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&priv->lock, flags);
> +	clk_rdesc_set(priv, r9a06g032_resets[id], set);
> +	spin_unlock_irqrestore(&priv->lock, flags);
> +
> +	return 0;
> +}

[Severity: Low]
The func parameter in r9a06g032_reset_set() is unused and triggers a
-Wunused-parameter warning under W=1 builds.

> +
> +static int r9a06g032_reset(struct reset_controller_dev *rcdev,
> +			  unsigned long id)
> +{
> +	r9a06g032_reset_set(rcdev, "reset", true, id);
> +	udelay(5);
> +	return r9a06g032_reset_set(rcdev, NULL, false, id);
> +}
> +
> +static int r9a06g032_reset_assert(struct reset_controller_dev *rcdev, unsigned long id)
> +{
> +	return r9a06g032_reset_set(rcdev, "assert", false, id);
> +}
> +
> +static int r9a06g032_reset_deassert(struct reset_controller_dev *rcdev,
> +			     unsigned long id)
> +{
> +	return r9a06g032_reset_set(rcdev, "deassert", true, id);
> +}

[Severity: High]
Is the reset polarity in r9a06g032_reset() inverted?

Because these resets are active-low (false asserts and true deasserts, as
in r9a06g032_reset_assert() and r9a06g032_reset_deassert()), passing true
before udelay(5) and false afterward deasserts the line and then leaves
the hardware held in reset.

> +
> +static int r9a06g032_reset_status(struct reset_controller_dev *rcdev,
> +			   unsigned long id)
> +{
> +	struct r9a06g032_priv *priv = rcdev_to_priv(rcdev);
> +
> +	return clk_rdesc_get(priv, r9a06g032_resets[id]);
> +}

[Severity: Medium]
Should r9a06g032_reset_status() invert the return value of
clk_rdesc_get()?

reset_control_ops.status must return a positive value when the reset is
asserted and 0 when deasserted, whereas clk_rdesc_get() on these
active-low bits returns 0 when asserted and 1 when deasserted.

[ ... ]

> @@ -1404,6 +1460,14 @@ static int __init r9a06g032_clocks_probe(struct platform_device *pdev)
>  	if (error)
>  		dev_err(dev, "Failed to populate children (%d)\n", error);
>  
> +	clocks->rcdev.ops = &r9a06g032_reset_ops;
> +	clocks->rcdev.of_node = np;
> +	clocks->rcdev.of_reset_n_cells = 1;
> +	clocks->rcdev.nr_resets = ARRAY_SIZE(r9a06g032_resets);
> +	error =  devm_reset_controller_register(dev, &clocks->rcdev);
> +	if (error)
> +		return error;

[Severity: Medium]
If devm_reset_controller_register() fails here, does returning an error
leave sysctrl_priv dangling after devres frees clocks?

Earlier in r9a06g032_clocks_probe(), r9a06g032_add_clk_domain(dev)
registers an unmanaged genpd provider, sysctrl_priv is set to clocks, and
of_platform_populate() creates child devices.  If
devm_reset_controller_register() fails afterward, devres frees clocks and
unmaps clocks->reg while sysctrl_priv remains non-NULL, causing a
use-after-free in r9a06g032_sysctrl_set_dmamux(), and child devices
probed during of_platform_populate() cannot look up the reset controller
yet.  Registering the reset controller before r9a06g032_add_clk_domain(),
sysctrl_priv = clocks, and of_platform_populate() avoids both problems.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-rzn1-miic-resets-v1-0-feee2bb28bb4@reliablecontrols.com?part=2

  parent reply	other threads:[~2026-11-20 17:58 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 17:57 [PATCH 0/6] clk: renesas: r9a06g032: Add reset controller to clear resets for mii converter Kyle Hendry via B4 Relay
2026-11-19 17:57 ` [PATCH 1/6] dt-bindings: clock: r9a06g032-sysctrl: Document reset cells Kyle Hendry via B4 Relay
2026-11-20  9:23   ` Wolfram Sang
2026-11-20  9:51     ` Philipp Zabel
2026-11-20 11:11       ` Wolfram Sang
2026-11-19 17:57 ` [PATCH 2/6] clk: renesas: r9a06g032: Add reset controller Kyle Hendry via B4 Relay
2026-11-20  9:30   ` Wolfram Sang
2026-11-20 10:00   ` Philipp Zabel
2026-11-20 11:47   ` Wolfram Sang
2026-11-20 17:58   ` sashiko-bot [this message]
2026-11-19 17:57 ` [PATCH 3/6] ARM: dts: renesas: r9a06g032: Add #reset-cells to system controller node Kyle Hendry via B4 Relay
2026-11-20  9:32   ` Wolfram Sang
2026-11-19 17:57 ` [PATCH 4/6] dt-bindings: net: pcs: renesas,rzn1-miic: Document rzn1 resets Kyle Hendry via B4 Relay
2026-11-20 11:49   ` Wolfram Sang
2026-11-19 17:57 ` [PATCH 5/6] net: pcs: rzn1-miic: Add resets to rzn1 info structure Kyle Hendry via B4 Relay
2026-11-20 17:58   ` sashiko-bot
2026-11-19 17:57 ` [PATCH 6/6] ARM: dts: renesas: r9a06g032: Add resets to mii converter Kyle Hendry via B4 Relay
2026-11-20  9:34   ` Wolfram Sang
2026-11-20 17:58   ` sashiko-bot
2026-11-19 22:02 ` [PATCH 0/6] clk: renesas: r9a06g032: Add reset controller to clear resets for " Jakub Kicinski

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-225759@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=khendry@reliablecontrols.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wsa+renesas@sang-engineering.com \
    /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