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: adc: ad7887: convert probe to device-managed functions

This is conversion of the driver to use device-managed functions.
The IIO registration and triggered buffer setup both have device-managed
versions.
The regulator disable needs to be handled via an action_or_reset handler.

With these changes, the remove hook is removed, and the error path is
cleaned up in probe.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Link: https://lore.kernel.org/r/20201113091648.148589-1-alexandru.ardelean@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Alexandru Ardelean and committed by
Jonathan Cameron
24b28498 89d1f725

+15 -28
+15 -28
drivers/iio/adc/ad7887.c
··· 232 232 .read_raw = &ad7887_read_raw, 233 233 }; 234 234 235 + static void ad7887_reg_disable(void *data) 236 + { 237 + struct regulator *reg = data; 238 + 239 + regulator_disable(reg); 240 + } 241 + 235 242 static int ad7887_probe(struct spi_device *spi) 236 243 { 237 244 struct ad7887_platform_data *pdata = spi->dev.platform_data; ··· 263 256 264 257 if (st->reg) { 265 258 ret = regulator_enable(st->reg); 259 + if (ret) 260 + return ret; 261 + 262 + ret = devm_add_action_or_reset(&spi->dev, ad7887_reg_disable, st->reg); 266 263 if (ret) 267 264 return ret; 268 265 } ··· 327 316 indio_dev->num_channels = st->chip_info->num_channels; 328 317 } 329 318 330 - ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, 319 + ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, 320 + &iio_pollfunc_store_time, 331 321 &ad7887_trigger_handler, &ad7887_ring_setup_ops); 332 322 if (ret) 333 - goto error_disable_reg; 323 + return ret; 334 324 335 - ret = iio_device_register(indio_dev); 336 - if (ret) 337 - goto error_unregister_ring; 338 - 339 - return 0; 340 - error_unregister_ring: 341 - iio_triggered_buffer_cleanup(indio_dev); 342 - error_disable_reg: 343 - if (st->reg) 344 - regulator_disable(st->reg); 345 - 346 - return ret; 347 - } 348 - 349 - static int ad7887_remove(struct spi_device *spi) 350 - { 351 - struct iio_dev *indio_dev = spi_get_drvdata(spi); 352 - struct ad7887_state *st = iio_priv(indio_dev); 353 - 354 - iio_device_unregister(indio_dev); 355 - iio_triggered_buffer_cleanup(indio_dev); 356 - if (st->reg) 357 - regulator_disable(st->reg); 358 - 359 - return 0; 325 + return devm_iio_device_register(&spi->dev, indio_dev); 360 326 } 361 327 362 328 static const struct spi_device_id ad7887_id[] = { ··· 347 359 .name = "ad7887", 348 360 }, 349 361 .probe = ad7887_probe, 350 - .remove = ad7887_remove, 351 362 .id_table = ad7887_id, 352 363 }; 353 364 module_spi_driver(ad7887_driver);