Re: [PATCH v3 05/11] iio: buffer-dmaengine: Support specifying buffer direction

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

 



On Mon,  3 Apr 2023 17:47:54 +0200
Paul Cercueil <paul@xxxxxxxxxxxxxxx> wrote:

> Update the devm_iio_dmaengine_buffer_setup() function to support
> specifying the buffer direction.
> 
> Update the iio_dmaengine_buffer_submit() function to handle input
> buffers as well as output buffers.
> 
> Signed-off-by: Paul Cercueil <paul@xxxxxxxxxxxxxxx>
> Reviewed-by: Alexandru Ardelean <ardeleanalex@xxxxxxxxx>

Just one trivial question inline.

Jonathan

> diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> index 5f85ba38e6f6..592d2aa9044c 100644
> --- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> +++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> @@ -64,14 +64,25 @@ static int iio_dmaengine_buffer_submit_block(struct iio_dma_buffer_queue *queue,
>  	struct dmaengine_buffer *dmaengine_buffer =
>  		iio_buffer_to_dmaengine_buffer(&queue->buffer);
>  	struct dma_async_tx_descriptor *desc;
> +	enum dma_transfer_direction dma_dir;
> +	size_t max_size;
>  	dma_cookie_t cookie;
>  
> -	block->bytes_used = min(block->size, dmaengine_buffer->max_size);
> -	block->bytes_used = round_down(block->bytes_used,
> -			dmaengine_buffer->align);
> +	max_size = min(block->size, dmaengine_buffer->max_size);
> +	max_size = round_down(max_size, dmaengine_buffer->align);
> +
> +	if (queue->buffer.direction == IIO_BUFFER_DIRECTION_IN) {
> +		block->bytes_used = max_size;
> +		dma_dir = DMA_DEV_TO_MEM;
> +	} else {
> +		dma_dir = DMA_MEM_TO_DEV;
> +	}
> +
> +	if (!block->bytes_used || block->bytes_used > max_size)
> +		return -EINVAL;

Two paths to here.  Either DIRECTION_IN in which we just set things
up so conditions being checked are always fine (unless max_size == 0?
Can that happen?), or !DIRECTION_IN.
So why not move this into the else {} branch above?

>  
>  	desc = dmaengine_prep_slave_single(dmaengine_buffer->chan,
> -		block->phys_addr, block->bytes_used, DMA_DEV_TO_MEM,
> +		block->phys_addr, block->bytes_used, dma_dir,
>  		DMA_PREP_INTERRUPT);
>  	if (!desc)
>  		return -ENOMEM;



[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux