Skip to contentSkip to conversation

PCI: rcar: Release temporary device tree node reference

PATCH In review Yuho Choi 3 participants 3 messages Aug 1 – Aug 2

Subsystems (4)
lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 PCI: rcar: Release temporary device tree node reference

of_find_matching_node() returns a referenced node even when it is used only as a boolean test. Keep the result in a scoped cleanup variable so the reference is released after the match check.

Fixes a115b1bd3af0 ("PCI: rcar: Add L1 link state fix into data abort hook")
---
 drivers/pci/controller/pcie-rcar-host.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-rcar-host.c +4 -1
index cd9171eebc28..7ed1bc0732ce 100644
@@ -1122,7 +1122,10 @@ static const struct of_device_id rcar_pcie_abort_handler_of_match[] __initconst
 
 static int __init rcar_pcie_init(void)
 {
-	if (of_find_matching_node(NULL, rcar_pcie_abort_handler_of_match)) {
+	struct device_node *np __free(device_node) =
+		of_find_matching_node(NULL, rcar_pcie_abort_handler_of_match);
+
+	if (np) {
 #ifdef CONFIG_ARM_LPAE
 		hook_fault_code(17, rcar_pcie_aarch32_abort_handler, SIGBUS, 0,
 				"asynchronous external abort");
Signature · 1 line
2.43.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines

of_find_matching_node() returns a referenced node even when it is used only as a boolean test. Keep the result in a scoped cleanup variable so the reference is released after the match check.

Fixes a115b1bd3af0 ("PCI: rcar: Add L1 link state fix into data abort hook")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Yuho Choi
Quoted 16 lines · Yuho Choi

of_find_matching_node() returns a referenced node even when it is used only as a boolean test. Keep the result in a scoped cleanup variable so the reference is released after the match check.

Fixes a115b1bd3af0 ("PCI: rcar: Add L1 link state fix into data abort hook")
---
  drivers/pci/controller/pcie-rcar-host.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-rcar-host.c +0 -0
index cd9171eebc28..7ed1bc0732ce 100644
@@ -1122,7 +1122,10 @@ static const struct of_device_id rcar_pcie_abort_handler_of_match[] __initconst
 

drivers/pci/controller/pcie-rcar-host.c static const struct of_device_id rcar_pcie_abort_handler_of_match[] __initconst · line 1131

Quoted 10 lines
drivers/pci/controller/pcie-rcar-host.c +4 -1
  static int __init rcar_pcie_init(void)
  {
-	if (of_find_matching_node(NULL, rcar_pcie_abort_handler_of_match)) {
+	struct device_node *np __free(device_node) =
+		of_find_matching_node(NULL, rcar_pcie_abort_handler_of_match);
+
+	if (np) {
  #ifdef CONFIG_ARM_LPAE
  		hook_fault_code(17, rcar_pcie_aarch32_abort_handler, SIGBUS, 0,
  				"asynchronous external abort");

How about this simpler version:

"

drivers/pci/controller/pcie-rcar-host.c +3 -1
index 213028052aa58..a4a42e435947f 100644
@@ -1123,7 +1123,9 @@ static const struct of_device_id rcar_pcie_abort_handler_of_match[] __initconst
 
 static int __init rcar_pcie_init(void)
 {
-       if (of_find_matching_node(NULL, rcar_pcie_abort_handler_of_match)) {
+       struct device_node *np = of_find_matching_node(NULL, rcar_pcie_abort_handler_of_match);
+       if (np) {
+               of_node_put(np);
 #ifdef CONFIG_ARM_LPAE
                hook_fault_code(17, rcar_pcie_aarch32_abort_handler, 

SIGBUS, 0,

                                "asynchronous external abort");

"

Also, and this is more of a question for DT maintainers, would it make sense to introduce of_find_matching_node_and_match() variant called e.g. of_test_matching_node_exists() which would return boolean and would NOT call of_node_get() on the matched node in the first place, and then use it here ?