Skip to contentSkip to conversation

mtd: rawnand: meson: Add of_node_put() before return

PATCH Applied Nishka Dasgupta 3 participants 3 messages Jul 9, 2019 – Jul 25, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: rawnand: meson: Add of_node_put() before return

Each iteration of for_each_child_of_node puts the previous node, but in the case of a return from the middle of the loop, there is no put, thus causing a memory leak. Hence add an of_node_put before the return. Issue found with Coccinelle.

---
 drivers/mtd/nand/raw/meson_nand.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/nand/raw/meson_nand.c +1 -0
index ea57ddcec41e..1b82b687e5a5 100644
@@ -1320,6 +1320,7 @@ static int meson_nfc_nand_chips_init(struct device *dev,
 		ret = meson_nfc_nand_chip_init(dev, nfc, nand_np);
 		if (ret) {
 			meson_nfc_nand_chip_cleanup(nfc);
+			of_node_put(nand_np);
 			return ret;
 		}
 	}
Signature · 6 lines
2.19.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer Acked-by on v1 1/1
#1 lore raw

Hi Nishka,

Quoted 15 lines · Nishka Dasgupta

Each iteration of for_each_child_of_node puts the previous node, but in the case of a return from the middle of the loop, there is no put, thus causing a memory leak. Hence add an of_node_put before the return. Issue found with Coccinelle.

---
  drivers/mtd/nand/raw/meson_nand.c | 1 +
  1 file changed, 1 insertion(+)
drivers/mtd/nand/raw/meson_nand.c +0 -0
index ea57ddcec41e..1b82b687e5a5 100644

drivers/mtd/nand/raw/meson_nand.c static int meson_nfc_nand_chips_init(struct device *dev, · line 1323

Quoted 4 lines
drivers/mtd/nand/raw/meson_nand.c +1 -0
@@ -1320,6 +1320,7 @@ static int meson_nfc_nand_chips_init(struct device *dev,
  		ret = meson_nfc_nand_chip_init(dev, nfc, nand_np);
  		if (ret) {
  			meson_nfc_nand_chip_cleanup(nfc);
+			of_node_put(nand_np);

Thank you. Looks good to me:

drivers/mtd/nand/raw/meson_nand.c static int meson_nfc_nand_chips_init(struct device *dev, · line 1326

Quoted 4 lines
drivers/mtd/nand/raw/meson_nand.c +0 -0
  			return ret;
  		}
  	}

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Applied
#2 lore raw
In reply to Nishka Dasgupta
Quoted 7 lines · Nishka Dasgupta

Each iteration of for_each_child_of_node puts the previous node, but in the case of a return from the middle of the loop, there is no put, thus causing a memory leak. Hence add an of_node_put before the return. Issue found with Coccinelle.

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel