diff options
author | Guenter Roeck <linux@roeck-us.net> | 2017-03-04 10:02:10 -0500 |
---|---|---|
committer | Tony Lindgren <tony@atomide.com> | 2017-03-04 11:27:46 -0500 |
commit | 10e5778f54765c96fe0c8f104b7a030e5b35bc72 (patch) | |
tree | 23207e3be7ebd440f1be9a7b479c02641ca04bc2 | |
parent | ac28e47ccc3ff8dabce1aec6b224760c3e524044 (diff) |
ARM: OMAP2+: Fix device node reference counts
After commit 0549bde0fcb1 ("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@68000000
CPU: 0 PID: 0 Comm: swapper Not tainted 4.10.0-rc7-next-20170210 #1
Hardware name: Generic OMAP3-GP (Flattened Device Tree)
[<c0310604>] (unwind_backtrace) from [<c030bbf4>] (show_stack+0x10/0x14)
[<c030bbf4>] (show_stack) from [<c05add8c>] (dump_stack+0x98/0xac)
[<c05add8c>] (dump_stack) from [<c05af1b0>] (kobject_release+0x48/0x7c)
[<c05af1b0>] (kobject_release)
from [<c0ad1aa4>] (of_find_node_by_name+0x74/0x94)
[<c0ad1aa4>] (of_find_node_by_name)
from [<c1215bd4>] (omap3xxx_hwmod_is_hs_ip_block_usable+0x24/0x2c)
[<c1215bd4>] (omap3xxx_hwmod_is_hs_ip_block_usable) from
[<c1215d5c>] (omap3xxx_hwmod_init+0x180/0x274)
[<c1215d5c>] (omap3xxx_hwmod_init)
from [<c120faa8>] (omap3_init_early+0xa0/0x11c)
[<c120faa8>] (omap3_init_early)
from [<c120fb2c>] (omap3430_init_early+0x8/0x30)
[<c120fb2c>] (omap3430_init_early)
from [<c1204710>] (setup_arch+0xc04/0xc34)
[<c1204710>] (setup_arch) from [<c1200948>] (start_kernel+0x68/0x38c)
[<c1200948>] (start_kernel) from [<8020807c>] (0x8020807c)
of_find_node_by_name() drops the reference to the passed device node.
The commit referenced above exposes this problem.
To fix the problem, use of_get_child_by_name() instead of
of_find_node_by_name(); of_get_child_by_name() does not drop
the reference count of passed device nodes. While semantically
different, we only look for immediate children of the passed
device node, so of_get_child_by_name() is a more appropriate
function to use anyway.
Release the reference to the device node obtained with
of_get_child_by_name() after it is no longer needed to avoid
another device node leak.
While at it, clean up the code and change the return type of
omap3xxx_hwmod_is_hs_ip_block_usable() to bool to match its use
and the return type of of_device_is_available().
Cc: Qi Hou <qi.hou@windriver.com>
Cc: Peter Rosin <peda@axentia.se>
Cc: Rob Herring <robh@kernel.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Tony Lindgren <tony@atomide.com>
-rw-r--r-- | arch/arm/mach-omap2/omap_hwmod_3xxx_data.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c index 507ff0795a8e..0fa08c1e4701 100644 --- a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c +++ b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c | |||
@@ -3131,16 +3131,20 @@ static struct omap_hwmod_ocp_if *omap3xxx_dss_hwmod_ocp_ifs[] __initdata = { | |||
3131 | * Return: 0 if device named @dev_name is not likely to be accessible, | 3131 | * Return: 0 if device named @dev_name is not likely to be accessible, |
3132 | * or 1 if it is likely to be accessible. | 3132 | * or 1 if it is likely to be accessible. |
3133 | */ | 3133 | */ |
3134 | static int __init omap3xxx_hwmod_is_hs_ip_block_usable(struct device_node *bus, | 3134 | static bool __init omap3xxx_hwmod_is_hs_ip_block_usable(struct device_node *bus, |
3135 | const char *dev_name) | 3135 | const char *dev_name) |
3136 | { | 3136 | { |
3137 | struct device_node *node; | ||
3138 | bool available; | ||
3139 | |||
3137 | if (!bus) | 3140 | if (!bus) |
3138 | return (omap_type() == OMAP2_DEVICE_TYPE_GP) ? 1 : 0; | 3141 | return omap_type() == OMAP2_DEVICE_TYPE_GP; |
3139 | 3142 | ||
3140 | if (of_device_is_available(of_find_node_by_name(bus, dev_name))) | 3143 | node = of_get_child_by_name(bus, dev_name); |
3141 | return 1; | 3144 | available = of_device_is_available(node); |
3145 | of_node_put(node); | ||
3142 | 3146 | ||
3143 | return 0; | 3147 | return available; |
3144 | } | 3148 | } |
3145 | 3149 | ||
3146 | int __init omap3xxx_hwmod_init(void) | 3150 | int __init omap3xxx_hwmod_init(void) |