Linux IIO development
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Archit Anant <architanant5@gmail.com>,
	lars@metafoo.de, Michael.Hennerich@analog.com,
	nuno.sa@analog.com, andy@kernel.org, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: adc: ad799x: use devm_iio_device_register and devm buffer setup
Date: Sun, 1 Mar 2026 10:46:07 -0600	[thread overview]
Message-ID: <8bf08908-b8fd-4c4f-ab74-66575ed771ab@baylibre.com> (raw)
In-Reply-To: <20260301113452.7e1f95ee@jic23-huawei>

On 3/1/26 5:34 AM, Jonathan Cameron wrote:
> On Sat, 28 Feb 2026 11:35:15 -0600
> David Lechner <dlechner@baylibre.com> wrote:
> 
>> On 2/28/26 11:19 AM, Archit Anant wrote:
>>> Hi David,
>>>
>>> On Sat, Feb 28, 2026 at 10:06 PM David Lechner <dlechner@baylibre.com> wrote:  
>>>>
>>>> On 2/28/26 9:45 AM, Archit Anant wrote:  
>>>>> Convert the driver to use the device-managed versions of
>>>>> iio_device_register() and iio_triggered_buffer_setup().
>>>>>
>>>>> This simplifies the error handling in ad799x_probe() by removing the
>>>>> 'error_cleanup_ring' goto label. It also removes the need to manually
>>>>> call iio_device_unregister() and iio_triggered_buffer_cleanup() in
>>>>> ad799x_remove().
>>>>>  
>>>> Since we are doing this, why not also handle the regulators and
>>>> rx_buf so that we can drop the remove() function completely?  
>>>
>>> I completely agree that dropping the remove() function is the
>>> ideal end state but I initially stopped short of doing that because of two
>>> hurdles:
>>>
>>> 1. regulators: since ad799x_read_raw() needs the regulator pointers
>>> to call regulator_get_voltage(), I couldn't simply use
>>> devm_regulator_get_enable().  
>>
>> In this case, we can use devm_add_action_or_reset() to register the
>> disable callbacks.
> 
> It is vanishingly rare for for the voltages to change after driver probe,
> so an alternative that is almost certainly fine is to read and cache the
> voltage at probe.

In this driver, we still need the handle to the regulator for suspend
resume, so that doesn't avoid the need for using devm_add_action_or_reset()
in this particular case, I don't think.

>> #define AD799X_MAX_CHANNELS 8
>>
>> ...
>>
>> struct ad799x_state {
>> 	...
>> 	unsigned int			transfer_size;
>> 	IIO_DECLARE_DMA_BUFFER_WITH_TS(__be16, rx_buf, AD799X_MAX_CHANNELS);
>> };
>>
>> Note, it is important for this to be the last field in the struct
>> for DMA alignment purposes.
>>
> I2C driver, so no need. I2C by default bounce buffers everything anyway so we don't
> need an aligned buffer (or the padding that results in at the end of the structure).

Thanks for the correction. I just saw an I2C driver the other day that
was incorrectly doing this then that lead me astray.



  reply	other threads:[~2026-03-01 16:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-28 15:45 [PATCH] iio: adc: ad799x: use devm_iio_device_register and devm buffer setup Archit Anant
2026-02-28 16:36 ` David Lechner
2026-02-28 17:19   ` Archit Anant
2026-02-28 17:35     ` David Lechner
2026-03-01 11:34       ` Jonathan Cameron
2026-03-01 16:46         ` David Lechner [this message]
2026-03-01 11:37 ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8bf08908-b8fd-4c4f-ab74-66575ed771ab@baylibre.com \
    --to=dlechner@baylibre.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=architanant5@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox