Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5950656pxb; Mon, 14 Feb 2022 11:29:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJw02Lm/H+MiWaBuHo7UxBnwNvVJrmcn91T7vEsXxh9SceTfhL/NoAODKw38mF8Xj+RmsU6r X-Received: by 2002:a17:90b:4a02:b0:1b8:d3c7:7a2b with SMTP id kk2-20020a17090b4a0200b001b8d3c77a2bmr198421pjb.194.1644866986869; Mon, 14 Feb 2022 11:29:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644866986; cv=none; d=google.com; s=arc-20160816; b=wlCUghut9n020YiXWnYNnNUw6zzx0qAL4NF29hNlonvbULf1xhuFpj6Rbk4l+uGRok G8gWImy1BF2RJZgSuTA305XqtPEgozwj/agQTRnPP5SnEITefMQ7UrwShtGvEBlcQGPw mkaFnlyeoe6+1rhQbRwxENHQwNbY5XOoVYOSotg+anpPjcYKqpc0PtLadq0U/ZANZ6VQ kFzP6UcLZaVjSrxMCE1T7fdTDnNvYiRPy/UJvW+FsyFaNVrUwUInB5souT/4ullGc0aK 2hWoLVZLhaaQizLacOFfiFU4EKYxwoVxviHwDE+oYRWN2dT7AC5vIY+SZdVdvYOeq5Hp Ud3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mP8aJjc+8ZqoNa+RpFweWcKM7RGv0w4g7N5yKaJ28Uk=; b=z+t9Ogo/AFLKpNvV0rSJJQ+wZdKYrruUTP/KyZkLGmv/kLIZUe12eAs++3Dp9ThyFO 9IxsvTS83cpZCc/tKP42Iw0JjWDfBpmV9XKAhcCM+ddCFZVWKRs1OCyjPXSmx7qqPKR5 hKmt8Fw/qPjQ2RGbojyUBKwCwu1tYDCEj9ZhDMFt4PcoEqjMZw4EuA5w729UzDSEEr2c xEDte2Yy317aWxxUvsr/sMQ3Jn7vxLNtlsfIcuU3Ba4FMLTQ7oSmcITBd3Mle9OncrZU cDzB1yZSqXt/TEy0foCCWpFiuKdOOL2X87aLpGf/gcUvw6RGdOD/n9fso1CqSJf1CeP0 TaDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=k1bGiqPh; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d10si12655497pjx.28.2022.02.14.11.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 11:29:46 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=k1bGiqPh; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 08B108E; Mon, 14 Feb 2022 11:18:26 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232902AbiBNJ5b (ORCPT + 99 others); Mon, 14 Feb 2022 04:57:31 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:33416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344945AbiBNJwI (ORCPT ); Mon, 14 Feb 2022 04:52:08 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8CD77B574; Mon, 14 Feb 2022 01:43:31 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5CFAEB80DC7; Mon, 14 Feb 2022 09:43:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75AE9C340E9; Mon, 14 Feb 2022 09:43:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644831809; bh=QL7IgnnS5NEn5+xPkax9kNlJwf421H3w804yKiFyQHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k1bGiqPhNKPZCUaA0VnO1mydzaBhRhBipvOR3LfkPIqNu+g8qGev+3BXWk0hT8nD0 T/1vZdxIezA9k7UvWNU3mF8OFi4dihjHZ98Z4F8pj+Tyn5CtTVG7+VgYrh3kuqCST6 Qy8tseE40duGDzgHVvzXZf5rQsw4bzB9cSdgK81Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Oltean , Florian Fainelli , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10 072/116] net: dsa: felix: dont use devres for mdiobus Date: Mon, 14 Feb 2022 10:26:11 +0100 Message-Id: <20220214092501.249190045@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092458.668376521@linuxfoundation.org> References: <20220214092458.668376521@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Vladimir Oltean [ Upstream commit 209bdb7ec6a28c7cdf580a0a98afbc9fc3b98932 ] 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 Felix VSC9959 switch is a PCI 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 felix 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 felix driver has the code structure in place for orderly mdiobus removal, so just replace devm_mdiobus_alloc_size() 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/ocelot/felix_vsc9959.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c index 2e5bbdca5ea47..cd8d9b0e0edb3 100644 --- a/drivers/net/dsa/ocelot/felix_vsc9959.c +++ b/drivers/net/dsa/ocelot/felix_vsc9959.c @@ -1050,7 +1050,7 @@ static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot) return PTR_ERR(hw); } - bus = devm_mdiobus_alloc_size(dev, sizeof(*mdio_priv)); + bus = mdiobus_alloc_size(sizeof(*mdio_priv)); if (!bus) return -ENOMEM; @@ -1070,6 +1070,7 @@ static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot) rc = mdiobus_register(bus); if (rc < 0) { dev_err(dev, "failed to register MDIO bus\n"); + mdiobus_free(bus); return rc; } @@ -1119,6 +1120,7 @@ static void vsc9959_mdio_bus_free(struct ocelot *ocelot) lynx_pcs_destroy(pcs); } mdiobus_unregister(felix->imdio); + mdiobus_free(felix->imdio); } static void vsc9959_sched_speed_set(struct ocelot *ocelot, int port, -- 2.34.1