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

iio: adc: ad7606: simplify using devm_regulator_get_enable()

Drop open-coded pattern: 'devm_regulator_get(), regulator_enable(),
add_action_or_reset(regulator_disable)' and use the
devm_regulator_get_enable() and drop the pointer to the regulator.
This simplifies code and makes it less tempting to add manual control
for the regulator which is also controlled by devm.

Whilst here also switch to dev_err_probe() to provide more information
if a deferred probe occurs.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Acked-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/521c52f5a9bdc2db04d5775b36df4b233ae338da.1660934107.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Matti Vaittinen and committed by
Jonathan Cameron
fd5b6c48 7ff0ad35

+3 -21
+3 -19
drivers/iio/adc/ad7606.c
··· 557 557 .validate_device = iio_trigger_validate_own_device, 558 558 }; 559 559 560 - static void ad7606_regulator_disable(void *data) 561 - { 562 - struct ad7606_state *st = data; 563 - 564 - regulator_disable(st->reg); 565 - } 566 - 567 560 int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, 568 561 const char *name, unsigned int id, 569 562 const struct ad7606_bus_ops *bops) ··· 582 589 st->scale_avail = ad7606_scale_avail; 583 590 st->num_scales = ARRAY_SIZE(ad7606_scale_avail); 584 591 585 - st->reg = devm_regulator_get(dev, "avcc"); 586 - if (IS_ERR(st->reg)) 587 - return PTR_ERR(st->reg); 588 - 589 - ret = regulator_enable(st->reg); 590 - if (ret) { 591 - dev_err(dev, "Failed to enable specified AVcc supply\n"); 592 - return ret; 593 - } 594 - 595 - ret = devm_add_action_or_reset(dev, ad7606_regulator_disable, st); 592 + ret = devm_regulator_get_enable(dev, "avcc"); 596 593 if (ret) 597 - return ret; 594 + return dev_err_probe(dev, ret, 595 + "Failed to enable specified AVcc supply\n"); 598 596 599 597 st->chip_info = &ad7606_chip_info_tbl[id]; 600 598
-2
drivers/iio/adc/ad7606.h
··· 62 62 * struct ad7606_state - driver instance specific data 63 63 * @dev pointer to kernel device 64 64 * @chip_info entry in the table of chips that describes this device 65 - * @reg regulator info for the power supply of the device 66 65 * @bops bus operations (SPI or parallel) 67 66 * @range voltage range selection, selects which scale to apply 68 67 * @oversampling oversampling selection ··· 91 92 struct ad7606_state { 92 93 struct device *dev; 93 94 const struct ad7606_chip_info *chip_info; 94 - struct regulator *reg; 95 95 const struct ad7606_bus_ops *bops; 96 96 unsigned int range[16]; 97 97 unsigned int oversampling;