Skip to content

Commit

Permalink
gpio: exar: Fix bad handling for ida_simple_get error path
Browse files Browse the repository at this point in the history
The commit 7ecced0 ("gpio: exar: add a check for the return value
of ida_simple_get fails") added a goto jump to the common error
handler for ida_simple_get() error, but this is wrong in two ways:
it doesn't set the proper return code and, more badly, it invokes
ida_simple_remove() with a negative index that shall lead to a kernel
panic via BUG_ON().

This patch addresses those two issues.

Fixes: 7ecced0 ("gpio: exar: add a check for the return value of ida_simple_get fails")
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
  • Loading branch information
tiwai authored and brgl committed May 5, 2020
1 parent 19c26d9 commit 333830a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/gpio/gpio-exar.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ static int gpio_exar_probe(struct platform_device *pdev)
mutex_init(&exar_gpio->lock);

index = ida_simple_get(&ida_index, 0, 0, GFP_KERNEL);
if (index < 0)
goto err_destroy;
if (index < 0) {
ret = index;
goto err_mutex_destroy;
}

sprintf(exar_gpio->name, "exar_gpio%d", index);
exar_gpio->gpio_chip.label = exar_gpio->name;
Expand All @@ -176,6 +178,7 @@ static int gpio_exar_probe(struct platform_device *pdev)

err_destroy:
ida_simple_remove(&ida_index, index);
err_mutex_destroy:
mutex_destroy(&exar_gpio->lock);
return ret;
}
Expand Down

0 comments on commit 333830a

Please sign in to comment.