mips/kernel: Add missing of_node_get()
PATCH 1/1 mips/kernel: Add missing of_node_get()
In mips_cpc_default_phys_base(), we need to add of_node_get() before of_find_compatible_node() which will decrease the refcount of its first arg.
--- arch/mips/kernel/mips-cpc.c | 1 + 1 file changed, 1 insertion(+)
arch/mips/kernel/mips-cpc.c +1 -0
@@ -25,6 +25,7 @@ phys_addr_t __weak mips_cpc_default_phys_base(void)struct resource res;int err; +of_node_get (of_root); cpc_node =of_find_compatible_node (of_root,NULL ,"mti,mips-cpc" );if (cpc_node) { err =of_address_to_resource (cpc_node,0 , &res);
Signature · 1 line
2.25.1
Hi Liang,
CC devicetree
Quoted 5 lines · Liang He
In
mips_cpc_default_phys_base(), we need to addof_node_get()beforeof_find_compatible_node()which will decrease the refcount of its first arg.Signed-off-by Liang He <[email protected]>
Thanks for your patch!
arch/mips/kernel/mips-cpc.c phys_addr_t __weak mips_cpc_default_phys_base(void) · line 28
Quoted 7 lines
arch/mips/kernel/mips-cpc.c +1
-0@@ -25,6 +25,7 @@ phys_addr_t __weak mips_cpc_default_phys_base(void)struct resource res;int err; +of_node_get (of_root);
Adding this looks strange to me...
However, of_find_compatible_node() indeed calls of_node_put(from), so your patch is correct.
However, when passed NULL as the from pointer, __of_find_all_nodes() (expanded from for_each_of_allnodes_from()) turns this into of_root. As of_find_compatible_node() still has the original (NULL) from pointer, of_node_put(from) becomes a no-op.
arch/mips/kernel/mips-cpc.c phys_addr_t __weak mips_cpc_default_phys_base(void) · line 29
Quoted 1 line
arch/mips/kernel/mips-cpc.c +0
-0cpc_node =of_find_compatible_node (of_root,NULL ,"mti,mips-cpc" );
Hence I think it would be better to change the above to
cpc_node = of_find_compatible_node(NULL, NULL, "mti,mips-cpc");
instead, i.e. get rid of the explicit of_root handling?
arch/mips/kernel/mips-cpc.c phys_addr_t __weak mips_cpc_default_phys_base(void) · line 31
Quoted 2 lines
arch/mips/kernel/mips-cpc.c +0
-0if (cpc_node) { err =of_address_to_resource (cpc_node,0 , &res);
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 19 lines · Geert Uytterhoeven
Hi Liang,
CC devicetree
Quoted 5 lines · Liang He
In
mips_cpc_default_phys_base(), we need to addof_node_get()beforeof_find_compatible_node()which will decrease the refcount of its first arg.Signed-off-by Liang He <[email protected]>Thanks for your patch!
Quoted 6 lines
arch/mips/kernel/mips-cpc.c +0
-0@@ -25,6 +25,7 @@ phys_addr_t __weak mips_cpc_default_phys_base(void)struct resource res;int err;
Quoted 4 lines
arch/mips/kernel/mips-cpc.c phys_addr_t __weak mips_cpc_default_phys_base(void) · line 28
Quoted 1 line
arch/mips/kernel/mips-cpc.c +1
-0+of_node_get (of_root);Adding this looks strange to me...
Hi, this is also strange to me.
In fact, I also don't like add a special of_node_get() before I call of_find_xx() each time.
In fact, I have learned this error-pattern based on the following bug-fix:
https://lore.kernel.org/all/[email protected]/
Quoted 3 lines
However,
of_find_compatible_node()indeed callsof_node_put(from), so your patch is correct.
Thanks.
Quoted 5 lines
However, when passed NULL as the from pointer,
__of_find_all_nodes()(expanded fromfor_each_of_allnodes_from()) turns this intoof_root. Asof_find_compatible_node()still has the original (NULL) from pointer,of_node_put(from)becomes a no-op.
Quoted 11 lines
arch/mips/kernel/mips-cpc.c phys_addr_t __weak mips_cpc_default_phys_base(void) · line 29
Quoted 1 line
arch/mips/kernel/mips-cpc.c +0
-0cpc_node =of_find_compatible_node (of_root,NULL ,"mti,mips-cpc" );Hence I think it would be better to change the above to
cpc_node = of_find_compatible_node(NULL, NULL, "mti,mips-cpc");instead, i.e. get rid of the explicit
of_roothandling?Quoted 2 lines
arch/mips/kernel/mips-cpc.c +0
-0if (cpc_node) { err =of_address_to_resource (cpc_node,0 , &res);
Sorry, Geert.
As I don't know anyother details of the code except the error-pattern code, I cannot do anyother (more efficient) changes.
If it is a bug, please fix it in your professional way if my patch is not so well.
Thanks.
Liang.
Quoted 10 lines
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds