clocksource: Do not drop unheld reference on device node
PATCH 1/1 clocksource: Do not drop unheld reference on device node
When booting a recent kernel on ARM with OF_DYNAMIC enabled, the kernel warns about the following:
[ 0.000000] ERROR: Bad of_node_put() on /timer@50004600 [ 0.000000] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 3.12.0-rc5-next-20131017-00077-gedfd827-dirty #406 [ 0.000000] [<c0015b68>] (unwind_backtrace+0x0/0xf4) from [<c00117e4>] (show_stack+0x10/0x14) [ 0.000000] [<c00117e4>] (show_stack+0x10/0x14) from [<c055f734>] (dump_stack+0x9c/0xc8) [ 0.000000] [<c055f734>] (dump_stack+0x9c/0xc8) from [<c03b47d4>] (of_node_release+0x90/0x9c) [ 0.000000] [<c03b47d4>] (of_node_release+0x90/0x9c) from [<c03b5084>] (of_find_matching_node_and_match+0x78/0xb4) [ 0.000000] [<c03b5084>] (of_find_matching_node_and_match+0x78/0xb4) from [<c07887c8>] (clocksource_of_init+0x60/0x70) [ 0.000000] [<c07887c8>] (clocksource_of_init+0x60/0x70) from [<c076e99c>] (start_kernel+0x1f4/0x33c) [ 0.000000] [<c076e99c>] (start_kernel+0x1f4/0x33c) from [<80008074>] (0x80008074)
This is caused by clocksource_of_init() dropping a reference on the device node that it never took. The reference taken by the loop is implicitly dropped on subsequent iterations. See the implementation of and the comment on top of the of_find_matching_node_and_match() function for reference (no pun intended).
--- drivers/clocksource/clksrc-of.c | 1 - 1 file changed, 1 deletion(-)
drivers/clocksource/clksrc-of.c +0 -1
@@ -35,6 +35,5 @@ void __init clocksource_of_init(void) init_func = match->data;init_func (np); -of_node_put (np); } }
Signature · 1 line
1.8.4
Quoted 19 lines · Thierry Reding
When booting a recent kernel on ARM with
OF_DYNAMICenabled, the kernel warns about the following:[ 0.000000] ERROR: Bad of_node_put() on /timer@50004600 [ 0.000000] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 3.12.0-rc5-next-20131017-00077-gedfd827-dirty #406 [ 0.000000] [<c0015b68>] (unwind_backtrace+0x0/0xf4) from [<c00117e4>] (show_stack+0x10/0x14) [ 0.000000] [<c00117e4>] (show_stack+0x10/0x14) from [<c055f734>] (dump_stack+0x9c/0xc8) [ 0.000000] [<c055f734>] (dump_stack+0x9c/0xc8) from [<c03b47d4>] (of_node_release+0x90/0x9c) [ 0.000000] [<c03b47d4>] (of_node_release+0x90/0x9c) from [<c03b5084>] (of_find_matching_node_and_match+0x78/0xb4) [ 0.000000] [<c03b5084>] (of_find_matching_node_and_match+0x78/0xb4) from [<c07887c8>] (clocksource_of_init+0x60/0x70) [ 0.000000] [<c07887c8>] (clocksource_of_init+0x60/0x70) from [<c076e99c>] (start_kernel+0x1f4/0x33c) [ 0.000000] [<c076e99c>] (start_kernel+0x1f4/0x33c) from [<80008074>] (0x80008074)This is caused by
clocksource_of_init()dropping a reference on the device node that it never took. The reference taken by the loop is implicitly dropped on subsequent iterations. See the implementation of and the comment on top of theof_find_matching_node_and_match()function for reference (no pun intended).
Quoted 4 lines
Signed-off-by Thierry Reding <[email protected]>--- drivers/clocksource/clksrc-of.c | 1 - 1 file changed, 1 deletion(-)
Can someone look at this?
Thierry
Quoted 14 lines
drivers/clocksource/clksrc-of.c +0
-1@@ -35,6 +35,5 @@ void __init clocksource_of_init(void) init_func = match->data;init_func (np); -of_node_put (np); } }Signature · 1 line
1.8.4
Daniel Lezcano
Acked-by David BrownQuoted 20 lines · Thierry Reding
Quoted 19 lines · Thierry Reding
When booting a recent kernel on ARM with
OF_DYNAMICenabled, the kernel warns about the following:[ 0.000000] ERROR: Bad of_node_put() on /timer@50004600 [ 0.000000] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 3.12.0-rc5-next-20131017-00077-gedfd827-dirty #406 [ 0.000000] [<c0015b68>] (unwind_backtrace+0x0/0xf4) from [<c00117e4>] (show_stack+0x10/0x14) [ 0.000000] [<c00117e4>] (show_stack+0x10/0x14) from [<c055f734>] (dump_stack+0x9c/0xc8) [ 0.000000] [<c055f734>] (dump_stack+0x9c/0xc8) from [<c03b47d4>] (of_node_release+0x90/0x9c) [ 0.000000] [<c03b47d4>] (of_node_release+0x90/0x9c) from [<c03b5084>] (of_find_matching_node_and_match+0x78/0xb4) [ 0.000000] [<c03b5084>] (of_find_matching_node_and_match+0x78/0xb4) from [<c07887c8>] (clocksource_of_init+0x60/0x70) [ 0.000000] [<c07887c8>] (clocksource_of_init+0x60/0x70) from [<c076e99c>] (start_kernel+0x1f4/0x33c) [ 0.000000] [<c076e99c>] (start_kernel+0x1f4/0x33c) from [<80008074>] (0x80008074)This is caused by
clocksource_of_init()dropping a reference on the device node that it never took. The reference taken by the loop is implicitly dropped on subsequent iterations. See the implementation of and the comment on top of theof_find_matching_node_and_match()function for reference (no pun intended).
Quoted 6 lines
Quoted 4 lines
Signed-off-by Thierry Reding <[email protected]>--- drivers/clocksource/clksrc-of.c | 1 - 1 file changed, 1 deletion(-)Can someone look at this?
Yes. Sounds like I missed it.
This regression has been introduced by:
commit 326e31eebe61dc838e031ea16968b2cfb43443e3
Author: Uwe Kleine-König <[email protected]> Date: Tue Oct 1 11:00:53 2013 +0200
clocksource: Put nodes passed to CLOCKSOURCE_OF_DECLARE callbacks
centrally
Instead of letting each driver call of_node_put do it centrally in the loop that also calls the CLOCKSOURCE_OF_DECLARE callbacks. This is less prone to error and also moves getting and putting the references
into the
same function.
Consequently all respective of_node_put calls in drivers are removed.
Quoted 14 lines
Quoted 14 lines
drivers/clocksource/clksrc-of.c +0
-2@@ -35,6 +35,5 @@ void __init clocksource_of_init(void) init_func = match->data;init_func (np); -of_node_put (np); } } --1.8.4
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Quoted 15 lines · Daniel Lezcano
Quoted 14 lines · Thierry Reding
Quoted 13 lines · Thierry Reding
When booting a recent kernel on ARM with
OF_DYNAMICenabled, the kernel warns about the following:[ 0.000000] ERROR: Bad of_node_put() on /timer@50004600 [ 0.000000] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 3.12.0-rc5-next-20131017-00077-gedfd827-dirty #406 [ 0.000000] [<c0015b68>] (unwind_backtrace+0x0/0xf4) from [<c00117e4>] (show_stack+0x10/0x14) [ 0.000000] [<c00117e4>] (show_stack+0x10/0x14) from [<c055f734>] (dump_stack+0x9c/0xc8) [ 0.000000] [<c055f734>] (dump_stack+0x9c/0xc8) from [<c03b47d4>] (of_node_release+0x90/0x9c) [ 0.000000] [<c03b47d4>] (of_node_release+0x90/0x9c) from [<c03b5084>] (of_find_matching_node_and_match+0x78/0xb4) [ 0.000000] [<c03b5084>] (of_find_matching_node_and_match+0x78/0xb4) from [<c07887c8>] (clocksource_of_init+0x60/0x70) [ 0.000000] [<c07887c8>] (clocksource_of_init+0x60/0x70) from [<c076e99c>] (start_kernel+0x1f4/0x33c) [ 0.000000] [<c076e99c>] (start_kernel+0x1f4/0x33c) from [<80008074>] (0x80008074)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
This is caused by
clocksource_of_init()dropping a reference on the device node that it never took. The reference taken by the loop is implicitly dropped on subsequent iterations. See the implementation of and the comment on top of theof_find_matching_node_and_match()function for reference (no pun intended).
I only saw the end of the comment saying:
Returns a node pointer with refcount incremented, use of_node_put() on it when done.
Maybe that could be improved to something like:
/**
* of_find_matching_node_and_match - Find a node based on an of_device_id
* match table
* @from: The node to start searching from or NULL, the node you pass
* will not be searched, only the next one will; typically, you
* pass what the previous call returned.
* @matches: ...
* @match: ...
*
* Reference counting: Puts a reference on @from and increases the
* reference count of the returned node.
*/
Quoted 25 lines
Quoted 7 lines
Quoted 5 lines
Signed-off-by Thierry Reding <[email protected]>--- drivers/clocksource/clksrc-of.c | 1 - 1 file changed, 1 deletion(-)Can someone look at this?
Yes. Sounds like I missed it.
This regression has been introduced by:
commit
326e31eebe61dc838e031ea16968b2cfb43443e3Author: Uwe Kleine-König <[email protected]> Date: Tue Oct 1 11:00:53 2013 +0200clocksource: Put nodes passed to
CLOCKSOURCE_OF_DECLARE
callbacks centrallyInstead of letting each driver call
of_node_putdo it centrally in the loop that also calls theCLOCKSOURCE_OF_DECLAREcallbacks. This is less prone to error and also moves getting and putting the references
into the
same function.
Quoted 5 lines
Consequently all respective
of_node_putcalls in drivers are removed.Signed-off-by Uwe Kleine-König <[email protected]>Signed-off-by Daniel Lezcano <[email protected]>Acked-by David Brown <[email protected]>
Still all but the hook in clocksource_of_init of this commit was correct, right? (Well, but this buggy hunk makes the commit log wrong.)
Best regards
Uwe
Signature · 6 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ | -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 66 lines · Uwe Kleine-König
Quoted 15 lines · Daniel Lezcano
Quoted 14 lines · Thierry Reding
Quoted 13 lines · Thierry Reding
When booting a recent kernel on ARM with
OF_DYNAMICenabled, the kernel warns about the following:[ 0.000000] ERROR: Bad of_node_put() on /timer@50004600 [ 0.000000] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 3.12.0-rc5-next-20131017-00077-gedfd827-dirty #406 [ 0.000000] [<c0015b68>] (unwind_backtrace+0x0/0xf4) from [<c00117e4>] (show_stack+0x10/0x14) [ 0.000000] [<c00117e4>] (show_stack+0x10/0x14) from [<c055f734>] (dump_stack+0x9c/0xc8) [ 0.000000] [<c055f734>] (dump_stack+0x9c/0xc8) from [<c03b47d4>] (of_node_release+0x90/0x9c) [ 0.000000] [<c03b47d4>] (of_node_release+0x90/0x9c) from [<c03b5084>] (of_find_matching_node_and_match+0x78/0xb4) [ 0.000000] [<c03b5084>] (of_find_matching_node_and_match+0x78/0xb4) from [<c07887c8>] (clocksource_of_init+0x60/0x70) [ 0.000000] [<c07887c8>] (clocksource_of_init+0x60/0x70) from [<c076e99c>] (start_kernel+0x1f4/0x33c) [ 0.000000] [<c076e99c>] (start_kernel+0x1f4/0x33c) from [<80008074>] (0x80008074)Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
This is caused by
clocksource_of_init()dropping a reference on the device node that it never took. The reference taken by the loop is implicitly dropped on subsequent iterations. See the implementation of and the comment on top of theof_find_matching_node_and_match()function for reference (no pun intended).I only saw the end of the comment saying:
Returns a node pointer with refcount incremented, use
of_node_put()on it when done.Maybe that could be improved to something like:
/**
*of_find_matching_node_and_match- Find a node based on anof_device_id
* match table
* @from: The node to start searching from or NULL, the node you pass
* will not be searched, only the next one will; typically, you
* pass what the previous call returned.
* @matches: ...
* @match: ...
*
* Reference counting: Puts a reference on @from and increases the
* reference count of the returned node.
*/Quoted 25 lines
Quoted 7 lines
Quoted 5 lines
Signed-off-by Thierry Reding <[email protected]>--- drivers/clocksource/clksrc-of.c | 1 - 1 file changed, 1 deletion(-)Can someone look at this?
Yes. Sounds like I missed it.
This regression has been introduced by:
commit
326e31eebe61dc838e031ea16968b2cfb43443e3Author: Uwe Kleine-König <[email protected]> Date: Tue Oct 1 11:00:53 2013 +0200clocksource: Put nodes passed to
CLOCKSOURCE_OF_DECLARE
callbacks centrallyInstead of letting each driver call
of_node_putdo it centrally in the loop that also calls theCLOCKSOURCE_OF_DECLAREcallbacks. This is less prone to error and also moves getting and putting the references
into the
same function.
Quoted 7 lines
Quoted 5 lines
Consequently all respective
of_node_putcalls in drivers are removed.Signed-off-by Uwe Kleine-König <[email protected]>Signed-off-by Daniel Lezcano <[email protected]>Acked-by David Brown <[email protected]>Still all but the hook in
clocksource_of_initof this commit was correct, right? (Well, but this buggy hunk makes the commit log wrong.)
I don't understand your comment, can you elaborate ?
Thanks
-- Daniel
Signature · 10 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hello Daniel,
Quoted 23 lines · Daniel Lezcano
Quoted 22 lines · Uwe Kleine-König
Quoted 21 lines · Daniel Lezcano
Quoted 1 line · Thierry Reding
On Sat, Oct 19, 2013 at 12:49:48AM +0200, Thierry Reding wrote:
Yes. Sounds like I missed it.
This regression has been introduced by:
commit
326e31eebe61dc838e031ea16968b2cfb43443e3Author: Uwe Kleine-König <[email protected]> Date: Tue Oct 1 11:00:53 2013 +0200clocksource: Put nodes passed to
CLOCKSOURCE_OF_DECLARE
callbacks centrallyInstead of letting each driver call
of_node_putdo it centrally in the loop that also calls theCLOCKSOURCE_OF_DECLAREcallbacks. This is less prone to error and also moves getting and putting the references
into the
same function.Consequently all respective
of_node_putcalls in drivers are removed.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Signed-off-by Uwe Kleine-König <[email protected]>Signed-off-by Daniel Lezcano <[email protected]>Acked-by David Brown <[email protected]>Still all but the hook in
clocksource_of_initof this commit was correct, right? (Well, but this buggy hunk makes the commit log wrong.)I don't understand your comment, can you elaborate ?
My patch added an of_node_put in clocksource_of_init and dropped several of_node_puts in drivers. This thread is about the first being wrong. My question was if dropping the others was correct.
Best regards
Uwe
Signature · 6 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ | -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 29 lines · Uwe Kleine-König
Hello Daniel,
Quoted 26 lines · Daniel Lezcano
Quoted 25 lines · Uwe Kleine-König
Quoted 24 lines · Daniel Lezcano
Quoted 1 line · Thierry Reding
On Sat, Oct 19, 2013 at 12:49:48AM +0200, Thierry Reding wrote:
Yes. Sounds like I missed it.
This regression has been introduced by:
commit
326e31eebe61dc838e031ea16968b2cfb43443e3Author: Uwe Kleine-König <[email protected]> Date: Tue Oct 1 11:00:53 2013 +0200clocksource: Put nodes passed to
CLOCKSOURCE_OF_DECLARE
callbacks centrallyInstead of letting each driver call
of_node_putdo it centrally in the loop that also calls theCLOCKSOURCE_OF_DECLAREcallbacks. This is less prone to error and also moves getting and putting the references
into the
same function.Consequently all respective
of_node_putcalls in drivers are removed.Signed-off-by Uwe Kleine-König <[email protected]>Signed-off-by Daniel Lezcano <[email protected]>Acked-by David Brown <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Still all but the hook in
clocksource_of_initof this commit was correct, right? (Well, but this buggy hunk makes the commit log wrong.)I don't understand your comment, can you elaborate ?
My patch added an
of_node_putinclocksource_of_initand dropped severalof_node_putsin drivers. This thread is about the first being wrong. My question was if dropping the others was correct.
Yes, Thierry's patch removes the of_node_puts but I am also wondering if we shouldn't just revert the patch 326e31eebe61dc838e instead.
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Quoted 33 lines · Daniel Lezcano
Quoted 32 lines · Uwe Kleine-König
Hello Daniel,
Quoted 29 lines · Daniel Lezcano
Quoted 27 lines · Uwe Kleine-König
Quoted 19 lines · Daniel Lezcano
Quoted 1 line · Thierry Reding
On Sat, Oct 19, 2013 at 12:49:48AM +0200, Thierry Reding wrote:
Yes. Sounds like I missed it.
This regression has been introduced by:
commit
326e31eebe61dc838e031ea16968b2cfb43443e3Author: Uwe Kleine-König <[email protected]> Date: Tue Oct 1 11:00:53 2013 +0200clocksource: Put nodes passed to
CLOCKSOURCE_OF_DECLARE
callbacks centrallyInstead of letting each driver call
of_node_putdo it centrally in the loop that also calls theCLOCKSOURCE_OF_DECLAREcallbacks. This is less prone to error and also moves getting and putting the references
into the
same function.Quoted 5 lines
Consequently all respective
of_node_putcalls in drivers are removed.Signed-off-by Uwe Kleine-König <[email protected]>Signed-off-by Daniel Lezcano <[email protected]>Acked-by David Brown <[email protected]>Still all but the hook in
clocksource_of_initof this commit was correct, right? (Well, but this buggy hunk makes the commit log wrong.)
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
I don't understand your comment, can you elaborate ?
My patch added an
of_node_putinclocksource_of_initand dropped severalof_node_putsin drivers. This thread is about the first being wrong. My question was if dropping the others was correct.Yes, Thierry's patch removes the
of_node_putsbut I am also wondering if we shouldn't just revert the patch326e31eebe61dc838einstead.
I don't think that's necessary. Dropping the other of_node_put()s looks like the right thing to do. They drop a reference that they haven't taken themselves, which is usually not correct. I can't find anything wrong with the rest of that commit.
Thierry
Quoted 29 lines · Uwe Kleine-König
Hello Daniel,
Quoted 26 lines · Daniel Lezcano
Quoted 25 lines · Uwe Kleine-König
Quoted 24 lines · Daniel Lezcano
Quoted 1 line · Thierry Reding
On Sat, Oct 19, 2013 at 12:49:48AM +0200, Thierry Reding wrote:
Yes. Sounds like I missed it.
This regression has been introduced by:
commit
326e31eebe61dc838e031ea16968b2cfb43443e3Author: Uwe Kleine-König <[email protected]> Date: Tue Oct 1 11:00:53 2013 +0200clocksource: Put nodes passed to
CLOCKSOURCE_OF_DECLARE
callbacks centrallyInstead of letting each driver call
of_node_putdo it centrally in the loop that also calls theCLOCKSOURCE_OF_DECLAREcallbacks. This is less prone to error and also moves getting and putting the references
into the
same function.Consequently all respective
of_node_putcalls in drivers are removed.Signed-off-by Uwe Kleine-König <[email protected]>Signed-off-by Daniel Lezcano <[email protected]>Acked-by David Brown <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Still all but the hook in
clocksource_of_initof this commit was correct, right? (Well, but this buggy hunk makes the commit log wrong.)I don't understand your comment, can you elaborate ?
My patch added an
of_node_putinclocksource_of_initand dropped severalof_node_putsin drivers. This thread is about the first being wrong. My question was if dropping the others was correct.
Yes, it looks to me like the others were correct. A reference on np is taken by the for_each_matching_node_and_match() in clocksource_of_init() and released when through the loop, or rather on the next iteration. So it would be an error to release the reference within the driver-specific initializations, since they don't take a reference of their own.
Thierry
Daniel Lezcano
AppliedQuoted 29 lines · Thierry Reding
When booting a recent kernel on ARM with
OF_DYNAMICenabled, the kernel warns about the following:[ 0.000000] ERROR: Bad of_node_put() on /timer@50004600 [ 0.000000] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 3.12.0-rc5-next-20131017-00077-gedfd827-dirty #406 [ 0.000000] [<c0015b68>] (unwind_backtrace+0x0/0xf4) from [<c00117e4>] (show_stack+0x10/0x14) [ 0.000000] [<c00117e4>] (show_stack+0x10/0x14) from [<c055f734>] (dump_stack+0x9c/0xc8) [ 0.000000] [<c055f734>] (dump_stack+0x9c/0xc8) from [<c03b47d4>] (of_node_release+0x90/0x9c) [ 0.000000] [<c03b47d4>] (of_node_release+0x90/0x9c) from [<c03b5084>] (of_find_matching_node_and_match+0x78/0xb4) [ 0.000000] [<c03b5084>] (of_find_matching_node_and_match+0x78/0xb4) from [<c07887c8>] (clocksource_of_init+0x60/0x70) [ 0.000000] [<c07887c8>] (clocksource_of_init+0x60/0x70) from [<c076e99c>] (start_kernel+0x1f4/0x33c) [ 0.000000] [<c076e99c>] (start_kernel+0x1f4/0x33c) from [<80008074>] (0x80008074)This is caused by
clocksource_of_init()dropping a reference on the device node that it never took. The reference taken by the loop is implicitly dropped on subsequent iterations. See the implementation of and the comment on top of theof_find_matching_node_and_match()function for reference (no pun intended).Signed-off-by Thierry Reding <[email protected]>--- drivers/clocksource/clksrc-of.c | 1 - 1 file changed, 1 deletion(-)drivers/clocksource/clksrc-of.c +0
-0
drivers/clocksource/clksrc-of.c void __init clocksource_of_init(void) · line 39
Quoted 6 lines
drivers/clocksource/clksrc-of.c +0
-1@@ -35,6 +35,5 @@ void __init clocksource_of_init(void) init_func = match->data;init_func (np); -of_node_put (np); } }
Applied to my tree for 3.13 fixes.
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog