On Wed, 11 Dec 2024 14:54:45 -0600 David Lechner <dlechner@xxxxxxxxxxxx> wrote: > Refactor the IIO dmaengine buffer code to split requesting the DMA > channel from allocating the buffer. We want to be able to add a new > function where the IIO device driver manages the DMA channel, so these > two actions need to be separate. > > To do this, calling dma_request_chan() is moved from > iio_dmaengine_buffer_alloc() to iio_dmaengine_buffer_setup_ext(). A new > __iio_dmaengine_buffer_setup_ext() helper function is added to simplify > error unwinding and will also be used by a new function in a later > patch. > > iio_dmaengine_buffer_free() now only frees the buffer and does not > release the DMA channel. A new iio_dmaengine_buffer_teardown() function > is added to unwind everything done in iio_dmaengine_buffer_setup_ext(). > This keeps things more symmetrical with obvious pairs alloc/free and > setup/teardown. > > Calling dma_get_slave_caps() in iio_dmaengine_buffer_alloc() is moved so > that we can avoid any gotos for error unwinding. > > Signed-off-by: David Lechner <dlechner@xxxxxxxxxxxx> > --- > > v6 changes: > * Split out from patch that adds the new function > * Dropped owns_chan flag > * Introduced iio_dmaengine_buffer_teardown() so that > iio_dmaengine_buffer_free() doesn't have to manage the DMA channel Ouch this is a fiddly refactor to unwind from the diff. I 'think' it's correct, but am keen to get a few more eyes on this if possible. Not 100% sure what route this series will take, so on off chance this patch doesn't go through IIO or a immutable branch I create. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>