Skip to content

Commit

Permalink
regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF
Browse files Browse the repository at this point in the history
Use of_device_get_match_data which has NULL test for match before
dereference match->data. Add NULL test for drvtype so it still works
for fixed_voltage_ops when !CONFIG_OF.

Signed-off-by: Axel Lin <[email protected]>
Reviewed-by: Philippe Schenker <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
AxelLin authored and broonie committed Sep 23, 2019
1 parent f8970d3 commit 1d6db22
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/regulator/fixed.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct fixed_voltage_config *config;
struct fixed_voltage_data *drvdata;
const struct fixed_dev_type *drvtype =
of_match_device(dev->driver->of_match_table, dev)->data;
const struct fixed_dev_type *drvtype = of_device_get_match_data(dev);
struct regulator_config cfg = { };
enum gpiod_flags gflags;
int ret;
Expand Down Expand Up @@ -177,7 +176,7 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
drvdata->desc.type = REGULATOR_VOLTAGE;
drvdata->desc.owner = THIS_MODULE;

if (drvtype->has_enable_clock) {
if (drvtype && drvtype->has_enable_clock) {
drvdata->desc.ops = &fixed_voltage_clkenabled_ops;

drvdata->enable_clock = devm_clk_get(dev, NULL);
Expand Down

0 comments on commit 1d6db22

Please sign in to comment.