__spi_alloc_controller(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– __spi_alloc_controller(9) πŸ’–

okay so bestie, we're in the Kernel API Manual and this is the page for __spi_alloc_controller(9) β€” the little function that gets you an SPI host or target controller. yes it's a double-underscore name, no I don't know why, we don't ask questions, we just read the docs. πŸŽ€


✨ NAME ✨

__spi_alloc_controller β€” allocate an SPI host or target controller 🌸


πŸ¦‹ SYNOPSIS πŸ¦‹

struct spi_controller * __spi_alloc_controller (struct device *dev ,
       unsigned int size , bool target );

πŸ’… ARGUMENTS πŸ’…

  • dev β€” the controller, possibly using the platform_bus. that's your device bestie 🫢
  • size β€” how much zeroed driver-private data to allocate. the pointer to this memory lives in the driver_data field of the returned device, and you get at it with spi_controller_get_devdata. the memory is cacheline aligned. and listen β€” if you're a driver granting DMA access to portions of your private data, you gotta round up the size using ALIGN(size, dma_get_cache_alignment). do not skip that step, it's giving important ✨
  • target β€” flag saying whether to allocate an SPI host controller (false) or an SPI target controller (true). pick your fighter πŸ’€

😴 CONTEXT 😴

can sleep. like, it's allowed to sleep. nap-friendly function, we love to see it πŸ›ŒπŸ’€


πŸ‘‘ DESCRIPTION πŸ‘‘

k so this call is only used by SPI controller drivers β€” the ones that are literally the only ones directly touching chip registers. it's how they allocate an spi_controller structure, before they call spi_register_controller. main character energy but in a "you had to be there" way πŸ’«

this must be called from context that can sleep. no cap. πŸ”₯

the caller is responsible for:

  • assigning the bus number
  • initializing the controller's methods

…before calling spi_register_controller. and also for calling spi_controller_put to prevent a memory leak when you're done with the controller. yes, you. memory leaks are not cute, bestie πŸ˜­πŸ™ˆ


πŸ“ RETURN πŸ“

the SPI controller structure on success β€” else NULL. that's it. that's the whole vibe check 🧚


🌈 SEE ALSO 🌈

the Kernel file ./drivers/spi/spi.c, plus literally this whole friend group:

iykyk πŸ’œ


anyway that's the page!! sourced from ./drivers/spi, dated October 2026, filed under __spi_alloc_controller(9) β€” love that for us, mwah, go allocate responsibly πŸŽ€πŸ’–βœ¨

πŸ“¦ where this page comes from