spi_alloc_device(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… spi_alloc_device β€” the Kernel API Manual page, bestie edition ✨

okay so real talk, this is a page from the Kernel API Manual, and it's about spi_alloc_device β€” yes that's the whole title, we're not doing a subtitle, the manual name is literally just Kernel API Manual. Sit down, hydrate, and let's get into it 🫢


🌸 NAME 🌸

spi_alloc_device β€” allocate a new SPI device, no cap πŸŽ€


✨ SYNOPSIS ✨

struct spi_device * spi_alloc_device (struct spi_controller *ctlr );

look at her go. one function, one pointer in, one pointer out πŸ’…


πŸ¦‹ ARGUMENTS πŸ¦‹

  • ctlr β€” the controller that this device is connected to. like, the whole vibe is which controller, that's the info you're giving it 🌈

🌸 CONTEXT 🌸

can sleep 😴 β€” okay so this one is allowed to nap. she's not in a hurry. plan accordingly, don't call her from somewhere you can't sleep, iykyk.


πŸ‘‘ DESCRIPTION πŸ‘‘

so here's the thing β€” this function lets a driver allocate and initialize a spi_device without registering it immediately. iconique. it's giving "buy the outfit now, wear it later" πŸŽ€

that delay is the whole point: it means a driver can directly fill that spi_device in with device parameters before calling spi_add_device on it. get her dressed first, then send her out πŸ’…

now, the caller is responsible β€” and i mean responsible β€” for calling spi_add_device on the returned spi_device structure so it actually gets added to the SPI controller. no ghost devices, bestie πŸ‘»

but what if you changed your mind and need to discard that spi_device without adding it? totally valid, we support the decision. in that case you call spi_dev_put on it. that's the clean-up, don't skip the clean-up, the kernel will notice 🫢


⭐ RETURN ⭐

a pointer to the new device, or NULL. so like... check it. seriously. NULL is a real possible outcome here, fr fr πŸ”₯


πŸ’œ SEE ALSO πŸ’œ

this list is long and honestly she ate, so we're listing every single one of them, no skips 🧚

oh and before the function refs β€” this all lives in the kernel file ./drivers/spi/spi.c πŸ“

like. forty-five of them. she's thorough and we respect it πŸ‘‘


quick vibe check before you close the tab: if you got a device back and you're not adding it, spi_dev_put it. that's it. that's the PSA πŸ’–

and that's the page!! this one came out of ./drivers/spi and it's dated October 2026 β€” shoutout to the section and the date, they're doing great, periodt πŸŒŸπŸ’…

πŸ“¦ where this page comes from