Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1382011 > unrolled thread

[PATCH 1/5] input: twl6040-vibra: fix DT node memory management

Started by"H. Nikolaus Schaller" <hns@goldelico.com>
First post2016-04-18 22:00 +0200
Last post2016-04-20 11:10 +0200
Articles 5 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 1/5] input: twl6040-vibra: fix DT node memory management "H. Nikolaus Schaller" <hns@goldelico.com> - 2016-04-18 22:00 +0200
    Re: [PATCH 1/5] input: twl6040-vibra: fix DT node memory management Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2016-04-18 23:30 +0200
      Re: [PATCH 1/5] input: twl6040-vibra: fix DT node memory management "H. Nikolaus Schaller" <hns@goldelico.com> - 2016-04-19 09:50 +0200
        Re: [PATCH 1/5] input: twl6040-vibra: fix DT node memory management Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2016-04-19 19:10 +0200
          Re: [PATCH 1/5] input: twl6040-vibra: fix DT node memory management "H. Nikolaus Schaller" <hns@goldelico.com> - 2016-04-20 11:10 +0200

#1382011 — [PATCH 1/5] input: twl6040-vibra: fix DT node memory management

From"H. Nikolaus Schaller" <hns@goldelico.com>
Date2016-04-18 22:00 +0200
Subject[PATCH 1/5] input: twl6040-vibra: fix DT node memory management
Message-ID<rpnuW-2F6-13@gated-at.bofh.it>
commit e7ec014a47e4 ("Input: twl6040-vibra - update for device tree support")

made the separate vibra DT node to a subnode of the twl6040.

It now calls of_find_node_by_name() to locate the "vibra" subnode.
This function has a side effect to call of_node_put on() for the twl6040
parent node passed in as a parameter. This causes trouble later on.

Solution: we must call of_node_get() before of_find_node_by_name()

Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
---
 drivers/input/misc/twl6040-vibra.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/input/misc/twl6040-vibra.c b/drivers/input/misc/twl6040-vibra.c
index ea63fad..7221a00 100644
--- a/drivers/input/misc/twl6040-vibra.c
+++ b/drivers/input/misc/twl6040-vibra.c
@@ -262,6 +262,7 @@ static int twl6040_vibra_probe(struct platform_device *pdev)
 	int vddvibr_uV = 0;
 	int error;
 
+	of_node_get(twl6040_core_dev->of_node);
 	twl6040_core_node = of_find_node_by_name(twl6040_core_dev->of_node,
 						 "vibra");
 	if (!twl6040_core_node) {
-- 
2.7.3

[toc] | [next] | [standalone]


#1382072

FromDmitry Torokhov <dmitry.torokhov@gmail.com>
Date2016-04-18 23:30 +0200
Message-ID<rpoU2-422-19@gated-at.bofh.it>
In reply to#1382011
On Mon, Apr 18, 2016 at 09:55:37PM +0200, H. Nikolaus Schaller wrote:
> commit e7ec014a47e4 ("Input: twl6040-vibra - update for device tree support")
> 
> made the separate vibra DT node to a subnode of the twl6040.
> 
> It now calls of_find_node_by_name() to locate the "vibra" subnode.
> This function has a side effect to call of_node_put on() for the twl6040
> parent node passed in as a parameter. This causes trouble later on.
> 
> Solution: we must call of_node_get() before of_find_node_by_name()

God, what messed up API. Any chance we can make it a bit more sane and
not drop the reference inside it instead?

> 
> Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
> ---
>  drivers/input/misc/twl6040-vibra.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/input/misc/twl6040-vibra.c b/drivers/input/misc/twl6040-vibra.c
> index ea63fad..7221a00 100644
> --- a/drivers/input/misc/twl6040-vibra.c
> +++ b/drivers/input/misc/twl6040-vibra.c
> @@ -262,6 +262,7 @@ static int twl6040_vibra_probe(struct platform_device *pdev)
>  	int vddvibr_uV = 0;
>  	int error;
>  
> +	of_node_get(twl6040_core_dev->of_node);
>  	twl6040_core_node = of_find_node_by_name(twl6040_core_dev->of_node,
>  						 "vibra");
>  	if (!twl6040_core_node) {
> -- 
> 2.7.3
> 

-- 
Dmitry

[toc] | [prev] | [next] | [standalone]


#1382235

From"H. Nikolaus Schaller" <hns@goldelico.com>
Date2016-04-19 09:50 +0200
Message-ID<rpyA1-3dt-9@gated-at.bofh.it>
In reply to#1382072
> Am 18.04.2016 um 23:22 schrieb Dmitry Torokhov <dmitry.torokhov@gmail.com>:
> 
> On Mon, Apr 18, 2016 at 09:55:37PM +0200, H. Nikolaus Schaller wrote:
>> commit e7ec014a47e4 ("Input: twl6040-vibra - update for device tree support")
>> 
>> made the separate vibra DT node to a subnode of the twl6040.
>> 
>> It now calls of_find_node_by_name() to locate the "vibra" subnode.
>> This function has a side effect to call of_node_put on() for the twl6040
>> parent node passed in as a parameter. This causes trouble later on.
>> 
>> Solution: we must call of_node_get() before of_find_node_by_name()
> 
> God, what messed up API.

Yes, indeed. It is opposite to the usual object ownership rule that the code
fragment that asks for a handle has to release it.

Usually it does not become obvious because often CONFIG_OF_DYNAMIC=n.
This disables all of_node refcounting completely so such bugs remain unnoticed.

> Any chance we can make it a bit more sane and
> not drop the reference inside it instead?

Well, if you want to change ~2000 files, test on all platforms and ask Linus
for agreement?

> 
>> 
>> Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
>> ---
>> drivers/input/misc/twl6040-vibra.c | 1 +
>> 1 file changed, 1 insertion(+)
>> 
>> diff --git a/drivers/input/misc/twl6040-vibra.c b/drivers/input/misc/twl6040-vibra.c
>> index ea63fad..7221a00 100644
>> --- a/drivers/input/misc/twl6040-vibra.c
>> +++ b/drivers/input/misc/twl6040-vibra.c
>> @@ -262,6 +262,7 @@ static int twl6040_vibra_probe(struct platform_device *pdev)
>> 	int vddvibr_uV = 0;
>> 	int error;
>> 
>> +	of_node_get(twl6040_core_dev->of_node);
>> 	twl6040_core_node = of_find_node_by_name(twl6040_core_dev->of_node,
>> 						 "vibra");
>> 	if (!twl6040_core_node) {
>> -- 
>> 2.7.3
>> 
> 
> -- 
> Dmitry

[toc] | [prev] | [next] | [standalone]


#1382715

FromDmitry Torokhov <dmitry.torokhov@gmail.com>
Date2016-04-19 19:10 +0200
Message-ID<rpHjY-1Nv-13@gated-at.bofh.it>
In reply to#1382235
On Tue, Apr 19, 2016 at 09:43:08AM +0200, H. Nikolaus Schaller wrote:
> 
> > Am 18.04.2016 um 23:22 schrieb Dmitry Torokhov <dmitry.torokhov@gmail.com>:
> > 
> > On Mon, Apr 18, 2016 at 09:55:37PM +0200, H. Nikolaus Schaller wrote:
> >> commit e7ec014a47e4 ("Input: twl6040-vibra - update for device tree support")
> >> 
> >> made the separate vibra DT node to a subnode of the twl6040.
> >> 
> >> It now calls of_find_node_by_name() to locate the "vibra" subnode.
> >> This function has a side effect to call of_node_put on() for the twl6040
> >> parent node passed in as a parameter. This causes trouble later on.
> >> 
> >> Solution: we must call of_node_get() before of_find_node_by_name()
> > 
> > God, what messed up API.
> 
> Yes, indeed. It is opposite to the usual object ownership rule that the code
> fragment that asks for a handle has to release it.
> 
> Usually it does not become obvious because often CONFIG_OF_DYNAMIC=n.
> This disables all of_node refcounting completely so such bugs remain unnoticed.
> 
> > Any chance we can make it a bit more sane and
> > not drop the reference inside it instead?
> 
> Well, if you want to change ~2000 files, test on all platforms and ask Linus
> for agreement?

It's not that bad, let's see what DT maintainers say to the patch I
posted...

-- 
Dmitry

[toc] | [prev] | [next] | [standalone]


#1383183

From"H. Nikolaus Schaller" <hns@goldelico.com>
Date2016-04-20 11:10 +0200
Message-ID<rpWj1-5uh-25@gated-at.bofh.it>
In reply to#1382715
> Am 19.04.2016 um 19:06 schrieb Dmitry Torokhov <dmitry.torokhov@gmail.com>:
> 
> On Tue, Apr 19, 2016 at 09:43:08AM +0200, H. Nikolaus Schaller wrote:
>> 
>>> Am 18.04.2016 um 23:22 schrieb Dmitry Torokhov <dmitry.torokhov@gmail.com>:
>>> 
>>> On Mon, Apr 18, 2016 at 09:55:37PM +0200, H. Nikolaus Schaller wrote:
>>>> commit e7ec014a47e4 ("Input: twl6040-vibra - update for device tree support")
>>>> 
>>>> made the separate vibra DT node to a subnode of the twl6040.
>>>> 
>>>> It now calls of_find_node_by_name() to locate the "vibra" subnode.
>>>> This function has a side effect to call of_node_put on() for the twl6040
>>>> parent node passed in as a parameter. This causes trouble later on.
>>>> 
>>>> Solution: we must call of_node_get() before of_find_node_by_name()
>>> 
>>> God, what messed up API.
>> 
>> Yes, indeed. It is opposite to the usual object ownership rule that the code
>> fragment that asks for a handle has to release it.
>> 
>> Usually it does not become obvious because often CONFIG_OF_DYNAMIC=n.
>> This disables all of_node refcounting completely so such bugs remain unnoticed.
>> 
>>> Any chance we can make it a bit more sane and
>>> not drop the reference inside it instead?
>> 
>> Well, if you want to change ~2000 files, test on all platforms and ask Linus
>> for agreement?
> 
> It's not that bad, let's see what DT maintainers say to the patch I
> posted...

Thanks! Would make me more happy a well.

Nikolaus

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web