Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF

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 <axel.lin@ingics.com>
Reviewed-by: Philippe Schenker <philippe.schenker@toradex.com>
Link: https://lore.kernel.org/r/20190922022928.28355-1-axel.lin@ingics.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Axel Lin and committed by
Mark Brown
1d6db22f f8970d34

+2 -3
+2 -3
drivers/regulator/fixed.c
··· 144 144 struct device *dev = &pdev->dev; 145 145 struct fixed_voltage_config *config; 146 146 struct fixed_voltage_data *drvdata; 147 - const struct fixed_dev_type *drvtype = 148 - of_match_device(dev->driver->of_match_table, dev)->data; 147 + const struct fixed_dev_type *drvtype = of_device_get_match_data(dev); 149 148 struct regulator_config cfg = { }; 150 149 enum gpiod_flags gflags; 151 150 int ret; ··· 176 177 drvdata->desc.type = REGULATOR_VOLTAGE; 177 178 drvdata->desc.owner = THIS_MODULE; 178 179 179 - if (drvtype->has_enable_clock) { 180 + if (drvtype && drvtype->has_enable_clock) { 180 181 drvdata->desc.ops = &fixed_voltage_clkenabled_ops; 181 182 182 183 drvdata->enable_clock = devm_clk_get(dev, NULL);