Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: wanghr2026@mail.zgclab.edu.cn
Cc: chester.a.unal@arinc9.com, daniel@makrotopia.org, andrew@lunn.ch,
	olteanv@gmail.com, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, matthias.bgg@gmail.com,
	angelogioacchino.delregno@collabora.com, netdev@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v2 3/5] net: dsa: mt7530: register the GPIO controller last in setup
Date: Fri, 04 Dec 2026 07:51:02 +0000	[thread overview]
Message-ID: <179637066256.3146.15251240010012967643@kernel.org> (raw)
In-Reply-To: <179628050300.1224.1177004205751897262@mail.zgclab.edu.cn>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] mt7530_setup_gpio() allocates the gpio_chip with
  devm_kzalloc_obj(priv->dev) and registers it with…
- [Medium] net: dsa: mt7530: GPIO controller registered before
  mt753x_setup() finishes

--

net: dsa: mt7530: register the GPIO controller last in setup

This patch moves the GPIO controller registration in mt7530_setup() after
the FDB flush. With that order the controller is not published when
mt7530_setup() itself fails. The commit message says this is needed for
the next patch, where a failed setup disables the regulators.

> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index 17c62b53ca062..e784123fb79ce 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
> @@ -2594,6 +2594,11 @@ mt7530_setup(struct dsa_switch *ds)
>  		}
>  	}
>  
> +	/* Flush the FDB table */
> +	ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
> +	if (ret < 0)
> +		return ret;
> +
>  #ifdef CONFIG_GPIOLIB
>  	if (of_property_read_bool(priv->dev->of_node, "gpio-controller")) {
>  		ret = mt7530_setup_gpio(priv);

[Severity: Medium]
mt7530_setup() is only the priv->info->sw_setup() step of
mt753x_setup(). After sw_setup() returns 0, mt753x_setup() still runs
two fallible steps, mt7530_setup_irq() and mt7530_setup_mdio(), so the
GPIO controller is not actually registered last in setup.

If either of those fails, mt753x_setup() returns an error and
dsa_switch_setup() jumps to unregister_notifier without calling
ds->ops->teardown(). Nothing unregisters the gpiochip that
mt7530_setup_gpio() added with devm_gpiochip_add_data(), so
mt7530_gpio_get(), mt7530_gpio_set() and the direction callbacks stay
reachable from /dev/gpiochipN and from in-kernel consumers.

Once the later patch in this series sends the mt7530_setup_irq() and
mt7530_setup_mdio() failures to mt7530_disable_pwrs(), the core_pwr and
io_pwr regulators are switched off while that controller is still
published. mt7530_setup_irq() getting -EPROBE_DEFER from of_irq_get()
is a realistic way to get there.

With a single switch the probe failure eventually releases devres. In a
multi-switch tree, where mt7530_probe() has already returned 0, the
chip stays registered until unbind, and a retried dsa_tree_setup()
would call devm_gpiochip_add_data() a second time on the same device.

Doesn't this leave the guarantee described in the commit message only
half met? Would it make sense to register the GPIO controller from
mt753x_setup() after mt7530_setup_mdio() succeeds, or to remove it
explicitly on those error paths before the regulators are disabled?

[Severity: Medium]
Does this reordering fully meet the goal in the commit message, that "the
controller must not be registered across a failed setup"?

mt7530_setup_gpio() registers the chip through devres on priv->dev:

drivers/net/dsa/mt7530.c:mt7530_setup_gpio() {
    ...
	return devm_gpiochip_add_data(dev, gc, priv);
}

So the gpiochip lives until driver unbind, not until DSA teardown.
mt753x_teardown() powers the switch down but does not unregister the
gpiochip:

	mt7530_disable_pwrs(priv);

DSA can call ->teardown while the driver stays bound. One case is when a
step after ops->setup fails in dsa_switch_setup(), for example
dsa_switch_setup_tag_protocol() or the user_mii_bus allocation or
mdiobus_register():

net/dsa/dsa.c:dsa_switch_setup() {
    ...
teardown:
	if (ds->ops->teardown)
		ds->ops->teardown(ds);
    ...
}

Another case is when a sibling switch fails in dsa_tree_setup_switches().
Switches that already set up successfully are then unwound:

	err = dsa_switch_setup(dp->ds);
	if (err) {
		dsa_tree_teardown_switches(dst);

In both cases mt7530_setup() has returned 0 and the gpiochip is
registered. The switch is then powered off while the GPIO controller is
still published.

If the tree is set up again, would mt7530_setup() call
devm_gpiochip_add_data() a second time on the same device? That would
leave two "mt7530" gpiochips for the same fwnode, with the stale one held
until unbind.

Since the devm registration is tied to the device rather than to
setup/teardown, can reordering calls inside mt7530_setup() alone keep the
controller from staying registered across these failed DSA-level setups?

>  		if (ret)
> @@ -2602,11 +2607,6 @@ mt7530_setup(struct dsa_switch *ds)
>  	}
>  #endif /* CONFIG_GPIOLIB */
>  
> -	/* Flush the FDB table */
> -	ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
> -	if (ret < 0)
> -		return ret;
> -
>  	return 0;
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179628050300.1224.11499384961750115678%40mail.zgclab.edu.cn


  reply	other threads:[~2026-12-04  7:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  6:48 [PATCH net-next v2 0/5] net: dsa: mt7530: disable regulators on teardown and setup failure Haoran Wang
2026-12-03  6:48 ` [PATCH net-next v2 1/5] net: dsa: mt7530: disable regulators on switch teardown Haoran Wang
2026-12-04  7:51   ` netdev-bot+sashiko
2026-12-03  6:48 ` [PATCH net-next v2 3/5] net: dsa: mt7530: register the GPIO controller last in setup Haoran Wang
2026-12-04  7:51   ` netdev-bot+sashiko [this message]
2026-12-03  6:48 ` [PATCH net-next v2 4/5] net: dsa: mt7530: disable regulators on setup failure Haoran Wang
2026-12-03  6:48 ` [PATCH net-next v2 5/5] net: dsa: mt7530: disable regulators on mt753x_setup() failure Haoran Wang
2026-12-04  7:51   ` netdev-bot+sashiko
2026-12-03  6:48 ` [PATCH net-next v2 2/5] net: dsa: mt7530: factor out mt7530_disable_pwrs() Haoran Wang
2026-12-03  6:53 ` [PATCH net-next v2 0/5] net: dsa: mt7530: disable regulators on teardown and setup failure netdev-bot+sinfo

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=179637066256.3146.15251240010012967643@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=chester.a.unal@arinc9.com \
    --cc=daniel@makrotopia.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=wanghr2026@mail.zgclab.edu.cn \
    /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