Skip to content

Commit 3533533

Browse files
Wei Lilinusw
authored andcommitted
pinctrl: single: fix refcount leak in pcs_add_gpio_func()
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>
1 parent e56aa18 commit 3533533

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

drivers/pinctrl/pinctrl-single.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,7 @@ static int pcs_add_gpio_func(struct device_node *node, struct pcs_device *pcs)
13591359
}
13601360
range = devm_kzalloc(pcs->dev, sizeof(*range), GFP_KERNEL);
13611361
if (!range) {
1362+
of_node_put(gpiospec.np);
13621363
ret = -ENOMEM;
13631364
break;
13641365
}
@@ -1368,6 +1369,7 @@ static int pcs_add_gpio_func(struct device_node *node, struct pcs_device *pcs)
13681369
mutex_lock(&pcs->mutex);
13691370
list_add_tail(&range->node, &pcs->gpiofuncs);
13701371
mutex_unlock(&pcs->mutex);
1372+
of_node_put(gpiospec.np);
13711373
}
13721374
return ret;
13731375
}

0 commit comments

Comments
 (0)