Skip to contentSkip to conversation

net: mscc: ocelot: add missing of_node_put after calling of_get_child_by_name

PATCH Applied Wen Yang 2 participants 3 messages Sep 29, 2019 – Oct 17, 2019

Subsystems (4)
lore
Share & tools
lore

Wen Yang

author
#0 lore raw

PATCH 1/1 net: mscc: ocelot: add missing of_node_put after calling of_get_child_by_name

of_node_put needs to be called when the device node which is got from of_get_child_by_name finished using.
In both cases of success and failure, we need to release 'ports', so clean up the code using goto.

Fixes a556c76adc05 ("net: mscc: Add initial Ocelot switch support")
Cc Alexandre Belloni <[email protected]>
Cc Microchip Linux Driver Support <[email protected]>
Cc "David S. Miller" <[email protected]>
---
 drivers/net/ethernet/mscc/ocelot_board.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/net/ethernet/mscc/ocelot_board.c +8 -6
index b063eb7..aac1151 100644
@@ -388,13 +388,14 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
 			continue;
 
 		phy = of_phy_find_device(phy_node);
+		of_node_put(phy_node);
 		if (!phy)
 			continue;
 
 		err = ocelot_probe_port(ocelot, port, regs, phy);
 		if (err) {
 			of_node_put(portnp);
-			return err;
+			goto out_put_ports;
 		}
 
 		phy_mode = of_get_phy_mode(portnp);
@@ -422,7 +423,8 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
 				"invalid phy mode for port%d, (Q)SGMII only\n",
 				port);
 			of_node_put(portnp);
-			return -EINVAL;
+			err = -EINVAL;
+			goto out_put_ports;
 		}
 
 		serdes = devm_of_phy_get(ocelot->dev, portnp, NULL);
@@ -435,7 +437,8 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
 					"missing SerDes phys for port%d\n",
 					port);
 
-			goto err_probe_ports;
+			of_node_put(portnp);
+			goto out_put_ports;
 		}
 
 		ocelot->ports[port]->serdes = serdes;
@@ -447,9 +450,8 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
 
 	dev_info(&pdev->dev, "Ocelot switch probed\n");
 
-	return 0;
-
-err_probe_ports:
+out_put_ports:
+	of_node_put(ports);
 	return err;
 }
 
Signature · 1 line
1.8.3.1
maintainer Applied
#1 lore raw

From: Wen Yang <[email protected]>
Date: Sun, 29 Sep 2019 14:54:24 +0800

Quoted 7 lines

of_node_put needs to be called when the device node which is got from of_get_child_by_name finished using.
In both cases of success and failure, we need to release 'ports', so clean up the code using goto.

Fixes a556c76adc05 ("net: mscc: Add initial Ocelot switch support")

Applied.

author
#2 lore raw
Quoted 8 lines · David Miller

From: Wen Yang <[email protected]>
Date: Sun, 29 Sep 2019 14:54:24 +0800

Quoted 5 lines

of_node_put needs to be called when the device node which is got from of_get_child_by_name finished using.
In both cases of success and failure, we need to release 'ports', so clean up the code using goto.

Quoted 5 lines
Quoted 2 lines
Fixes a556c76adc05 ("net: mscc: Add initial Ocelot switch support")

Applied.

Thank you for your comments.

We checked the code repository and found that both ‘Fixes’ and ‘fixes’ are being used, such as:

commit a53651ec93a8d7ab5b26c5390e0c389048b4b4b6
…
net: ena: don't wake up tx queue when down
…

Fixes 1738cd3ed342 (net: ena: Add a driver for Amazon Elastic

Network Adapters (ENA))
…

And,

commit 1df379924304b687263942452836db1d725155df …
clk: consoldiate the __clk_get_hw() declarations
…

Fixes 59fcdce425b7 ("clk: Remove ifdef for COMMON_CLK in

clk-provider.h")

Fixes 73e0e496afda ("clkdev: Always allocate a struct clk and call

__clk_get() w/ CCF")
…

It is also found that the sha1 following ‘Fixes:’ requires at least 12 digits.

So we plan to modify the checkpatch.pl script to check for these issues.

scripts/checkpatch.pl +20 -1
index a85d719..ddcd2d0 100755
@@ -2925,7 +2925,7 @@ sub process {
 		}
 
 # check for invalid commit id
-		if ($in_commit_log && $line =~ /(^fixes:|\bcommit)\s+([0-9a-f]{6,40})\b/i) {
+		if ($in_commit_log && $line =~ /(\bcommit)\s+([0-9a-f]{6,40})\b/i) {
 			my $id;
 			my $description;
 			($id, $description) = git_commit_info($2, undef, undef);
@@ -2935,6 +2935,25 @@ sub process {
 			}
 		}
 
+# check for fixes tag
+		if ($in_commit_log && $line =~ /(^fixes:)\s+([0-9a-f]{6,40})\b/i) {
+			my $id;
+			my $description;
+			($id, $description) = git_commit_info($2, undef, undef);
+			if (!defined($id)) {
+				WARN("UNKNOWN_COMMIT_ID",
+				     "Unknown commit id '$2', maybe rebased or not pulled?\n" . $herecurr);
+			}
+			if ($1 ne "Fixes") {
+				WARN("FIXES_TAG_STYLE",
+				     "The fixes tag should be capitalized (Fixes:).\n" . $hereprev);
+			}
+			if (length($2) < 12) {
+				WARN("FIXES_TAG_STYLE",
+				     "SHA1 should be at least 12 digits long.\n" . $hereprev);
+			}
+		}
+
 # ignore non-hunk lines and lines being removed
 		next if (!$hunk_line || $line =~ /^-/);
 

--
Best wishes,
Wen Yang