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: mcp320x: Simplify device removal logic

Use devm_* APIs to enable/disable regulator and to register in IIO infrastructure.

Signed-off-by: Arturas Moskvinas <arturas.moskvinas@gmail.com>
Link: https://lore.kernel.org/r/20240219074139.193464-2-arturas.moskvinas@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Arturas Moskvinas and committed by
Jonathan Cameron
58efe761 3b4ebff2

+10 -21
+10 -21
drivers/iio/adc/mcp320x.c
··· 371 371 }, 372 372 }; 373 373 374 + static void mcp320x_regulator_disable(void *reg) 375 + { 376 + regulator_disable(reg); 377 + } 378 + 374 379 static int mcp320x_probe(struct spi_device *spi) 375 380 { 376 381 struct iio_dev *indio_dev; ··· 393 388 indio_dev->name = spi_get_device_id(spi)->name; 394 389 indio_dev->modes = INDIO_DIRECT_MODE; 395 390 indio_dev->info = &mcp320x_info; 396 - spi_set_drvdata(spi, indio_dev); 397 391 398 392 device_index = spi_get_device_id(spi)->driver_data; 399 393 chip_info = &mcp320x_chip_infos[device_index]; ··· 449 445 if (ret < 0) 450 446 return ret; 451 447 448 + ret = devm_add_action_or_reset(&spi->dev, mcp320x_regulator_disable, adc->reg); 449 + if (ret < 0) 450 + return ret; 451 + 452 452 mutex_init(&adc->lock); 453 453 454 - ret = iio_device_register(indio_dev); 455 - if (ret < 0) 456 - goto reg_disable; 457 - 458 - return 0; 459 - 460 - reg_disable: 461 - regulator_disable(adc->reg); 462 - 463 - return ret; 464 - } 465 - 466 - static void mcp320x_remove(struct spi_device *spi) 467 - { 468 - struct iio_dev *indio_dev = spi_get_drvdata(spi); 469 - struct mcp320x *adc = iio_priv(indio_dev); 470 - 471 - iio_device_unregister(indio_dev); 472 - regulator_disable(adc->reg); 454 + return devm_iio_device_register(&spi->dev, indio_dev); 473 455 } 474 456 475 457 static const struct of_device_id mcp320x_dt_ids[] = { ··· 510 520 .of_match_table = mcp320x_dt_ids, 511 521 }, 512 522 .probe = mcp320x_probe, 513 - .remove = mcp320x_remove, 514 523 .id_table = mcp320x_id, 515 524 }; 516 525 module_spi_driver(mcp320x_driver);