usb_alloc_coherent(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸŽ€ usb_alloc_coherent(9) β€” Kernel API Manual πŸŽ€

🌸 NAME 🌸

usb_alloc_coherent β€” allocate a dma-consistent buffer for URB_NO_xxx_DMA_MAP. that’s the whole assignment, bestie πŸ’…


✨ SYNOPSIS ✨

okay so the signature is literally:

void * usb_alloc_coherent (struct usb_device *dev , size_t size , gfp_t
       mem_flags , dma_addr_t *dma );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • dev β€” the device the buffer will be used with 🫢
  • size β€” requested buffer size, no cap
  • mem_flags β€” affect whether allocation may block πŸ‘€
  • dma β€” used to return DMA address of buffer ✨

πŸ’– RETURN πŸ’–

so it returns either null β€” which means no buffer could be allocated, sad β€” or the cpu-space pointer to a buffer that may be used to perform DMA to the specified device. those cpu-space buffers come back along with the DMA address (through the pointer you provided), periodt πŸ’…


πŸ”₯ NOTE πŸ”₯

these buffers are used with URB_NO_xxx_DMA_MAP set in urb->transfer_flags to avoid behaviors like using β€œDMA bounce buffers”, or thrashing IOMMU hardware during URB completion/resubmit. the implementation varies between platforms, depending on details of how DMA will work to this device. using these buffers also eliminates cacheline sharing problems on architectures where CPU caches are not DMA-coherent. on systems without bus-snooping caches, these buffers are uncached.

when the buffer is no longer used, free it with usb_free_coherent. don’t leave it hanging, bestie 😭


🌈 SEE ALSO 🌈

Kernel file ./drivers/usb/core/usb.c plus the whole linked-up crew:

mwah πŸ’‹ β€” source/version ./drivers/usb/core, dated October 2026, page usb_alloc_coherent(9). byeee 🫢

πŸ“¦ where this page comes from