Netdev List
 help / color / mirror / Atom feed
* [PATCH v2] net: dsa: Fix error handling in dsa_port_parse_of
@ 2025-12-14 13:12 Ma Ke
  2025-12-14 16:02 ` Jonas Gorski
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Ma Ke @ 2025-12-14 13:12 UTC (permalink / raw)
  To: andrew, olteanv, davem, edumazet, kuba, pabeni, horms, tobias
  Cc: netdev, linux-kernel, akpm, Ma Ke, stable

When of_find_net_device_by_node() successfully acquires a reference to
a network device but the subsequent call to dsa_port_parse_cpu()
fails, dsa_port_parse_of() returns without releasing the reference
count on the network device.

of_find_net_device_by_node() increments the reference count of the
returned structure, which should be balanced with a corresponding
put_device() when the reference is no longer needed.

Found by code review.

Cc: stable@vger.kernel.org
Fixes: deff710703d8 ("net: dsa: Allow default tag protocol to be overridden from DT")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
Changes in v2:
- simplified the patch as suggestions;
- modified the Fixes tag as suggestions.
---
 net/dsa/dsa.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index a20efabe778f..31b409a47491 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -1247,6 +1247,7 @@ static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
 	struct device_node *ethernet = of_parse_phandle(dn, "ethernet", 0);
 	const char *name = of_get_property(dn, "label", NULL);
 	bool link = of_property_read_bool(dn, "link");
+	int err = 0;
 
 	dp->dn = dn;
 
@@ -1260,7 +1261,11 @@ static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
 			return -EPROBE_DEFER;
 
 		user_protocol = of_get_property(dn, "dsa-tag-protocol", NULL);
-		return dsa_port_parse_cpu(dp, conduit, user_protocol);
+		err = dsa_port_parse_cpu(dp, conduit, user_protocol);
+		if (err)
+			put_device(conduit);
+
+		return err;
 	}
 
 	if (link)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-12-20 16:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-14 13:12 [PATCH v2] net: dsa: Fix error handling in dsa_port_parse_of Ma Ke
2025-12-14 16:02 ` Jonas Gorski
2025-12-14 16:10   ` Vladimir Oltean
2025-12-14 16:14     ` Jonas Gorski
2025-12-14 18:29       ` Vladimir Oltean
2025-12-20 14:34 ` kernel test robot
2025-12-20 16:41 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox