linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Use of_get_child_by_name() instead of of_find_node_by_name()
@ 2015-01-14 13:51 Geert Uytterhoeven
  2015-01-14 13:51 ` [PATCH 1/3] powerpc/pmac: Fix DT refcount imbalance in pmac_pic_probe_oldstyle Geert Uytterhoeven
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Geert Uytterhoeven @ 2015-01-14 13:51 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Bryan Wu, Richard Purdie, Jingoo Han, Lee Jones
  Cc: devicetree, linux-kernel, Geert Uytterhoeven

	Hi Ben, Bryan/Richard, Jingoo/Lee,

Internally, of_find_node_by_name() calls of_node_put() on its "from"
parameter.  This is a problem if that device_node will be used
afterwards, or if of_node_put() is called on it again (either manually
or in a for_each_*_node() loop) later, as that may cause a zero kref
refcount. This may be caught by the system if CONFIG_OF_DYNAMIC=y:

	ERROR: Bad of_node_put() on /....

Use of_get_child_by_name() instead to fix this, and remove existing
workarounds to pre-increase the refcount.

Compile-tested only.

Geert Uytterhoeven (3):
  powerpc/pmac: Fix DT refcount imbalance in pmac_pic_probe_oldstyle
  leds: leds-mc13783: Use of_get_child_by_name() instead of refcount
    hack
  backlight: 88pm860x_bl: Use of_get_child_by_name() instead of refcount
    hack

 arch/powerpc/platforms/powermac/pic.c | 2 +-
 drivers/leds/leds-mc13783.c           | 4 +---
 drivers/video/backlight/88pm860x_bl.c | 5 +----
 3 files changed, 3 insertions(+), 8 deletions(-)

-- 
1.9.1

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] powerpc/pmac: Fix DT refcount imbalance in pmac_pic_probe_oldstyle
  2015-01-14 13:51 [PATCH 0/3] Use of_get_child_by_name() instead of of_find_node_by_name() Geert Uytterhoeven
@ 2015-01-14 13:51 ` Geert Uytterhoeven
  2015-01-30  4:09   ` [1/3] " Michael Ellerman
  2015-01-14 13:51 ` [PATCH 2/3] leds: leds-mc13783: Use of_get_child_by_name() instead of refcount hack Geert Uytterhoeven
  2015-01-14 13:51 ` [PATCH 3/3] backlight: 88pm860x_bl: " Geert Uytterhoeven
  2 siblings, 1 reply; 9+ messages in thread
From: Geert Uytterhoeven @ 2015-01-14 13:51 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Bryan Wu, Richard Purdie, Jingoo Han, Lee Jones
  Cc: devicetree, linux-kernel, Geert Uytterhoeven, linuxppc-dev

of_find_node_by_name() calls of_node_put() on its "from" parameter,
which must not be done on "master", as it's still in use, and will be
released manually later.  This may cause a zero kref refcount.
Use of_get_child_by_name() instead to fix this.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: linuxppc-dev@lists.ozlabs.org
---
Compile-tested only
---
 arch/powerpc/platforms/powermac/pic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/powermac/pic.c b/arch/powerpc/platforms/powermac/pic.c
index 4c24bf60d39d2834..90ada1209c118902 100644
--- a/arch/powerpc/platforms/powermac/pic.c
+++ b/arch/powerpc/platforms/powermac/pic.c
@@ -321,7 +321,7 @@ static void __init pmac_pic_probe_oldstyle(void)
 		max_irqs = max_real_irqs = 64;
 
 		/* We might have a second cascaded heathrow */
-		slave = of_find_node_by_name(master, "mac-io");
+		slave = of_get_child_by_name(master, "mac-io");
 
 		/* Check ordering of master & slave */
 		if (of_device_is_compatible(master, "gatwick")) {
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] leds: leds-mc13783: Use of_get_child_by_name() instead of refcount hack
  2015-01-14 13:51 [PATCH 0/3] Use of_get_child_by_name() instead of of_find_node_by_name() Geert Uytterhoeven
  2015-01-14 13:51 ` [PATCH 1/3] powerpc/pmac: Fix DT refcount imbalance in pmac_pic_probe_oldstyle Geert Uytterhoeven
@ 2015-01-14 13:51 ` Geert Uytterhoeven
  2015-01-14 18:42   ` Bryan Wu
  2015-01-14 13:51 ` [PATCH 3/3] backlight: 88pm860x_bl: " Geert Uytterhoeven
  2 siblings, 1 reply; 9+ messages in thread
From: Geert Uytterhoeven @ 2015-01-14 13:51 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Bryan Wu, Richard Purdie, Jingoo Han, Lee Jones
  Cc: devicetree, linux-kernel, Geert Uytterhoeven, linux-leds

of_find_node_by_name() calls of_node_put() on its "from" parameter.
To counter this, mc13xxx_led_probe_dt() calls of_node_get() first.

Use of_get_child_by_name() instead to get rid of the refcount hack.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: linux-leds@vger.kernel.org
---
Compile-tested only
---
 drivers/leds/leds-mc13783.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
index 85c3714e1b5aabba..e2b847fe22a1c934 100644
--- a/drivers/leds/leds-mc13783.c
+++ b/drivers/leds/leds-mc13783.c
@@ -134,9 +134,7 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
 	if (!pdata)
 		return ERR_PTR(-ENOMEM);
 
-	of_node_get(dev->parent->of_node);
-
-	parent = of_find_node_by_name(dev->parent->of_node, "leds");
+	parent = of_get_child_by_name(dev->parent->of_node, "leds");
 	if (!parent)
 		goto out_node_put;
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] backlight: 88pm860x_bl: Use of_get_child_by_name() instead of refcount hack
  2015-01-14 13:51 [PATCH 0/3] Use of_get_child_by_name() instead of of_find_node_by_name() Geert Uytterhoeven
  2015-01-14 13:51 ` [PATCH 1/3] powerpc/pmac: Fix DT refcount imbalance in pmac_pic_probe_oldstyle Geert Uytterhoeven
  2015-01-14 13:51 ` [PATCH 2/3] leds: leds-mc13783: Use of_get_child_by_name() instead of refcount hack Geert Uytterhoeven
@ 2015-01-14 13:51 ` Geert Uytterhoeven
  2015-01-18 12:46   ` Lee Jones
  2 siblings, 1 reply; 9+ messages in thread
From: Geert Uytterhoeven @ 2015-01-14 13:51 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Bryan Wu, Richard Purdie, Jingoo Han, Lee Jones
  Cc: devicetree, linux-kernel, Geert Uytterhoeven, linux-fbdev

of_find_node_by_name() calls of_node_put() on its "from" parameter.
To counter this, pm860x_backlight_dt_init() calls of_node_get() first.

Use of_get_child_by_name() instead to get rid of the refcount hack.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: linux-fbdev@vger.kernel.org
---
Compile-tested only
---
 drivers/video/backlight/88pm860x_bl.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/video/backlight/88pm860x_bl.c b/drivers/video/backlight/88pm860x_bl.c
index 9a23698b6fe8398c..2da5862876d1fe78 100644
--- a/drivers/video/backlight/88pm860x_bl.c
+++ b/drivers/video/backlight/88pm860x_bl.c
@@ -168,10 +168,7 @@ static int pm860x_backlight_dt_init(struct platform_device *pdev,
 	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");
+	nproot = of_get_child_by_name(pdev->dev.parent->of_node, "backlights");
 	if (!nproot) {
 		dev_err(&pdev->dev, "failed to find backlights node\n");
 		return -ENODEV;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] leds: leds-mc13783: Use of_get_child_by_name() instead of refcount hack
  2015-01-14 13:51 ` [PATCH 2/3] leds: leds-mc13783: Use of_get_child_by_name() instead of refcount hack Geert Uytterhoeven
@ 2015-01-14 18:42   ` Bryan Wu
  0 siblings, 0 replies; 9+ messages in thread
From: Bryan Wu @ 2015-01-14 18:42 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Benjamin Herrenschmidt, Richard Purdie, Jingoo Han, Lee Jones,
	devicetree, lkml, Linux LED Subsystem

On Wed, Jan 14, 2015 at 5:51 AM, Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
> of_find_node_by_name() calls of_node_put() on its "from" parameter.
> To counter this, mc13xxx_led_probe_dt() calls of_node_get() first.
>
> Use of_get_child_by_name() instead to get rid of the refcount hack.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Cc: linux-leds@vger.kernel.org

Looks good, applied to my tree.
Thanks,
-Bryan


> ---
> Compile-tested only
> ---
>  drivers/leds/leds-mc13783.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
> index 85c3714e1b5aabba..e2b847fe22a1c934 100644
> --- a/drivers/leds/leds-mc13783.c
> +++ b/drivers/leds/leds-mc13783.c
> @@ -134,9 +134,7 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
>         if (!pdata)
>                 return ERR_PTR(-ENOMEM);
>
> -       of_node_get(dev->parent->of_node);
> -
> -       parent = of_find_node_by_name(dev->parent->of_node, "leds");
> +       parent = of_get_child_by_name(dev->parent->of_node, "leds");
>         if (!parent)
>                 goto out_node_put;
>
> --
> 1.9.1
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] backlight: 88pm860x_bl: Use of_get_child_by_name() instead of refcount hack
  2015-01-14 13:51 ` [PATCH 3/3] backlight: 88pm860x_bl: " Geert Uytterhoeven
@ 2015-01-18 12:46   ` Lee Jones
  0 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2015-01-18 12:46 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Benjamin Herrenschmidt, Bryan Wu, Richard Purdie, Jingoo Han,
	devicetree, linux-kernel, linux-fbdev

On Wed, 14 Jan 2015, Geert Uytterhoeven wrote:

> of_find_node_by_name() calls of_node_put() on its "from" parameter.
> To counter this, pm860x_backlight_dt_init() calls of_node_get() first.
> 
> Use of_get_child_by_name() instead to get rid of the refcount hack.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Cc: linux-fbdev@vger.kernel.org
> ---
> Compile-tested only
> ---
>  drivers/video/backlight/88pm860x_bl.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)

Looks good, applied, thanks.

> diff --git a/drivers/video/backlight/88pm860x_bl.c b/drivers/video/backlight/88pm860x_bl.c
> index 9a23698b6fe8398c..2da5862876d1fe78 100644
> --- a/drivers/video/backlight/88pm860x_bl.c
> +++ b/drivers/video/backlight/88pm860x_bl.c
> @@ -168,10 +168,7 @@ static int pm860x_backlight_dt_init(struct platform_device *pdev,
>  	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");
> +	nproot = of_get_child_by_name(pdev->dev.parent->of_node, "backlights");
>  	if (!nproot) {
>  		dev_err(&pdev->dev, "failed to find backlights node\n");
>  		return -ENODEV;

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [1/3] powerpc/pmac: Fix DT refcount imbalance in pmac_pic_probe_oldstyle
  2015-01-14 13:51 ` [PATCH 1/3] powerpc/pmac: Fix DT refcount imbalance in pmac_pic_probe_oldstyle Geert Uytterhoeven
@ 2015-01-30  4:09   ` Michael Ellerman
  2015-01-30  9:00     ` Geert Uytterhoeven
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Ellerman @ 2015-01-30  4:09 UTC (permalink / raw)
  To: Geert Uytterhoeven, Benjamin Herrenschmidt, Bryan Wu,
	Richard Purdie, Jingoo Han, Lee Jones
  Cc: devicetree, linuxppc-dev, linux-kernel, Geert Uytterhoeven

On Wed, 2015-14-01 at 13:51:57 UTC, Geert Uytterhoeven wrote:
> of_find_node_by_name() calls of_node_put() on its "from" parameter,
> which must not be done on "master", as it's still in use, and will be
> released manually later.  This may cause a zero kref refcount.
> Use of_get_child_by_name() instead to fix this.

But of_find_node_by_name() searches *all* nodes, not just the children of the
parameter.

So this is a logic change AFAICS, and I have no idea what machines we'd need to
test on to check it.

So I think an of_node_get(master) would be safer and also fix the refcounting.

cheers

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [1/3] powerpc/pmac: Fix DT refcount imbalance in pmac_pic_probe_oldstyle
  2015-01-30  4:09   ` [1/3] " Michael Ellerman
@ 2015-01-30  9:00     ` Geert Uytterhoeven
  2015-02-03  1:12       ` Michael Ellerman
  0 siblings, 1 reply; 9+ messages in thread
From: Geert Uytterhoeven @ 2015-01-30  9:00 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: Geert Uytterhoeven, Benjamin Herrenschmidt, Bryan Wu,
	Richard Purdie, Jingoo Han, Lee Jones, devicetree, linuxppc-dev,
	linux-kernel

Hi Michael,

On Fri, Jan 30, 2015 at 5:09 AM, Michael Ellerman <mpe@ellerman.id.au> wrote:
> On Wed, 2015-14-01 at 13:51:57 UTC, Geert Uytterhoeven wrote:
>> of_find_node_by_name() calls of_node_put() on its "from" parameter,
>> which must not be done on "master", as it's still in use, and will be
>> released manually later.  This may cause a zero kref refcount.
>> Use of_get_child_by_name() instead to fix this.
>
> But of_find_node_by_name() searches *all* nodes, not just the children of the
> parameter.

That's correct. However, I guess the second mac-io will just be a direct child.

> So this is a logic change AFAICS, and I have no idea what machines we'd need to
> test on to check it.

Originally it comes from arch/ppc/platforms/pmac_pic.c, added in 2002 in
full-history-linux commit 5ea3254844ae344a
("Import arch/ppc and include/asm-ppc changes from linuxppc_2_5 tree").

I've also checked my linuxppc mail archives from 1997-2002, but couldn't find
the actual patch and a description.

So I don't know on which machines it's needed.

> So I think an of_node_get(master) would be safer and also fix the refcounting.

If no one can confirm the above, that may indeed be the best solution.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [1/3] powerpc/pmac: Fix DT refcount imbalance in pmac_pic_probe_oldstyle
  2015-01-30  9:00     ` Geert Uytterhoeven
@ 2015-02-03  1:12       ` Michael Ellerman
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Ellerman @ 2015-02-03  1:12 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Geert Uytterhoeven, Benjamin Herrenschmidt, Bryan Wu,
	Richard Purdie, Jingoo Han, Lee Jones, devicetree, linuxppc-dev,
	linux-kernel

On Fri, 2015-01-30 at 10:00 +0100, Geert Uytterhoeven wrote:
> Hi Michael,
> 
> On Fri, Jan 30, 2015 at 5:09 AM, Michael Ellerman <mpe@ellerman.id.au> wrote:
> > On Wed, 2015-14-01 at 13:51:57 UTC, Geert Uytterhoeven wrote:
> >> of_find_node_by_name() calls of_node_put() on its "from" parameter,
> >> which must not be done on "master", as it's still in use, and will be
> >> released manually later.  This may cause a zero kref refcount.
> >> Use of_get_child_by_name() instead to fix this.
> >
> > But of_find_node_by_name() searches *all* nodes, not just the children of the
> > parameter.
> 
> That's correct. However, I guess the second mac-io will just be a direct child.

Yeah OK, I don't have a system or an example device tree to check.

> > So this is a logic change AFAICS, and I have no idea what machines we'd need to
> > test on to check it.
> 
> Originally it comes from arch/ppc/platforms/pmac_pic.c, added in 2002 in
> full-history-linux commit 5ea3254844ae344a
> ("Import arch/ppc and include/asm-ppc changes from linuxppc_2_5 tree").
> 
> I've also checked my linuxppc mail archives from 1997-2002, but couldn't find
> the actual patch and a description.
> 
> So I don't know on which machines it's needed.

Yep. Ben or Paul might know, but even then their memory may not be perfect :)
 
> > So I think an of_node_get(master) would be safer and also fix the refcounting.
> 
> If no one can confirm the above, that may indeed be the best solution.

I think so. Given how few of these machines are around it's easy to break them
with an inadvertent change like this, so I think it's better to be safe.

Wanna send a patch for that?

cheers




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-02-03  1:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-14 13:51 [PATCH 0/3] Use of_get_child_by_name() instead of of_find_node_by_name() Geert Uytterhoeven
2015-01-14 13:51 ` [PATCH 1/3] powerpc/pmac: Fix DT refcount imbalance in pmac_pic_probe_oldstyle Geert Uytterhoeven
2015-01-30  4:09   ` [1/3] " Michael Ellerman
2015-01-30  9:00     ` Geert Uytterhoeven
2015-02-03  1:12       ` Michael Ellerman
2015-01-14 13:51 ` [PATCH 2/3] leds: leds-mc13783: Use of_get_child_by_name() instead of refcount hack Geert Uytterhoeven
2015-01-14 18:42   ` Bryan Wu
2015-01-14 13:51 ` [PATCH 3/3] backlight: 88pm860x_bl: " Geert Uytterhoeven
2015-01-18 12:46   ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).