usb_sg_init(9)
π« usb_sg_init β the Kernel API Manual glow-up π«
okay so bestie, welcome to usb_sg_init(9) from the Kernel API Manual β this is the function that initializes scatterlist-based bulk/interrupt I/O requests and honestly? it's kind of the moment. π
β¨ SYNOPSIS β¨
int usb_sg_init (struct usb_sg_request *io , struct usb_device *dev ,
unsigned pipe , unsigned period , struct scatterlist *sg , int nents ,
size_t length , gfp_t mem_flags );
like yes that's a lot of parameters, breathe, we're gonna go through every single one π
π¦ ARGUMENTS π¦
ioβ the request block that's being initialized. real talk: untilusb_sg_waitreturns, you gotta treat this as a pointer to an opaque block of memory. no peeking, no cap πdevβ the usb device that's gonna send or receive the data. the main character of this whole operation, frpipeβ the endpoint "pipe" used to transfer the data. the lil delivery chute πperiodβ the polling rate for interrupt endpoints, in frames or (for high speed endpoints) microframes; it's ignored for bulk, so don't stress about it if you're doing bulk i/o, bestie π«Άsgβ the scatterlist entries. this is the whole point of the function honestlynentsβ how many entries are in that scatterlist. gotta know the count, iykyklengthβ how many bytes to send from the scatterlist, or zero to send every byte identified in the list. zero = send it all, iconic behavior πmem_flagsβ theSLAB_*flags affecting memory allocations in this call. memory allocation vibes set here β¨
π DESCRIPTION π
so this initializes a scatter/gather request, allocating resources such as I/O mappings and urb memory (except maybe memory used by USB controller drivers). it's giving "getting everything ready for you before the real work starts" π
the request must be issued using usb_sg_wait, which waits for the I/O to complete (or to be canceled) and then cleans up all resources allocated by usb_sg_init. so like, usb_sg_wait is the responsible friend who cleans up after the party π§Ή
the request may be canceled with usb_sg_cancel, either before or after usb_sg_wait is called. flexible queen behavior honestly π
β RETURN β
zero for success, else a negative errno value. simple as that, no notes π
π₯ SEE ALSO π₯
kernel file ./drivers/usb/core/message.c plus the whole friend group:
usb_control_msg(9)usb_control_msg_send(9)usb_control_msg_recv(9)usb_interrupt_msg(9)usb_bulk_msg(9)usb_bulk_msg_killable(9)usb_sg_wait(9)usb_sg_cancel(9)usb_get_descriptor(9)usb_get_string(9)usb_string(9)usb_cache_string(9)usb_get_status(9)usb_clear_halt(9)usb_disable_endpoint(9)usb_reset_endpoint(9)usb_disable_interface(9)usb_disable_device(9)usb_enable_endpoint(9)usb_enable_interface(9)usb_set_interface(9)usb_reset_configuration(9)usb_set_wireless_status(9)usb_driver_set_configuration(9)cdc_parse_cdc_header(9)
like, the whole squad showed up for this one π«π
bestie reminder:usb_sg_initdoes not clean up after itself β that's onusb_sg_wait. don't leave your resources hanging, that's not the vibe π
and that's the tea! π this page lives in ./drivers/usb/core, dated October 2026, and we out here shipping usb_sg_init(9) into your brain. slay, go write some scatter/gather i/o, you're doing amazing β¨ππ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms