From mboxrd@z Thu Jan 1 00:00:00 1970 From: linux@roeck-us.net (Guenter Roeck) Date: Mon, 27 Feb 2017 15:34:05 -0800 Subject: ARM: OMAP2+: Grab reference to device nodes where needed In-Reply-To: <1486853948-20978-1-git-send-email-linux@roeck-us.net> References: <1486853948-20978-1-git-send-email-linux@roeck-us.net> Message-ID: <20170227233405.GA16546@roeck-us.net> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org ping ... this problem is now seen in mainline. Guenter On Sat, Feb 11, 2017 at 02:59:08PM -0800, Guenter Roeck wrote: > After commit 'of: fix of_node leak caused in of_find_node_opts_by_path', > the following error may be reported when running omap images. > > OF: ERROR: Bad of_node_put() on /ocp at 68000000 > CPU: 0 PID: 0 Comm: swapper Not tainted 4.10.0-rc7-next-20170210 #1 > Hardware name: Generic OMAP3-GP (Flattened Device Tree) > [] (unwind_backtrace) from [] (show_stack+0x10/0x14) > [] (show_stack) from [] (dump_stack+0x98/0xac) > [] (dump_stack) from [] (kobject_release+0x48/0x7c) > [] (kobject_release) > from [] (of_find_node_by_name+0x74/0x94) > [] (of_find_node_by_name) > from [] (omap3xxx_hwmod_is_hs_ip_block_usable+0x24/0x2c) > [] (omap3xxx_hwmod_is_hs_ip_block_usable) from > [] (omap3xxx_hwmod_init+0x180/0x274) > [] (omap3xxx_hwmod_init) > from [] (omap3_init_early+0xa0/0x11c) > [] (omap3_init_early) > from [] (omap3430_init_early+0x8/0x30) > [] (omap3430_init_early) > from [] (setup_arch+0xc04/0xc34) > [] (setup_arch) from [] (start_kernel+0x68/0x38c) > [] (start_kernel) from [<8020807c>] (0x8020807c) > > of_find_node_by_name() drops the reference to the passed device node, > so it is necessary to grab an extra one if it is still needed after the > call. > > Cc: Qi Hou > Cc: Peter Rosin > Cc: Rob Herring > Signed-off-by: Guenter Roeck > --- > arch/arm/mach-omap2/omap_hwmod_3xxx_data.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c > index 56f917ec8621..d4ca1e3964c3 100644 > --- a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c > +++ b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c > @@ -3117,6 +3117,7 @@ static int __init omap3xxx_hwmod_is_hs_ip_block_usable(struct device_node *bus, > if (!bus) > return (omap_type() == OMAP2_DEVICE_TYPE_GP) ? 1 : 0; > > + of_node_get(bus); > if (of_device_is_available(of_find_node_by_name(bus, dev_name))) > return 1; > > @@ -3189,15 +3190,20 @@ int __init omap3xxx_hwmod_init(void) > > if (h_sham && omap3xxx_hwmod_is_hs_ip_block_usable(bus, "sham")) { > r = omap_hwmod_register_links(h_sham); > - if (r < 0) > + if (r < 0) { > + of_node_put(bus); > return r; > + } > } > > if (h_aes && omap3xxx_hwmod_is_hs_ip_block_usable(bus, "aes")) { > r = omap_hwmod_register_links(h_aes); > - if (r < 0) > + if (r < 0) { > + of_node_put(bus); > return r; > + } > } > + of_node_put(bus); > > /* > * Register hwmod links specific to certain ES levels of a