Re: [PATCH] iio: adc: mcp320x: Simplify device removal logic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 2/10/24 17:58, Jonathan Cameron wrote:
Use devm_* APIs to enable regulator and to register in IIO infrastructure.

Signed-off-by: Arturas Moskvinas <arturas.moskvinas@xxxxxxxxx>

Don't get the same regulator twice so as automate turning it off.
The devm_regulator_get_enable() call is carefully hiding the
regulator for cases where the driver never accesses it.

Here we need it to read the voltage.

To convert such a case to fully devm managed, use a
devm_add_action_or_reset() and a custom callback.
This is exactly the reason I wanted to use devm_regulator_get_enable() instead of devm_add_action_or_reset + custom callback which I saw in other ADCs code. It seems quite repetitive. Wondering if this could be addressed by regulator subsystem to provide device managed method which gets _enabled_ regulator resource and an automated disabling + resource freeing? We will loose fine grained information where failure happened exactly - getting resource or enabling regulator though...

  static void mcp320x_remove(struct spi_device *spi)
  {
-	struct iio_dev *indio_dev = spi_get_drvdata(spi);
-	struct mcp320x *adc = iio_priv(indio_dev);
-
-	iio_device_unregister(indio_dev);
-	regulator_disable(adc->reg);
  }
Had the change otherwise been ok...

You should be able to remove this function completely now it is empty.
https://elixir.bootlin.com/linux/latest/source/drivers/spi/spi.c#L446
checks it's existence before calling it.
Ack, will address with V2 patch.

Arturas Moskvinas




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux