Re: [PATCH v3 1/3] usb: core: add dma-noncoherent buffer alloc and free API
From: Andy Shevchenko
Date: Wed Jul 02 2025 - 08:20:56 EST
On Wed, Jul 02, 2025 at 07:02:20PM +0800, Xu Yang wrote:
> This will add usb_alloc_noncoherent() and usb_free_noncoherent()
> functions to support alloc and free buffer in a dma-noncoherent way.
>
> To explicit manage the memory ownership for the kernel and device,
> this will also add usb_dma_noncoherent_sync_for_cpu/device() functions
> and call it at proper time. The management requires the user save
> sg_table returned by usb_alloc_noncoherent() to urb->sgt.
...
> + if ((urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) &&
> + urb->sgt) {
Something weird with the indentation. Here you wrapped, but the very next line
is not, and they both satisfy 80 limit (even though we have it relaxed now).
> + dma_sync_sgtable_for_cpu(hcd->self.sysdev, urb->sgt, dir);
> + if (dir == DMA_FROM_DEVICE)
> + invalidate_kernel_vmap_range(urb->transfer_buffer,
> + urb->transfer_buffer_length);
> + }
...
> +
> + return ret;
> }
> +
> + if ((urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) &&
> + urb->sgt) {
Why not
} else if {
and drop the above return ret; ?
> + if (dir == DMA_TO_DEVICE)
> + flush_kernel_vmap_range(urb->transfer_buffer,
> + urb->transfer_buffer_length);
> + dma_sync_sgtable_for_device(hcd->self.sysdev, urb->sgt, dir);
> + }
> +
> return ret;
--
With Best Regards,
Andy Shevchenko