Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6457959pxb; Tue, 15 Feb 2022 02:55:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJWEP7jv7B9EiiZnZ3cLvF+phk9wEJZk9npcY/7qccibuA+oVttknikIinUt1ciMrh+CUu X-Received: by 2002:a17:906:19c2:: with SMTP id h2mr2439446ejd.394.1644922532364; Tue, 15 Feb 2022 02:55:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644922532; cv=none; d=google.com; s=arc-20160816; b=vyB8ot3yIaTHEXkAIosRYagQQN5NPiPdoXOd5sebTS368UcZ2Ll8cMNc0T7khnrdVB oXDV6qY/sJrRlicm4rt1pzaWdZpk7XyFBsnWeF91rKZ7TGNhXuLOO7JPgaFHrbIIy0bw Oz05u312IPXt/el9eCMhd45psDfHvIcGOIc+YkaCWqhONeQSM2G/VlkD4gEhgOUTcEP0 mavbjoketNvT6KoaWvlLjrpqR7Dq1QB7zN4lcvlZ45uqLRn7KQCKz1x2OjgL/Q4pS/Mr aPeVe6utHUYaaxSMWw7Ro7YGNUN81c2lMyhwjVni1Gxwfn4t0OHhepRSqaawbYBbIshp l4DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:autocrypt:from :references:cc:to:subject; bh=+yoFJxTSdX1vi7rOVVQf/gmym++0K2y5uLSH8gqqb04=; b=jSz7U3THrnsVuNNg1lTcbly4ExTTuAZCGOzbQEDkvJotXfNhgxfNBa49s09xbZgeT6 6I45qQbTZi/6KyQXmLl+fpCcToCA7bVB/asfFNoiYoXFQ2DDvSgXwqjn6UuGbz2f4wMs R4fvY2P35OR0J3TV3L6oAcVJuYPCqzibOtdCc1CE8fmF9AXgnJ/LiBjVB7kHnd6ASsAR TIvGj7tF5Y4gQ/lv9o15pTLEwoc8XTMC/NjiCJjk7bW6vAWDhA3X/5zB1Iw5z3C2Jtr5 lPwqozlcSe0pIvPIfBasAY7g1r2zm9TYzJu1T6EzJTYhh1fbC+tNLuVO0ZuMMk9fuct4 Gy2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g2si24093419ejt.974.2022.02.15.02.54.37; Tue, 15 Feb 2022 02:55:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236047AbiBOJpW (ORCPT + 99 others); Tue, 15 Feb 2022 04:45:22 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232267AbiBOJpQ (ORCPT ); Tue, 15 Feb 2022 04:45:16 -0500 X-Greylist: delayed 550 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 15 Feb 2022 01:45:06 PST Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25863E61D6; Tue, 15 Feb 2022 01:45:05 -0800 (PST) Received: from [10.10.2.52] (unknown [10.10.2.52]) by mail.ispras.ru (Postfix) with ESMTPSA id 2BA404076B21; Tue, 15 Feb 2022 09:35:44 +0000 (UTC) Subject: Re: [PATCH 5.10 073/116] net: dsa: lantiq_gswip: dont use devres for mdiobus To: Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org, Vladimir Oltean , Florian Fainelli , Jakub Kicinski , Sasha Levin References: <20220214092458.668376521@linuxfoundation.org> <20220214092501.284425363@linuxfoundation.org> From: Alexey Khoroshilov Autocrypt: addr=khoroshilov@ispras.ru; prefer-encrypt=mutual; keydata= xsFNBFtq9eIBEACxmOIPDht+aZvO9DGi4TwnZ1WTDnyDVz3Nnh0rlQCK8IssaT6wE5a95VWo iwOWalcL9bJMHQvw60JwZKFjt9oH2bov3xzx/JRCISQB4a4U1J/scWvPtabbB3t+VAodF5KZ vZ2gu/Q/Wa5JZ9aBH0IvNpBAAThFg1rBXKh7wNqrhsQlMLg+zTSK6ZctddNl6RyaJvAmbaTS sSeyUKXiabxHn3BR9jclXfmPLfWuayinBvW4J3vS+bOhbLxeu3MO0dUqeX/Nl8EAhvzo0I2d A0vRu/Ze1wU3EQYT6M8z3i1b3pdLjr/i+MI8Rgijs+TFRAhxRw/+0vHGTg6Pn02t0XkycxQR mhH3v0kVTvMyM7YSI7yXvd0QPxb1RX9AGmvbJu7eylzcq9Jla+/T3pOuWsJkbvbvuFKKmmYY WnAOR7vu/VNVfiy4rM0bfO14cIuEG+yvogcPuMmQGYu6ZwS9IdgZIOAkO57M/6wR0jIyfxrG FV3ietPtVcqeDVrcShKyziRLJ+Xcsg9BLdnImAqVQomYr27pyNMRL5ILuT7uOuAQPDKBksK+ l2Fws0d5iUifqnXSPuYxqgS4f8SQLS7ECxvCGVVbkEEng9vkkmyrF6wM86BZ9apPGDFbopiK 7GRxQtSGszVv83abaVb8aDsAudJIp7lLaIuXLZAe1r+ycYpEtQARAQABzSpBbGV4ZXkgS2hv cm9zaGlsb3YgPGtob3Jvc2hpbG92QGlzcHJhcy5ydT7CwX0EEwEIACcFAltq9eICGwMFCRLM AwAFCwkIBwIGFQgJCgsCBBYCAwECHgECF4AACgkQ2B/JSz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ID: <1e75b66a-295b-02bc-b4c5-421aec2cae96@ispras.ru> Date: Tue, 15 Feb 2022 12:35:44 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20220214092501.284425363@linuxfoundation.org> Content-Type: text/plain; charset=utf-8 Content-Language: ru-RU Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14.02.2022 12:26, Greg Kroah-Hartman wrote: > From: Vladimir Oltean > > [ Upstream commit 0d120dfb5d67edc5bcd1804e167dba2b30809afd ] > > As explained in commits: > 74b6d7d13307 ("net: dsa: realtek: register the MDIO bus under devres") > 5135e96a3dd2 ("net: dsa: don't allocate the slave_mii_bus using devres") > > mdiobus_free() will panic when called from devm_mdiobus_free() <- > devres_release_all() <- __device_release_driver(), and that mdiobus was > not previously unregistered. > > The GSWIP switch is a platform device, so the initial set of constraints > that I thought would cause this (I2C or SPI buses which call ->remove on > ->shutdown) do not apply. But there is one more which applies here. > > If the DSA master itself is on a bus that calls ->remove from ->shutdown > (like dpaa2-eth, which is on the fsl-mc bus), there is a device link > between the switch and the DSA master, and device_links_unbind_consumers() > will unbind the GSWIP switch driver on shutdown. > > So the same treatment must be applied to all DSA switch drivers, which > is: either use devres for both the mdiobus allocation and registration, > or don't use devres at all. > > The gswip driver has the code structure in place for orderly mdiobus > removal, so just replace devm_mdiobus_alloc() with the non-devres > variant, and add manual free where necessary, to ensure that we don't > let devres free a still-registered bus. > > Fixes: ac3a68d56651 ("net: phy: don't abuse devres in devm_mdiobus_register()") > Signed-off-by: Vladimir Oltean > Reviewed-by: Florian Fainelli > Signed-off-by: Jakub Kicinski > Signed-off-by: Sasha Levin > --- > drivers/net/dsa/lantiq_gswip.c | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c > index 4d23a7aba7961..ed517985ca88e 100644 > --- a/drivers/net/dsa/lantiq_gswip.c > +++ b/drivers/net/dsa/lantiq_gswip.c > @@ -495,8 +495,9 @@ static int gswip_mdio_rd(struct mii_bus *bus, int addr, int reg) > static int gswip_mdio(struct gswip_priv *priv, struct device_node *mdio_np) > { > struct dsa_switch *ds = priv->ds; > + int err; > > - ds->slave_mii_bus = devm_mdiobus_alloc(priv->dev); > + ds->slave_mii_bus = mdiobus_alloc(); > if (!ds->slave_mii_bus) > return -ENOMEM; > > @@ -509,7 +510,11 @@ static int gswip_mdio(struct gswip_priv *priv, struct device_node *mdio_np) > ds->slave_mii_bus->parent = priv->dev; > ds->slave_mii_bus->phy_mask = ~ds->phys_mii_mask; > > - return of_mdiobus_register(ds->slave_mii_bus, mdio_np); > + err = of_mdiobus_register(ds->slave_mii_bus, mdio_np); > + if (err) > + mdiobus_free(ds->slave_mii_bus); > + > + return err; > } > > static int gswip_pce_table_entry_read(struct gswip_priv *priv, > @@ -2086,8 +2091,10 @@ static int gswip_probe(struct platform_device *pdev) > gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB); > dsa_unregister_switch(priv->ds); > mdio_bus: > - if (mdio_np) > + if (mdio_np) { > mdiobus_unregister(priv->ds->slave_mii_bus); > + mdiobus_free(priv->ds->slave_mii_bus); > + } > put_mdio_node: > of_node_put(mdio_np); > for (i = 0; i < priv->num_gphy_fw; i++) > @@ -2107,6 +2114,7 @@ static int gswip_remove(struct platform_device *pdev) > > if (priv->ds->slave_mii_bus) { > mdiobus_unregister(priv->ds->slave_mii_bus); > + mdiobus_free(priv->ds->slave_mii_bus); > of_node_put(priv->ds->slave_mii_bus->dev.of_node); > } Should of_node_put(priv->ds->slave_mii_bus->dev.of_node); be here before mdiobus_free(priv->ds->slave_mii_bus); ? -- Best regards, Alexey Khoroshilov Linux Verification Center, ISPRAS