Skip to contentSkip to conversation

i2c: mux: demux-pinctrl: fix OF node leak on kstrdup failure

PATCH Applied Linkai Gong 2 participants 2 messages Aug 13 – Aug 16

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

PATCH 1/1 i2c: mux: demux-pinctrl: fix OF node leak on kstrdup failure

of_parse_phandle() takes a reference on the parent node. If a later devm_kstrdup() fails, err_rollback only releases nodes for indices 0..i-1, so the current node is leaked.

of_node_put() the current parent before rolling back.

Fixes 7c0195fa9a9e ("i2c: mux: demux-pinctrl: check the return value of devm_kstrdup()")
---
 drivers/i2c/muxes/i2c-demux-pinctrl.c | 1 +
 1 file changed, 1 insertion(+)
drivers/i2c/muxes/i2c-demux-pinctrl.c +1 -0
index f2a1f4744978..2403c0bf7c43 100644
@@ -247,6 +247,7 @@ static int i2c_demux_pinctrl_probe(struct platform_device *pdev)
 		props[i].value = devm_kstrdup(&pdev->dev, "ok", GFP_KERNEL);
 		if (!props[i].name || !props[i].value) {
 			err = -ENOMEM;
+			of_node_put(adap_np);
 			goto err_rollback;
 		}
 		props[i].length = 3;
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw

Hi Linkai,

Quoted 8 lines · Linkai Gong

of_parse_phandle() takes a reference on the parent node. If a later devm_kstrdup() fails, err_rollback only releases nodes for indices 0..i-1, so the current node is leaked.

of_node_put() the current parent before rolling back.

Fixes 7c0195fa9a9e ("i2c: mux: demux-pinctrl: check the return value of devm_kstrdup()")

merged to i2c/i2c-2.

Thanks,
Andi