Skip to content

Commit a05a140

Browse files
vzapolskiyLinus Walleij
authored andcommitted
gpio: don't free unallocated ida on gpiochip_add_data_with_key() error path
The change corrects the error path in gpiochip_add_data_with_key() by avoiding to call ida_simple_remove(), if ida_simple_get() returns an error. Note that ida_simple_remove()/ida_free() throws a BUG(), if id argument is negative, it allows to easily check the correctness of the fix by fuzzing the return value from ida_simple_get(). Fixes: ff2b135 ("gpio: make the gpiochip a real device") Cc: [email protected] # v4.6+ Signed-off-by: Vladimir Zapolskiy <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent defeea5 commit a05a140

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

drivers/gpio/gpiolib.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
12951295
gdev->descs = kcalloc(chip->ngpio, sizeof(gdev->descs[0]), GFP_KERNEL);
12961296
if (!gdev->descs) {
12971297
status = -ENOMEM;
1298-
goto err_free_gdev;
1298+
goto err_free_ida;
12991299
}
13001300

13011301
if (chip->ngpio == 0) {
@@ -1427,8 +1427,9 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
14271427
kfree_const(gdev->label);
14281428
err_free_descs:
14291429
kfree(gdev->descs);
1430-
err_free_gdev:
1430+
err_free_ida:
14311431
ida_simple_remove(&gpio_ida, gdev->id);
1432+
err_free_gdev:
14321433
/* failures here can mean systems won't boot... */
14331434
pr_err("%s: GPIOs %d..%d (%s) failed to register, %d\n", __func__,
14341435
gdev->base, gdev->base + gdev->ngpio - 1,

0 commit comments

Comments
 (0)