Skip to content

Commit

Permalink
regulator: gpio-regulator: Don't oops on missing regulator-type property
Browse files Browse the repository at this point in the history
Catch missing regulator-type property in DT and return an error
gracefully instead of deferencing a NULL pointer and crashing.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
  • Loading branch information
Laurent Pinchart authored and Mark Brown committed Nov 9, 2013
1 parent 5e01dc7 commit 251b9c2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/regulator/gpio-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np)
struct property *prop;
const char *regtype;
int proplen, gpio, i;
int ret;

config = devm_kzalloc(dev,
sizeof(struct gpio_regulator_config),
Expand Down Expand Up @@ -202,7 +203,11 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np)
}
config->nr_states = i;

of_property_read_string(np, "regulator-type", &regtype);
ret = of_property_read_string(np, "regulator-type", &regtype);
if (ret < 0) {
dev_err(dev, "Missing 'regulator-type' property\n");
return ERR_PTR(-EINVAL);
}

if (!strncmp("voltage", regtype, 7))
config->type = REGULATOR_VOLTAGE;
Expand Down

0 comments on commit 251b9c2

Please sign in to comment.