Skip to contentSkip to conversation

drivers/soc/tegra: Replace dev_node refcount management

PATCH In review Miguel Miranda 2 participants 2 messages Apr 24, 2024 – Apr 25, 2024 Tegra architecture support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/soc/tegra: Replace dev_node refcount management

Remove the manual refcount management of device_node and instead, use scope-based resource management.

While the pointer never gets out of scope it reduces somehow the risk of missing the of_node_put() call.

---
I only have a deprecated jetson nano dev-kit, but need to test this on hardware. I am exploring options to build a rootfs to test this using qemu-system-aarch64.

---
 drivers/soc/tegra/common.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/soc/tegra/common.c +1 -3
index dff6d5ef4e46..94d11102d90f 100644
@@ -28,14 +28,12 @@ static const struct of_device_id tegra_machine_match[] = {
 bool soc_is_tegra(void)
 {
 	const struct of_device_id *match;
-	struct device_node *root;
+	struct device_node *root __free(device_node) = of_find_node_by_path("/");
 
-	root = of_find_node_by_path("/");
 	if (!root)
 		return false;
 
 	match = of_match_node(tegra_machine_match, root);
-	of_node_put(root);
 
 	return match != NULL;
 }
Signature · 1 line
2.25.1
#1 lore raw
Quoted 5 lines · Miguel Miranda

Remove the manual refcount management of device_node and instead, use scope-based resource management.

While the pointer never gets out of scope it reduces somehow the risk of missing the of_node_put() call.

I don't understand what you're trying to say here.

Quoted 6 lines

---
I only have a deprecated jetson nano dev-kit, but need to test this on hardware. I am exploring options to build a rootfs to test this using qemu-system-aarch64.

It doesn't look like it'll be necessary to extensively test this. Just by inspecting this we can see that it doesn't change behaviour. There isn't really a big advantage to employ the __free() mechanism here since we have exactly one of_node_put() to clean up, but I guess why not. So maybe reword that commit message to be less confusing.

Thierry

Quoted 24 lines
---
 drivers/soc/tegra/common.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/soc/tegra/common.c +1 -3
index dff6d5ef4e46..94d11102d90f 100644
@@ -28,14 +28,12 @@ static const struct of_device_id tegra_machine_match[] = {
 bool soc_is_tegra(void)
 {
 	const struct of_device_id *match;
-	struct device_node *root;
+	struct device_node *root __free(device_node) = of_find_node_by_path("/");
 
-	root = of_find_node_by_path("/");
 	if (!root)
 		return false;
 
 	match = of_match_node(tegra_machine_match, root);
-	of_node_put(root);
 
 	return match != NULL;
 }