[PATCH v3 02/13] dma-mapping: Force bouncing if the kmalloc() size is not cacheline-aligned

Christoph Hellwig hch at lst.de
Mon Nov 7 01:43:55 PST 2022


> +/*
> + * Check whether the given size, assuming it is for a kmalloc()'ed object, is
> + * safe for non-coherent DMA or needs bouncing.
> + */
> +static inline bool dma_kmalloc_needs_bounce(struct device *dev, size_t size,
> +					    enum dma_data_direction dir)
> +{
> +	/*
> +	 * No need for bouncing if coherent DMA or the direction is
> +	 * DMA_TO_DEVICE.
> +	 */
> +	if (!IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) ||
> +	    dir == DMA_TO_DEVICE || dev_is_dma_coherent(dev))

Minor nit, but for clarify I'd preper to split the generaly availabily
checks from the direction one, i.e.:

	if (dev_is_dma_coherent(dev) ||
	    !IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC))
		return false;

	if (dir == DMA_TO_DEVICE)
		return false;



More information about the linux-arm-kernel mailing list