From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Vladimir Oltean" <vladimir.oltean@nxp.com>,
"Alvin Šipraga" <alsi@bang-olufsen.dk>,
"Florian Fainelli" <florian.fainelli@broadcom.com>,
"David S . Miller" <davem@davemloft.net>,
"Sasha Levin" <sashal@kernel.org>,
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.1 68/68] net: dsa: qca8k: put MDIO bus OF node on qca8k_mdio_register() failure
Date: Tue, 16 Jan 2024 14:54:07 -0500 [thread overview]
Message-ID: <20240116195511.255854-68-sashal@kernel.org> (raw)
In-Reply-To: <20240116195511.255854-1-sashal@kernel.org>
From: Vladimir Oltean <vladimir.oltean@nxp.com>
[ 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 <vladimir.oltean@nxp.com>
Reviewed-by: Alvin Šipraga <alsi@bang-olufsen.dk>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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 1e94ba1031ec..7c3c90c9edbe 100644
--- a/drivers/net/dsa/qca/qca8k-8xxx.c
+++ b/drivers/net/dsa/qca/qca8k-8xxx.c
@@ -842,10 +842,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",
@@ -855,12 +860,12 @@ qca8k_mdio_register(struct qca8k_priv *priv)
ds->slave_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 slave 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,
@@ -869,7 +874,13 @@ qca8k_mdio_register(struct qca8k_priv *priv)
bus->name = "qca8k-legacy slave 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
prev parent reply other threads:[~2024-01-16 19:57 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-16 19:53 [PATCH AUTOSEL 6.1 01/68] wifi: rt2x00: restart beacon queue when hardware reset Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 02/68] selftests/bpf: satisfy compiler by having explicit return in btf test Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 03/68] selftests/bpf: Fix pyperf180 compilation failure with clang18 Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 04/68] wifi: rt2x00: correct wrong BBP register in RxDCOC calibration Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 05/68] selftests/bpf: Fix issues in setup_classid_environment() Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 06/68] soc: xilinx: Fix for call trace due to the usage of smp_processor_id() Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 07/68] soc: xilinx: fix unhandled SGI warning message Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 08/68] scsi: lpfc: Fix possible file string name overflow when updating firmware Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 09/68] PCI: Add no PM reset quirk for NVIDIA Spectrum devices Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 10/68] bonding: return -ENOMEM instead of BUG in alb_upper_dev_walk Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 11/68] net: usb: ax88179_178a: avoid two consecutive device resets Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 12/68] wifi: ieee80211: fix PV1 frame control field name Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 13/68] scsi: mpi3mr: Add PCI checks where SAS5116 diverges from SAS4116 Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 14/68] scsi: arcmsr: Support new PCI device IDs 1883 and 1886 Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 15/68] ARM: dts: imx7d: Fix coresight funnel ports Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 16/68] ARM: dts: imx7s: Fix lcdif compatible Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 17/68] ARM: dts: imx7s: Fix nand-controller #size-cells Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 18/68] wifi: ath9k: Fix potential array-index-out-of-bounds read in ath9k_htc_txstatus() Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 19/68] wifi: ath11k: fix race due to setting ATH11K_FLAG_EXT_IRQ_ENABLED too early Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 20/68] bnxt_en: Add 5760X (P7) PCI IDs Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 21/68] bpf: Check rcu_read_lock_trace_held() before calling bpf map helpers Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 22/68] bpf: Add map and need_defer parameters to .map_fd_put_ptr() Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 23/68] bpf: Set need_defer as false when clearing fd array during map free Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 24/68] scsi: libfc: Don't schedule abort twice Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 25/68] scsi: libfc: Fix up timeout error in fc_fcp_rec_error() Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 26/68] net: mvmdio: Avoid excessive sleeps in polled mode Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 27/68] net: wangxun: fix changing mac failed when running Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 28/68] bpf: Guard stack limits against 32bit overflow Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 29/68] bpf: Set uattr->batch.count as zero before batched update or deletion Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 30/68] wifi: wfx: fix possible NULL pointer dereference in wfx_set_mfp_ap() Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 31/68] ARM: dts: rockchip: fix rk3036 hdmi ports node Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 32/68] ARM: dts: imx25/27-eukrea: Fix RTC node name Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 33/68] ARM: dts: imx: Use flash@0,0 pattern Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 34/68] ARM: dts: imx27: Fix sram node Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 35/68] ARM: dts: imx1: " Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 36/68] net: phy: at803x: fix passing the wrong reference for config_intr Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 37/68] ionic: pass opcode to devcmd_wait Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 38/68] ionic: bypass firmware cmds when stuck in reset Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 39/68] block/rnbd-srv: Check for unlikely string overflow Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 40/68] ARM: dts: imx25: Fix the iim compatible string Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 41/68] ARM: dts: imx25/27: Pass timing0 Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 42/68] ARM: dts: imx27-apf27dev: Fix LED name Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 43/68] ARM: dts: imx23-sansa: Use preferred i2c-gpios properties Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 44/68] ARM: dts: imx23/28: Fix the DMA controller node name Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 45/68] scsi: hisi_sas: Set .phy_attached before notifing phyup event HISI_PHYE_PHY_UP_PM Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 46/68] ice: fix ICE_AQ_VSI_Q_OPT_RSS_* register values Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 47/68] net: atlantic: eliminate double free in error handling logic Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 48/68] net: dsa: mv88e6xxx: Fix mv88e6352_serdes_get_stats error path Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 49/68] block: prevent an integer overflow in bvec_try_merge_hw_page Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 50/68] md: Whenassemble the array, consult the superblock of the freshest device Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 51/68] cfi: Add CFI_NOSEAL() Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 52/68] arm64: dts: qcom: msm8996: Fix 'in-ports' is a required property Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 53/68] arm64: dts: qcom: msm8998: Fix 'out-ports' " Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 54/68] ice: fix pre-shifted bit usage Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 55/68] arm64: dts: amlogic: fix format for s4 uart node Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 56/68] wifi: rtl8xxxu: Add additional USB IDs for RTL8192EU devices Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 57/68] libbpf: Fix NULL pointer dereference in bpf_object__collect_prog_relos Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 58/68] wifi: rtlwifi: add calculate_bit_shift() Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 59/68] wifi: rtlwifi: rtl8723{be,ae}: using calculate_bit_shift() Sasha Levin
2024-01-16 19:53 ` [PATCH AUTOSEL 6.1 60/68] wifi: cfg80211: free beacon_ies when overridden from hidden BSS Sasha Levin
2024-01-16 19:54 ` [PATCH AUTOSEL 6.1 61/68] Bluetooth: qca: Set both WIDEBAND_SPEECH and LE_STATES quirks for QCA2066 Sasha Levin
2024-01-16 19:54 ` [PATCH AUTOSEL 6.1 62/68] Bluetooth: hci_sync: fix BR/EDR wakeup bug Sasha Levin
2024-01-16 19:54 ` [PATCH AUTOSEL 6.1 63/68] Bluetooth: L2CAP: Fix possible multiple reject send Sasha Levin
2024-01-16 19:54 ` [PATCH AUTOSEL 6.1 64/68] net/smc: disable SEID on non-s390 archs where virtual ISM may be used Sasha Levin
2024-01-16 19:54 ` [PATCH AUTOSEL 6.1 65/68] bridge: cfm: fix enum typo in br_cc_ccm_tx_parse Sasha Levin
2024-01-16 19:54 ` [PATCH AUTOSEL 6.1 66/68] i40e: Fix VF disable behavior to block all traffic Sasha Levin
2024-01-16 19:54 ` [PATCH AUTOSEL 6.1 67/68] octeontx2-af: Fix max NPC MCAM entry check while validating ref_entry Sasha Levin
2024-01-16 19:54 ` Sasha Levin [this message]
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=20240116195511.255854-68-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=alsi@bang-olufsen.dk \
--cc=andrew@lunn.ch \
--cc=ansuelsmth@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=florian.fainelli@broadcom.com \
--cc=kabel@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=rmk+kernel@armlinux.org.uk \
--cc=stable@vger.kernel.org \
--cc=vladimir.oltean@nxp.com \
/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
all inboxes | Powered by JetHome®