Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d688e0f authored by Takashi Iwai's avatar Takashi Iwai Committed by Greg Kroah-Hartman
Browse files

gpio: exar: Fix bad handling for ida_simple_get error path



[ Upstream commit 333830aa149a87cabeb5d30fbcf12eecc8040d2c ]

The commit 7ecced0934e5 ("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: 7ecced0934e5 ("gpio: exar: add a check for the return value of ida_simple_get fails")
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent efae5201
Loading
Loading
Loading
Loading
+5 −2
Original line number Original line Diff line number Diff line
@@ -148,8 +148,10 @@ static int gpio_exar_probe(struct platform_device *pdev)
	mutex_init(&exar_gpio->lock);
	mutex_init(&exar_gpio->lock);


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


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


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