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

Configure Feed

Select the types of activity you want to include in your feed.

iio: amplifiers: ad8366: refactor device resource management

Adhere modern device resource management with the following:
- Voltage regulator managed and enabled internally;
- IIO device registration handled with devm_iio_device_register();
- removal of goto's from the probe function;
- ad8366_remove() removed as it is not needed anymore;

With the drop of goto's dev_err_probe() is used to report probe errors.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Rodrigo Alencar and committed by
Jonathan Cameron
5fdb9c83 5603a07a

+10 -40
+10 -40
drivers/iio/amplifiers/ad8366.c
··· 43 43 44 44 struct ad8366_state { 45 45 struct spi_device *spi; 46 - struct regulator *reg; 47 46 struct mutex lock; /* protect sensor state */ 48 47 struct gpio_desc *reset_gpio; 49 48 unsigned char ch[2]; ··· 262 263 if (ret) 263 264 return ret; 264 265 265 - st->reg = devm_regulator_get(&spi->dev, "vcc"); 266 - if (!IS_ERR(st->reg)) { 267 - ret = regulator_enable(st->reg); 268 - if (ret) 269 - return ret; 270 - } 266 + ret = devm_regulator_get_enable(dev, "vcc"); 267 + if (ret) 268 + return dev_err_probe(dev, ret, "Failed to get regulator\n"); 271 269 272 - spi_set_drvdata(spi, indio_dev); 273 270 st->spi = spi; 274 271 st->type = spi_get_device_id(spi)->driver_data; 275 272 ··· 279 284 case ID_HMC792: 280 285 case ID_HMC1119: 281 286 st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_HIGH); 282 - if (IS_ERR(st->reset_gpio)) { 283 - ret = PTR_ERR(st->reset_gpio); 284 - goto error_disable_reg; 285 - } 287 + if (IS_ERR(st->reset_gpio)) 288 + return dev_err_probe(dev, PTR_ERR(st->reset_gpio), 289 + "Failed to get reset gpio\n"); 290 + 286 291 indio_dev->channels = ada4961_channels; 287 292 indio_dev->num_channels = ARRAY_SIZE(ada4961_channels); 288 293 break; 289 294 default: 290 - dev_err(&spi->dev, "Invalid device ID\n"); 291 - ret = -EINVAL; 292 - goto error_disable_reg; 295 + return dev_err_probe(dev, -EINVAL, "Invalid device ID\n"); 293 296 } 294 297 295 298 st->info = &ad8366_infos[st->type]; ··· 297 304 298 305 ret = ad8366_write(indio_dev, 0, 0); 299 306 if (ret < 0) 300 - goto error_disable_reg; 307 + return dev_err_probe(dev, ret, "failed to write initial gain\n"); 301 308 302 - ret = iio_device_register(indio_dev); 303 - if (ret) 304 - goto error_disable_reg; 305 - 306 - return 0; 307 - 308 - error_disable_reg: 309 - if (!IS_ERR(st->reg)) 310 - regulator_disable(st->reg); 311 - 312 - return ret; 313 - } 314 - 315 - static void ad8366_remove(struct spi_device *spi) 316 - { 317 - struct iio_dev *indio_dev = spi_get_drvdata(spi); 318 - struct ad8366_state *st = iio_priv(indio_dev); 319 - struct regulator *reg = st->reg; 320 - 321 - iio_device_unregister(indio_dev); 322 - 323 - if (!IS_ERR(reg)) 324 - regulator_disable(reg); 309 + return devm_iio_device_register(dev, indio_dev); 325 310 } 326 311 327 312 static const struct spi_device_id ad8366_id[] = { ··· 317 346 .name = KBUILD_MODNAME, 318 347 }, 319 348 .probe = ad8366_probe, 320 - .remove = ad8366_remove, 321 349 .id_table = ad8366_id, 322 350 }; 323 351