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

iio: adc: max1241: 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.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Acked-by: Alexandru Lazar <alazar@startmail.com>
Link: https://lore.kernel.org/r/7c759bf6c06e72ae70bffeebc1939d9903427278.1660934107.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Matti Vaittinen and committed by
Jonathan Cameron
f55c8e66 fd5b6c48

+3 -25
+3 -25
drivers/iio/adc/max1241.c
··· 22 22 struct max1241 { 23 23 struct spi_device *spi; 24 24 struct mutex lock; 25 - struct regulator *vdd; 26 25 struct regulator *vref; 27 26 struct gpio_desc *shutdown; 28 27 ··· 109 110 .read_raw = max1241_read_raw, 110 111 }; 111 112 112 - static void max1241_disable_vdd_action(void *data) 113 - { 114 - struct max1241 *adc = data; 115 - struct device *dev = &adc->spi->dev; 116 - int err; 117 - 118 - err = regulator_disable(adc->vdd); 119 - if (err) 120 - dev_err(dev, "could not disable vdd regulator.\n"); 121 - } 122 - 123 113 static void max1241_disable_vref_action(void *data) 124 114 { 125 115 struct max1241 *adc = data; ··· 135 147 adc->spi = spi; 136 148 mutex_init(&adc->lock); 137 149 138 - adc->vdd = devm_regulator_get(dev, "vdd"); 139 - if (IS_ERR(adc->vdd)) 140 - return dev_err_probe(dev, PTR_ERR(adc->vdd), 141 - "failed to get vdd regulator\n"); 142 - 143 - ret = regulator_enable(adc->vdd); 150 + ret = devm_regulator_get_enable(dev, "vdd"); 144 151 if (ret) 145 - return ret; 146 - 147 - ret = devm_add_action_or_reset(dev, max1241_disable_vdd_action, adc); 148 - if (ret) { 149 - dev_err(dev, "could not set up vdd regulator cleanup action\n"); 150 - return ret; 151 - } 152 + return dev_err_probe(dev, ret, 153 + "failed to get/enable vdd regulator\n"); 152 154 153 155 adc->vref = devm_regulator_get(dev, "vref"); 154 156 if (IS_ERR(adc->vref))