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

This change converts the probe of this driver to use device-managed
register functions, and a devm_add_action_or_reset() for the regulator
disable.

With this, the exit & error paths can be removed.
Another side-effect is that this should avoid some static-analyzer's check
with respect to a potential null dereference of the regulator. The null
dereference isn't likely to happen (under normal operation), so there isn't
a requirement to have this fixed/backported in other releases.

As a note: this is removing spi_set_drvdata() since there is no other
spi_get_drvdata() (or dev_get_drvdata()) call that need it.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Cc: Colin Ian King <colin.king@canonical.com>
Link: https://lore.kernel.org/r/20201127094038.91714-1-alexandru.ardelean@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Alexandru Ardelean and committed by
Jonathan Cameron
b6a3f832 617e38a2

+15 -31
+15 -31
drivers/iio/adc/ad7298.c
··· 279 279 .update_scan_mode = ad7298_update_scan_mode, 280 280 }; 281 281 282 + static void ad7298_reg_disable(void *data) 283 + { 284 + struct regulator *reg = data; 285 + 286 + regulator_disable(reg); 287 + } 288 + 282 289 static int ad7298_probe(struct spi_device *spi) 283 290 { 284 291 struct ad7298_state *st; ··· 313 306 ret = regulator_enable(st->reg); 314 307 if (ret) 315 308 return ret; 316 - } 317 309 318 - spi_set_drvdata(spi, indio_dev); 310 + ret = devm_add_action_or_reset(&spi->dev, ad7298_reg_disable, 311 + st->reg); 312 + if (ret) 313 + return ret; 314 + } 319 315 320 316 st->spi = spi; 321 317 ··· 344 334 spi_message_add_tail(&st->scan_single_xfer[1], &st->scan_single_msg); 345 335 spi_message_add_tail(&st->scan_single_xfer[2], &st->scan_single_msg); 346 336 347 - ret = iio_triggered_buffer_setup(indio_dev, NULL, 337 + ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL, 348 338 &ad7298_trigger_handler, NULL); 349 339 if (ret) 350 - goto error_disable_reg; 340 + return ret; 351 341 352 - ret = iio_device_register(indio_dev); 353 - if (ret) 354 - goto error_cleanup_ring; 355 - 356 - return 0; 357 - 358 - error_cleanup_ring: 359 - iio_triggered_buffer_cleanup(indio_dev); 360 - error_disable_reg: 361 - if (st->ext_ref) 362 - regulator_disable(st->reg); 363 - 364 - return ret; 365 - } 366 - 367 - static int ad7298_remove(struct spi_device *spi) 368 - { 369 - struct iio_dev *indio_dev = spi_get_drvdata(spi); 370 - struct ad7298_state *st = iio_priv(indio_dev); 371 - 372 - iio_device_unregister(indio_dev); 373 - iio_triggered_buffer_cleanup(indio_dev); 374 - if (st->ext_ref) 375 - regulator_disable(st->reg); 376 - 377 - return 0; 342 + return devm_iio_device_register(&spi->dev, indio_dev); 378 343 } 379 344 380 345 static const struct spi_device_id ad7298_id[] = { ··· 363 378 .name = "ad7298", 364 379 }, 365 380 .probe = ad7298_probe, 366 - .remove = ad7298_remove, 367 381 .id_table = ad7298_id, 368 382 }; 369 383 module_spi_driver(ad7298_driver);