From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76FB7606A32D for ; Fri, 4 Dec 2026 07:51:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=LhKJ3WtV; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fi+vzZQM DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Message-ID:Date :Cc:To:From:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=G9z7vQdtiilFal7euhzbX6rf6GLtn2E7YfFH8h/rCEo=; b=LhKJ3WtV6yKoSof82J18bBmEgX gc1EOWk9yxiH28PEoEL9PlgurVFbauVsFZBqihpMyAA7ATLrf4QEopakzi0XgvNI6rk/VgwWGIh5n UiHir6tF2NeBuAESvuy+TWwQCh4zNwmn7nEVoQngG5Nb+utxo6PL+4v9d+iCyNGqYJivxatHO4wEp V08e60518Z4mzdOU8+BZF/fZ0O5UMBEH6QZgCimdeK+z7BWjVW9ZlSCxxAY0huqJDuM4K74wwXznz cp4tbRAfcQE0YEVKuKpSkqIKsIH9ZsTb6nGXg7N3yFlUGq1bJTveczQcP0q8UAW8mUPmlVjTL1nws ElBzA20w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZO4d-0000000H1Td-0jVO; Fri, 04 Dec 2026 07:51:19 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZO4O-0000000H1Op-3Eff; Fri, 04 Dec 2026 07:51:10 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 1B7D06262A; Fri, 4 Dec 2026 07:51:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03A831F000C2; Fri, 4 Dec 2026 07:51:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796370663; bh=G9z7vQdtiilFal7euhzbX6rf6GLtn2E7YfFH8h/rCEo=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=fi+vzZQMT9W8TdCaRNtJsWmLWDekrpJVmswkOxwqVXPXHSQ9Lp358OW4Q/YH7rYUA vF5iNxaTUlp2HMIvYS/tmCupGQJ0CwUM5hOAqULWOy5dK9aO8XOP42QzDssPzdgkh2 bQRO61YRZxjEI0zOuqDTGk+MIeoRsVGFV4+hpB9iSIDT/uEHev2mel5SQAblJfOT+L Lj6WyjPW57aLHxqymBkPmE/xL7xptKOgPVDz1a0w5AaivpQlIbT1X7y2vGu26LwTMv wuvpudcuWsOnbQ+EyL1G3m4njPrd69dKX7e2zmXpXbg6H3TKFxdQthd0DxQQ5x8naD G2RIkDuxy3cKg== Subject: Re: [PATCH net-next v2 3/5] net: dsa: mt7530: register the GPIO controller last in setup 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 Date: Fri, 04 Dec 2026 07:51:02 +0000 Message-ID: <179637066256.3146.15251240010012967643@kernel.org> In-Reply-To: <179628050300.1224.1177004205751897262@mail.zgclab.edu.cn> References: <179628050300.1224.1177004205751897262@mail.zgclab.edu.cn> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Archived-By: MIME-Version: 1.0 X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" X-Spam-Status: No, score=-11.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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