Skip to contentSkip to conversation

backlight: 88pm860x_bl: Add missing of_node_put()

PATCH In review Axel Lin 2 participants 2 messages Jan 27, 2013 – Feb 4, 2013

Subsystems (2)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH v2 1/1 backlight: 88pm860x_bl: Add missing of_node_put()

of_find_node_by_name() returns a node pointer with refcount incremented, use of_node_put() on it when done.

of_find_node_by_name() will call of_node_put() against the node pass to from parameter, thus we also need to call of_node_get(from) before calling of_find_node_by_name().

---
v2:
need to call of_node_get(pdev->dev.parent->of_node) before calling of_find_node_by_name().

 drivers/video/backlight/88pm860x_bl.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/video/backlight/88pm860x_bl.c +4 -1
index c072ed9..2cd6350 100644
@@ -165,8 +165,10 @@ static int pm860x_backlight_dt_init(struct platform_device *pdev,
 				    struct pm860x_backlight_data *data,
 				    char *name)
 {
-	struct device_node *nproot = pdev->dev.parent->of_node, *np;
+	struct device_node *nproot, *np;
 	int iset = 0;
+
+	nproot = of_node_get(pdev->dev.parent->of_node);
 	if (!nproot)
 		return -ENODEV;
 	nproot = of_find_node_by_name(nproot, "backlights");
@@ -184,6 +186,7 @@ static int pm860x_backlight_dt_init(struct platform_device *pdev,
 			break;
 		}
 	}
+	of_node_put(nproot);
 	return 0;
 }
 #else
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 33 lines · Axel Lin

of_find_node_by_name() returns a node pointer with refcount incremented, use of_node_put() on it when done.

of_find_node_by_name() will call of_node_put() against the node pass to from parameter, thus we also need to call of_node_get(from) before calling of_find_node_by_name().

---
v2:
need to call of_node_get(pdev->dev.parent->of_node) before calling of_find_node_by_name().

 drivers/video/backlight/88pm860x_bl.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/video/backlight/88pm860x_bl.c +3 -1
index c072ed9..2cd6350 100644
@@ -165,8 +165,10 @@ static int pm860x_backlight_dt_init(struct platform_device *pdev,
                                    struct pm860x_backlight_data *data,
                                    char *name)
 {
-       struct device_node *nproot = pdev->dev.parent->of_node, *np;
+       struct device_node *nproot, *np;
        int iset = 0;
+
+       nproot = of_node_get(pdev->dev.parent->of_node);
        if (!nproot)
                return -ENODEV;
        nproot = of_find_node_by_name(nproot, "backlights");

drivers/video/backlight/88pm860x_bl.c static int pm860x_backlight_dt_init(struct platform_device *pdev, · line 192

Quoted 7 lines
drivers/video/backlight/88pm860x_bl.c +1 -0
@@ -184,6 +186,7 @@ static int pm860x_backlight_dt_init(struct platform_device *pdev,
                        break;
                }
        }
+       of_node_put(nproot);
        return 0;
 }
 #else

Don't agree on this. If we want to protect it, we should use the logic in below.
1. of_node_get() in parent 88pm860x-core driver.
2. of_node_put() in child backlight driver or anything else.

The reference is used to prevent of_node releasing before some usage. At here, we need
to prevent parent driver to release of_node. I can't see any benefit from of_node_get()
in the child backlight driver.

Regards
Haojian