linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: ti: Fix reference imbalance in ti_find_clock_provider
@ 2022-08-08 22:26 Jan Kiszka
  2022-08-19 21:23 ` Stephen Boyd
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Kiszka @ 2022-08-08 22:26 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd; +Cc: linux-omap, linux-clk, linux-kernel

From: Jan Kiszka <jan.kiszka@siemens.com>

When a clock is found via clock-output-names, we need to reference it
explicitly to match of_find_node_by_name behavior. Failing to do so
causes warnings like this:

------------[ cut here ]------------
WARNING: CPU: 0 PID: 0 at lib/refcount.c:25 kobject_get+0x9c/0xa0
refcount_t: addition on 0; use-after-free.
Modules linked in:
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.19.0+ #37
Hardware name: Generic AM33XX (Flattened Device Tree)
 unwind_backtrace from show_stack+0x10/0x14
 show_stack from dump_stack_lvl+0x40/0x4c
 dump_stack_lvl from __warn+0xc8/0x13c
 __warn from warn_slowpath_fmt+0x78/0xa8
 warn_slowpath_fmt from kobject_get+0x9c/0xa0
 kobject_get from of_node_get+0x14/0x1c
 of_node_get from of_fwnode_get+0x34/0x40
 of_fwnode_get from fwnode_full_name_string+0x34/0xa0
 fwnode_full_name_string from device_node_string+0x604/0x6d0
 device_node_string from pointer+0x38c/0x5b0
 pointer from vsnprintf+0x230/0x3cc
 vsnprintf from vprintk_store+0x10c/0x3fc
 vprintk_store from vprintk_emit+0x70/0x240
 vprintk_emit from vprintk_default+0x20/0x28
 vprintk_default from _printk+0x2c/0x5c
 _printk from of_node_release+0x11c/0x124
 of_node_release from kobject_put+0x98/0x104
 kobject_put from ti_dt_clocks_register+0x2d8/0x3a8
 ti_dt_clocks_register from am33xx_dt_clk_init+0x14/0xa4
 am33xx_dt_clk_init from omap_init_time_of+0x8/0x10
 omap_init_time_of from start_kernel+0x4f8/0x6b0
 start_kernel from 0x0
---[ end trace 0000000000000000 ]---

Fixes: 51f661ef9a10 ("clk: ti: Add ti_find_clock_provider() to use clock-output-names")
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

Tested against 5.19 as at least current Linus master does not boot on 
the BeagleBone Black.

 drivers/clk/ti/clk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/ti/clk.c b/drivers/clk/ti/clk.c
index ef2a445c63a3..5261642974df 100644
--- a/drivers/clk/ti/clk.c
+++ b/drivers/clk/ti/clk.c
@@ -142,8 +142,10 @@ static struct device_node *ti_find_clock_provider(struct device_node *from,
 	of_node_put(from);
 	kfree(tmp);
 
-	if (found)
+	if (found) {
+		of_node_get(np);
 		return np;
+	}
 
 	/* Fall back to using old node name base provider name */
 	return of_find_node_by_name(from, name);
-- 
2.35.3

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

* Re: [PATCH] clk: ti: Fix reference imbalance in ti_find_clock_provider
  2022-08-08 22:26 [PATCH] clk: ti: Fix reference imbalance in ti_find_clock_provider Jan Kiszka
@ 2022-08-19 21:23 ` Stephen Boyd
  2022-08-23  9:29   ` Romain Naour
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Boyd @ 2022-08-19 21:23 UTC (permalink / raw)
  To: Jan Kiszka, Michael Turquette
  Cc: linux-omap, linux-clk, linux-kernel, Tony Lindgren

Quoting Jan Kiszka (2022-08-08 15:26:58)
> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> When a clock is found via clock-output-names, we need to reference it
> explicitly to match of_find_node_by_name behavior. Failing to do so
> causes warnings like this:
> 

Is this superseeded by
https://lore.kernel.org/r/20220621091118.33930-1-tony@atomide.com?

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

* Re: [PATCH] clk: ti: Fix reference imbalance in ti_find_clock_provider
  2022-08-19 21:23 ` Stephen Boyd
@ 2022-08-23  9:29   ` Romain Naour
  2022-08-23 11:52     ` Tony Lindgren
  0 siblings, 1 reply; 4+ messages in thread
From: Romain Naour @ 2022-08-23  9:29 UTC (permalink / raw)
  To: Stephen Boyd, Jan Kiszka, Michael Turquette
  Cc: linux-omap, linux-clk, linux-kernel, Tony Lindgren

Hello,

Le 19/08/2022 à 23:23, Stephen Boyd a écrit :
> Quoting Jan Kiszka (2022-08-08 15:26:58)
>> From: Jan Kiszka <jan.kiszka@siemens.com>
>>
>> When a clock is found via clock-output-names, we need to reference it
>> explicitly to match of_find_node_by_name behavior. Failing to do so
>> causes warnings like this:
>>
> 
> Is this superseeded by
> https://lore.kernel.org/r/20220621091118.33930-1-tony@atomide.com?

I noticed the same issue and tested separately with both patches.

Indeed, this patch is not needed anymore with "[PATCH] clk: ti: Fix missing
of_node_get() ti_find_clock_provider()" applied.

Best regards,
Romain

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

* Re: [PATCH] clk: ti: Fix reference imbalance in ti_find_clock_provider
  2022-08-23  9:29   ` Romain Naour
@ 2022-08-23 11:52     ` Tony Lindgren
  0 siblings, 0 replies; 4+ messages in thread
From: Tony Lindgren @ 2022-08-23 11:52 UTC (permalink / raw)
  To: Romain Naour
  Cc: Stephen Boyd, Jan Kiszka, Michael Turquette, linux-omap,
	linux-clk, linux-kernel

* Romain Naour <romain.naour@smile.fr> [220823 09:22]:
> Hello,
> 
> Le 19/08/2022 à 23:23, Stephen Boyd a écrit :
> > Quoting Jan Kiszka (2022-08-08 15:26:58)
> >> From: Jan Kiszka <jan.kiszka@siemens.com>
> >>
> >> When a clock is found via clock-output-names, we need to reference it
> >> explicitly to match of_find_node_by_name behavior. Failing to do so
> >> causes warnings like this:
> >>
> > 
> > Is this superseeded by
> > https://lore.kernel.org/r/20220621091118.33930-1-tony@atomide.com?
> 
> I noticed the same issue and tested separately with both patches.
> 
> Indeed, this patch is not needed anymore with "[PATCH] clk: ti: Fix missing
> of_node_get() ti_find_clock_provider()" applied.

OK good to hear and thanks for testing.

Regards,

Tony

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

end of thread, other threads:[~2022-08-23 16:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-08 22:26 [PATCH] clk: ti: Fix reference imbalance in ti_find_clock_provider Jan Kiszka
2022-08-19 21:23 ` Stephen Boyd
2022-08-23  9:29   ` Romain Naour
2022-08-23 11:52     ` Tony Lindgren

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).