Skip to content

Commit cb2381c

Browse files
AxelLinbroonie
authored andcommitted
regulator: rt4801: Fix NULL pointer dereference if priv->enable_gpios is NULL
devm_gpiod_get_array_optional may return NULL if no GPIO was assigned. Signed-off-by: Axel Lin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 50bec7f commit cb2381c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/regulator/rt4801-regulator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static int rt4801_enable(struct regulator_dev *rdev)
6666
struct gpio_descs *gpios = priv->enable_gpios;
6767
int id = rdev_get_id(rdev), ret;
6868

69-
if (gpios->ndescs <= id) {
69+
if (!gpios || gpios->ndescs <= id) {
7070
dev_warn(&rdev->dev, "no dedicated gpio can control\n");
7171
goto bypass_gpio;
7272
}
@@ -88,7 +88,7 @@ static int rt4801_disable(struct regulator_dev *rdev)
8888
struct gpio_descs *gpios = priv->enable_gpios;
8989
int id = rdev_get_id(rdev);
9090

91-
if (gpios->ndescs <= id) {
91+
if (!gpios || gpios->ndescs <= id) {
9292
dev_warn(&rdev->dev, "no dedicated gpio can control\n");
9393
goto bypass_gpio;
9494
}

0 commit comments

Comments
 (0)