Skip to contentSkip to conversation

misc: eeprom: idt_89hpesx: fix fwnode leak in idt_get_fw_data()

PATCH In review Manush Prajwal 2 participants 2 messages Aug 23 – Oct 1 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 misc: eeprom: idt_89hpesx: fix fwnode leak in idt_get_fw_data()

device_for_each_child_node() takes a reference on each fwnode it returns, which the loop body must release before it stops iterating. When idt_ee_match_id() finds a matching EEPROM child, the loop breaks out immediately without calling fwnode_handle_put() on that fwnode, leaking the reference.

Rework the loop around device_for_each_child_node_scoped() instead of adding a manual fwnode_handle_put(), so the reference is released automatically on every exit path (the early break as well as normal loop completion), per Markus Elfring's review of v1.

---
v2: Use device_for_each_child_node_scoped() instead of a manual
fwnode_handle_put() before the break, and use my full name in Signed-off-by, per Markus Elfring's review.

 drivers/misc/eeprom/idt_89hpesx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/eeprom/idt_89hpesx.c +1 -1
index e056d2dea..a1b2c3d4e 100644
@@ -1080,7 +1080,7 @@ static void idt_get_fw_data(struct idt_89hpesx_dev *pdev)
 	struct device *dev = &pdev->client->dev;
 	struct fwnode_handle *fwnode;
 
-	device_for_each_child_node(dev, fwnode) {
+	device_for_each_child_node_scoped(dev, fwnode) {
 		ee_id = idt_ee_match_id(fwnode);
 		if (ee_id)
 			break;

--
2.46.2.windows.1

maintainer
#1 lore raw
Quoted 34 lines · Manush Prajwal

device_for_each_child_node() takes a reference on each fwnode it returns, which the loop body must release before it stops iterating. When idt_ee_match_id() finds a matching EEPROM child, the loop breaks out immediately without calling fwnode_handle_put() on that fwnode, leaking the reference.

Rework the loop around device_for_each_child_node_scoped() instead of adding a manual fwnode_handle_put(), so the reference is released automatically on every exit path (the early break as well as normal loop completion), per Markus Elfring's review of v1.

---
v2: Use device_for_each_child_node_scoped() instead of a manual
fwnode_handle_put() before the break, and use my full name in Signed-off-by, per Markus Elfring's review.

 drivers/misc/eeprom/idt_89hpesx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/eeprom/idt_89hpesx.c +1 -2
index e056d2dea..a1b2c3d4e 100644
@@ -1080,7 +1080,7 @@ static void idt_get_fw_data(struct idt_89hpesx_dev *pdev)
 	struct device *dev = &pdev->client->dev;
 	struct fwnode_handle *fwnode;
 
-	device_for_each_child_node(dev, fwnode) {
+	device_for_each_child_node_scoped(dev, fwnode) {
 		ee_id = idt_ee_match_id(fwnode);
 		if (ee_id)
 			break;
--
Quoted 2 lines

2.46.2.windows.1

Breaks the build, please be more careful.