Skip to contentSkip to conversation

drm:pl111: Add of_node_put() when breaking out of for_each_available_child_of_node()

PATCH In review Liang He 3 participants 4 messages Jul 11, 2022 – Aug 11, 2022

Subsystems (3)
lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 drm:pl111: Add of_node_put() when breaking out of for_each_available_child_of_node()

The reference 'child' in the iteration of for_each_available_child_of_node() is only escaped out into a local variable which is only used to check its value. So we still need to the of_node_put() when breaking of the for_each_available_child_of_node() which will automatically increase and decrease the refcount.

Fixes ca454bd42dc2 ("drm/pl111: Support the Versatile Express")

---

As 'Check-after-Put' has been widely accepted in kernel source, we just use it. If the maintainer thinks it is harmful, I'd like also to use 'Check-and-Put' coding style but with a bit more work.

 drivers/gpu/drm/pl111/pl111_versatile.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/pl111/pl111_versatile.c +1 -0
index bdd883f4f0da..963a5d5e6987 100644
@@ -402,6 +402,7 @@ static int pl111_vexpress_clcd_init(struct device *dev, struct device_node *np,
 		if (of_device_is_compatible(child, "arm,pl111")) {
 			has_coretile_clcd = true;
 			ct_clcd = child;
+			of_node_put(child);
 			break;
 		}
 		if (of_device_is_compatible(child, "arm,hdlcd")) {
Signature · 1 line
2.25.1
#1 lore raw
Quoted 22 lines · Liang He

The reference 'child' in the iteration of for_each_available_child_of_node() is only escaped out into a local variable which is only used to check its value. So we still need to the of_node_put() when breaking of the for_each_available_child_of_node() which will automatically increase and decrease the refcount.

Fixes ca454bd42dc2 ("drm/pl111: Support the Versatile Express")

---

As 'Check-after-Put' has been widely accepted in kernel source, we just use it. If the maintainer thinks it is harmful, I'd like also to use 'Check-and-Put' coding style but with a bit more work.

 drivers/gpu/drm/pl111/pl111_versatile.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/pl111/pl111_versatile.c +0 -0
index bdd883f4f0da..963a5d5e6987 100644

drivers/gpu/drm/pl111/pl111_versatile.c static int pl111_vexpress_clcd_init(struct device *dev, struct device_node *np, · line 405

Quoted 4 lines
drivers/gpu/drm/pl111/pl111_versatile.c +1 -0
@@ -402,6 +402,7 @@ static int pl111_vexpress_clcd_init(struct device *dev, struct device_node *np,
 		if (of_device_is_compatible(child, "arm,pl111")) {
 			has_coretile_clcd = true;
 			ct_clcd = child;
+			of_node_put(child);

The same issue seems to exist right below in the next break? Can you pls respin with that included?

Thanks, Daniel

Quoted 6 lines
drivers/gpu/drm/pl111/pl111_versatile.c +0 -0
 			break;
 		}
 		if (of_device_is_compatible(child, "arm,hdlcd")) {
Signature · 1 line
2.25.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Reviewed-by
#2 lore raw
Quoted 19 lines · Daniel Vetter
Quoted 17 lines · Liang He

The reference 'child' in the iteration of for_each_available_child_of_node() is only escaped out into a local variable which is only used to check its value. So we still need to the of_node_put() when breaking of the for_each_available_child_of_node() which will automatically increase and decrease the refcount.

Fixes ca454bd42dc2 ("drm/pl111: Support the Versatile Express")

---

As 'Check-after-Put' has been widely accepted in kernel source, we just use it. If the maintainer thinks it is harmful, I'd like also to use 'Check-and-Put' coding style but with a bit more work.

 drivers/gpu/drm/pl111/pl111_versatile.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 12 lines

drivers/gpu/drm/pl111/pl111_versatile.c static int pl111_vexpress_clcd_init(struct device *dev, struct device_node *np, · line 405

Quoted 9 lines
drivers/gpu/drm/pl111/pl111_versatile.c +1 -0
index bdd883f4f0da..963a5d5e6987 100644
@@ -402,6 +402,7 @@ static int pl111_vexpress_clcd_init(struct device *dev, struct device_node *np,
              if (of_device_is_compatible(child, "arm,pl111")) {
                      has_coretile_clcd = true;
                      ct_clcd = child;
+                     of_node_put(child);

The same issue seems to exist right below in the next break? Can you pls respin with that included?

It has a put already.

#3 lore raw
Quoted 33 lines · Rob Herring
Quoted 19 lines · Daniel Vetter
Quoted 17 lines · Liang He

The reference 'child' in the iteration of for_each_available_child_of_node() is only escaped out into a local variable which is only used to check its value. So we still need to the of_node_put() when breaking of the for_each_available_child_of_node() which will automatically increase and decrease the refcount.

Fixes ca454bd42dc2 ("drm/pl111: Support the Versatile Express")

---

As 'Check-after-Put' has been widely accepted in kernel source, we just use it. If the maintainer thinks it is harmful, I'd like also to use 'Check-and-Put' coding style but with a bit more work.

 drivers/gpu/drm/pl111/pl111_versatile.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 12 lines

drivers/gpu/drm/pl111/pl111_versatile.c static int pl111_vexpress_clcd_init(struct device *dev, struct device_node *np, · line 405

Quoted 9 lines
drivers/gpu/drm/pl111/pl111_versatile.c +1 -0
index bdd883f4f0da..963a5d5e6987 100644
@@ -402,6 +402,7 @@ static int pl111_vexpress_clcd_init(struct device *dev, struct device_node *np,
              if (of_device_is_compatible(child, "arm,pl111")) {
                      has_coretile_clcd = true;
                      ct_clcd = child;
+                     of_node_put(child);

The same issue seems to exist right below in the next break? Can you pls respin with that included?

Quoted 3 lines

It has a put already.

Huh I was blind.

Thanks for patch&review, pushed to drm-misc-next.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch