powerpc/powermac: Fix reference count leak in i2c probe functions
Subsystems (3)
PATCH 1/1 powerpc/powermac: Fix reference count leak in i2c probe functions
The of_find_node_by_name() function returns a device tree node with its reference count incremented. The caller is responsible for calling of_node_put() to release this reference when done.
--- arch/powerpc/platforms/powermac/low_i2c.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/platforms/powermac/low_i2c.c +4 -1
@@ -802,8 +802,10 @@ static void __init pmu_i2c_probe(void)for (channel =1 ; channel <=2 ; channel++) { sz =sizeof (struct pmac_i2c_bus ) +sizeof (struct adb_request ); bus =kzalloc (sz,GFP_KERNEL ); -if (bus ==NULL ) +if (bus ==NULL ) { +of_node_put (busnode);return ; + } bus->controller = busnode; bus->busnode = busnode;
@@ -928,6 +930,7 @@ static void __init smu_i2c_probe(void) bus =kzalloc (sz,GFP_KERNEL );if (bus ==NULL ) {of_node_put (busnode); +of_node_put (controller);return ; }
Signature · 1 line
2.39.5 (Apple Git-154)
Christophe Leroy
reviewerLe 27/10/2025 à 09:45, Miaoqian Lin a écrit :
Quoted 18 lines
[Vous ne recevez pas souvent de courriers de [email protected]. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]
The
of_find_node_by_name()function returns a device tree node with its reference count incremented. The caller is responsible for callingof_node_put()to release this reference when done.Fixes 730745a5c450 ("[PATCH] 1/5 powerpc: Rework PowerMac i2c part 1")Signed-off-by Miaoqian Lin <[email protected]>--- arch/powerpc/platforms/powermac/low_i2c.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)arch/powerpc/platforms/powermac/low_i2c.c +0
-0
arch/powerpc/platforms/powermac/low_i2c.c static void __init pmu_i2c_probe(void) · line 806
Quoted 6 lines
arch/powerpc/platforms/powermac/low_i2c.c +2
-1@@ -802,8 +802,10 @@ static void __init pmu_i2c_probe(void)for (channel =1 ; channel <=2 ; channel++) { sz =sizeof (struct pmac_i2c_bus ) +sizeof (struct adb_request ); bus =kzalloc (sz,GFP_KERNEL ); -if (bus ==NULL ) +if (bus ==NULL ) { +of_node_put (busnode);
We are in a loop, what happens when kzalloc() succeded in the first iteration but not in a further iteration ? In that case we have already registered some bus which references busnode as bus->busnode so it just can't but put.
Quoted 16 lines
arch/powerpc/platforms/powermac/low_i2c.c +2
-1return ; + } bus->controller = busnode; bus->busnode = busnode;@@ -928,6 +930,7 @@ static void __init smu_i2c_probe(void) bus =kzalloc (sz,GFP_KERNEL );if (bus ==NULL ) {of_node_put (busnode); +of_node_put (controller);return ; } --2.39.5 (Apple Git-154)
Signature · 1 line
pw-bot: cr