From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1DCF7E78A; Tue, 16 Jan 2024 19:47:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705434427; cv=none; b=QPt5vG99wz89zMT8X4bpNwlRcJ79vbpYXHj5cOL6DG41mKI5+sVrTQN+w1eXfoSt4lH348lxlxnyZaEaF1RL6ePz5xTVpxB1fSNVClB0xc/SvyNvjLK/KC1wD+qNkpHRZdsfYnqZpmT4rhwV+qcwC+dbBBCzhgbvfSDWhx+C4so= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705434427; c=relaxed/simple; bh=yg63Q6KN363mmGQBTPoS7pqAImXxdGR3CBoLen4GHOQ=; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version:Content-Type:X-stable: X-Patchwork-Hint:X-stable-base:Content-Transfer-Encoding; b=FJF33kBc52zLrgv1ykw8YQcpsBSHtUxK1TQDiF+FOiNA4iVDYbNJXPtrzkS/vEeI7azAXEdIPJ2wmZ45c6lKEeX9rbBpx1McwDodaizCkis51IACTVReSOnMcDiRuqCZy4AYAGoCzPcoRw8vhqHKWY7gD3R4jux86B8LIudTeuY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TCh4HanY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TCh4HanY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7626AC433F1; Tue, 16 Jan 2024 19:47:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705434427; bh=yg63Q6KN363mmGQBTPoS7pqAImXxdGR3CBoLen4GHOQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TCh4HanYOm4oXWaac5H06/bW5WrWu9LNmLtQTSVy99P7Sa7RHwdK830+yqZRfbDUn 8v+re6gGMOzsiS7ecdQBKzagSG+sDbsOTOcHOhi8s7YIfymdB9/BcJeLWt1hYZQETW 3XzExBKmDD76bov21B2h3nbed/hOyGSW90BtAnhfkRM/Sd/IjAKmrPE7vhAdDpSzCl gEB5LgPZ/9HJ3HB3gf3RZAbt2jOfxGSNbpyumF8gckqAAjTAZ16gNYkYbIH6hwcY7X 9DAt6zSkUl/QGATO37zlF4ld8tYO7YdCKHpiTxauL2MzrnSbDhV0X+fvOCbMWA7Ltc HY9pHwLH3hzXw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vladimir Oltean , =?UTF-8?q?Alvin=20=C5=A0ipraga?= , Florian Fainelli , "David S . Miller" , Sasha Levin , andrew@lunn.ch, f.fainelli@gmail.com, olteanv@gmail.com, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, ansuelsmth@gmail.com, rmk+kernel@armlinux.org.uk, kabel@kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 6.7 107/108] net: dsa: qca8k: put MDIO bus OF node on qca8k_mdio_register() failure Date: Tue, 16 Jan 2024 14:40:13 -0500 Message-ID: <20240116194225.250921-107-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240116194225.250921-1-sashal@kernel.org> References: <20240116194225.250921-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.7 Content-Transfer-Encoding: 8bit From: Vladimir Oltean [ Upstream commit 68e1010cda7967cfca9c8650ee1f4efcae54ab90 ] of_get_child_by_name() gives us an OF node with an elevated refcount, which should be dropped when we're done with it. This is so that, if (of_node_check_flag(node, OF_DYNAMIC)) is true, the node's memory can eventually be freed. There are 2 distinct paths to be considered in qca8k_mdio_register(): - devm_of_mdiobus_register() succeeds: since commit 3b73a7b8ec38 ("net: mdio_bus: add refcounting for fwnodes to mdiobus"), the MDIO core treats this well. - devm_of_mdiobus_register() or anything up to that point fails: it is the duty of the qca8k driver to release the OF node. This change addresses the second case by making sure that the OF node reference is not leaked. The "mdio" node may be NULL, but of_node_put(NULL) is safe. Signed-off-by: Vladimir Oltean Reviewed-by: Alvin Šipraga Reviewed-by: Florian Fainelli Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/dsa/qca/qca8k-8xxx.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c index ec57d9d52072..5f47a290bd6e 100644 --- a/drivers/net/dsa/qca/qca8k-8xxx.c +++ b/drivers/net/dsa/qca/qca8k-8xxx.c @@ -949,10 +949,15 @@ qca8k_mdio_register(struct qca8k_priv *priv) struct dsa_switch *ds = priv->ds; struct device_node *mdio; struct mii_bus *bus; + int err; + + mdio = of_get_child_by_name(priv->dev->of_node, "mdio"); bus = devm_mdiobus_alloc(ds->dev); - if (!bus) - return -ENOMEM; + if (!bus) { + err = -ENOMEM; + goto out_put_node; + } bus->priv = (void *)priv; snprintf(bus->id, MII_BUS_ID_SIZE, "qca8k-%d.%d", @@ -962,12 +967,12 @@ qca8k_mdio_register(struct qca8k_priv *priv) ds->user_mii_bus = bus; /* Check if the devicetree declare the port:phy mapping */ - mdio = of_get_child_by_name(priv->dev->of_node, "mdio"); if (of_device_is_available(mdio)) { bus->name = "qca8k user mii"; bus->read = qca8k_internal_mdio_read; bus->write = qca8k_internal_mdio_write; - return devm_of_mdiobus_register(priv->dev, bus, mdio); + err = devm_of_mdiobus_register(priv->dev, bus, mdio); + goto out_put_node; } /* If a mapping can't be found the legacy mapping is used, @@ -976,7 +981,13 @@ qca8k_mdio_register(struct qca8k_priv *priv) bus->name = "qca8k-legacy user mii"; bus->read = qca8k_legacy_mdio_read; bus->write = qca8k_legacy_mdio_write; - return devm_mdiobus_register(priv->dev, bus); + + err = devm_mdiobus_register(priv->dev, bus); + +out_put_node: + of_node_put(mdio); + + return err; } static int -- 2.43.0