[PATCH] i2c: Fix reference leak in of_i2c_register_devices

Sunny Patel posted 1 patch 8 months, 1 week ago
drivers/i2c/i2c-core-of.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] i2c: Fix reference leak in of_i2c_register_devices
Posted by Sunny Patel 8 months, 1 week ago
Fix a potential reference leak in of_i2c_register_devices where the
reference to the node is not released if device registration fails.
This ensures proper reference management and avoids memory leaks.

Signed-off-by: Sunny Patel <nueralspacetech@gmail.com>
---
 drivers/i2c/i2c-core-of.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
index 02feee6c9ba9..7c50905de8f1 100644
--- a/drivers/i2c/i2c-core-of.c
+++ b/drivers/i2c/i2c-core-of.c
@@ -107,6 +107,7 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
 				 "Failed to create I2C device for %pOF\n",
 				 node);
 			of_node_clear_flag(node, OF_POPULATED);
+			of_node_put(node);
 		}
 	}
 
-- 
2.43.0
Re: [PATCH] i2c: Fix reference leak in of_i2c_register_devices
Posted by Christophe JAILLET 8 months ago
Le 14/04/2025 à 17:42, Sunny Patel a écrit :
> Fix a potential reference leak in of_i2c_register_devices where the
> reference to the node is not released if device registration fails.
> This ensures proper reference management and avoids memory leaks.
> 
> Signed-off-by: Sunny Patel <nueralspacetech@gmail.com>
> ---
>   drivers/i2c/i2c-core-of.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
> index 02feee6c9ba9..7c50905de8f1 100644
> --- a/drivers/i2c/i2c-core-of.c
> +++ b/drivers/i2c/i2c-core-of.c
> @@ -107,6 +107,7 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
>   				 "Failed to create I2C device for %pOF\n",
>   				 node);
>   			of_node_clear_flag(node, OF_POPULATED);
> +			of_node_put(node);
>   		}
>   	}
>   

Hi,

Why resending this patch?
it is the same has before,, so my understanding is still the same and I 
still think that it is just wrong.

See [1].

CJ

[1]: 
https://lore.kernel.org/all/1dacfce7-c66d-44c6-9a0c-2dd00bc24ffc@wanadoo.fr/