Skip to contentSkip to conversation

misc:ti_fpc202:fix a potential memory leak in probe function

PATCH Superseded Felix Gu 2 participants 3 messages Dec 25, 2025 – Dec 26, 2025

Subsystems (2)
lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH 1/1 misc:ti_fpc202:fix a potential memory leak in probe function

Use for_each_child_of_node_scoped() to simplify the code and ensure the device node reference is automatically released when the loop scope ends.

---
 drivers/misc/ti_fpc202.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/misc/ti_fpc202.c +1 -2
index 7964e46c7448..8eb2b5ac9850 100644
@@ -309,7 +309,6 @@ static void fpc202_remove_port(struct fpc202_priv *priv, int port_id)
 static int fpc202_probe(struct i2c_client *client)
 {
 	struct device *dev = &client->dev;
-	struct device_node *i2c_handle;
 	struct fpc202_priv *priv;
 	int ret, port_id;
 
@@ -357,7 +356,7 @@ static int fpc202_probe(struct i2c_client *client)
 
 	bitmap_zero(priv->probed_ports, FPC202_NUM_PORTS);
 
-	for_each_child_of_node(dev->of_node, i2c_handle) {
+	for_each_child_of_node_scoped(dev->of_node, i2c_handle) {
 		ret = of_property_read_u32(i2c_handle, "reg", &port_id);
 		if (ret) {
 			if (ret == -EINVAL)
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hello Felix,

Quoted 4 lines · On Thursday, 25 December 2025 16:02:56 CET Felix Gu wrote:

Use for_each_child_of_node_scoped() to simplify the code and ensure the device node reference is automatically released when the loop scope ends.

Nit: please put spaces between the tags in the commit log title, like so:

"misc: ti_fpc202: fix a potential memory leak ..."

Quoted 18 lines
---
 drivers/misc/ti_fpc202.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/misc/ti_fpc202.c +0 -1
index 7964e46c7448..8eb2b5ac9850 100644
@@ -309,7 +309,6 @@ static void fpc202_remove_port(struct fpc202_priv *priv,
 int port_id) static int fpc202_probe(struct i2c_client *client)
 {
 	struct device *dev = &client->dev;
-	struct device_node *i2c_handle;
 	struct fpc202_priv *priv;
 	int ret, port_id;
 

drivers/misc/ti_fpc202.c static int fpc202_probe(struct i2c_client *client) · line 362

Quoted 8 lines
drivers/misc/ti_fpc202.c +1 -1
@@ -357,7 +356,7 @@ static int fpc202_probe(struct i2c_client *client)
 
 	bitmap_zero(priv->probed_ports, FPC202_NUM_PORTS);
 
-	for_each_child_of_node(dev->of_node, i2c_handle) {
+	for_each_child_of_node_scoped(dev->of_node, i2c_handle) {
 		ret = of_property_read_u32(i2c_handle, "reg", &port_id);
 		if (ret) {
 			if (ret == -EINVAL)

With the above fixed:

author
#2 lore raw

PATCH v2 1/1 misc: ti_fpc202: fix a potential memory leak in probe function

Use for_each_child_of_node_scoped() to simplify the code and ensure the device node reference is automatically released when the loop scope ends.

---
v2:
- Fixed spacing in the commit title ("misc: ti_fpc202: ...") as requested by Romain.
- Added Romain's Reviewed-by tag.

 drivers/misc/ti_fpc202.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/misc/ti_fpc202.c +1 -2
index 7964e46c7448..8eb2b5ac9850 100644
@@ -309,7 +309,6 @@ static void fpc202_remove_port(struct fpc202_priv *priv, int port_id)
 static int fpc202_probe(struct i2c_client *client)
 {
 	struct device *dev = &client->dev;
-	struct device_node *i2c_handle;
 	struct fpc202_priv *priv;
 	int ret, port_id;
 
@@ -357,7 +356,7 @@ static int fpc202_probe(struct i2c_client *client)
 
 	bitmap_zero(priv->probed_ports, FPC202_NUM_PORTS);
 
-	for_each_child_of_node(dev->of_node, i2c_handle) {
+	for_each_child_of_node_scoped(dev->of_node, i2c_handle) {
 		ret = of_property_read_u32(i2c_handle, "reg", &port_id);
 		if (ret) {
 			if (ret == -EINVAL)
Signature · 1 line
2.43.0