Skip to content
/ linux Public

Commit 456a60d

Browse files
Wei LiSasha Levin
authored andcommitted
pinctrl: single: fix refcount leak in pcs_add_gpio_func()
[ Upstream commit 3533533 ] of_parse_phandle_with_args() returns a device_node pointer with refcount incremented in gpiospec.np. The loop iterates through all phandles but never releases the reference, causing a refcount leak on each iteration. Add of_node_put() calls to release the reference after extracting the needed arguments and on the error path when devm_kzalloc() fails. This bug was detected by our static analysis tool and verified by my code review. Fixes: a1a277e ("pinctrl: single: create new gpio function range") Signed-off-by: Wei Li <unsw.weili@gmail.com> Signed-off-by: Linus Walleij <linusw@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 9c0eed6 commit 456a60d

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/pinctrl/pinctrl-single.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,7 @@ static int pcs_add_gpio_func(struct device_node *node, struct pcs_device *pcs)
13641364
}
13651365
range = devm_kzalloc(pcs->dev, sizeof(*range), GFP_KERNEL);
13661366
if (!range) {
1367+
of_node_put(gpiospec.np);
13671368
ret = -ENOMEM;
13681369
break;
13691370
}
@@ -1373,6 +1374,7 @@ static int pcs_add_gpio_func(struct device_node *node, struct pcs_device *pcs)
13731374
mutex_lock(&pcs->mutex);
13741375
list_add_tail(&range->node, &pcs->gpiofuncs);
13751376
mutex_unlock(&pcs->mutex);
1377+
of_node_put(gpiospec.np);
13761378
}
13771379
return ret;
13781380
}

0 commit comments

Comments
 (0)