spi_alloc_device(9)
π 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 π
__spi_register_driver(9)spi_add_device(9)spi_new_device(9)spi_unregister_device(9)spi_register_board_info(9)spi_res_alloc(9)spi_res_free(9)spi_res_add(9)spi_res_release(9)spi_finalize_current_transfer(9)__spi_pump_messages(9)spi_pump_messages(9)spi_take_timestamp_pre(9)spi_take_timestamp_post(9)spi_set_thread_rt(9)spi_get_next_queued_message(9)spi_finalize_current_message(9)spi_queued_transfer(9)spi_flush_queue(9)of_register_spi_devices(9)spi_new_ancillary_device(9)devm_spi_new_ancillary_device(9)acpi_spi_count_resources(9)acpi_spi_device_alloc(9)spi_target_abort(9)__spi_alloc_controller(9)__devm_spi_alloc_controller(9)spi_get_gpio_descs(9)spi_register_controller(9)devm_spi_register_controller(9)spi_unregister_controller(9)spi_replace_transfers(9)spi_split_transfers_maxsize(9)spi_split_transfers_maxwords(9)spi_set_cs_timing(9)spi_setup(9)spi_optimize_message(9)spi_unoptimize_message(9)devm_spi_optimize_message(9)spi_async(9)spi_sync(9)spi_sync_locked(9)spi_bus_lock(9)spi_bus_unlock(9)spi_write_then_read(9)
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
- 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