snd_devm_card_new(9)
okay bestie π welcome to the snd_devm_card_new(9) page from the Kernel API Manual β section 9, kernel API edition. this one is all about making a managed snd_card object, and yes itβs giving βlet devres handle the cleanupβ energy β¨
NAME π
snd_devm_card_new β managed snd_card object creation.
SYNOPSIS β¨
int snd_devm_card_new (struct device *parent , int idx , const char *xid
, struct module *module , size_t extra_size , struct snd_card **card_ret
);
ARGUMENTS π«Ά
parentβ the parent device object.idxβ card index (address), and the range is[0 ... (SNDRV_CARDS-1)].xidβ card identification (ASCII string).moduleβ top level module for locking.extra_sizeβ allocate this extra size after the main soundcard structure.card_retβ the pointer to store the created card instance.
DESCRIPTION π
This function works like snd_card_new, but it manages the allocated resource via devres, i.e. you donβt need to free explicitly. literally the whole point, and it ate.
When a snd_card object is created with this function and registered via snd_card_register, the very first devres action to call snd_card_free is added automatically. In that way, the resource disconnection is assured at first, then released in the expected order. no cap, that ordering matters.
β οΈ bestie, listen: if an error happens at the probe beforesnd_card_registeris called and there have been other devres resources, youβd need to free the card manually viasnd_card_freecall in the error; otherwise it may lead to UAF due to devres call orders. You can usesnd_card_free_on_errorhelper for handling it more easily. this is the βplease donβt rawdog the error pathβ warning π«Ά
RETURN π
zero if successful, or a negative error code.
SEE ALSO π
Kernel file ./sound/core/init.c and the whole squad: snd_device_alloc(9), snd_card_new(9), snd_card_free_on_error(9), snd_card_ref(9), snd_card_disconnect(9), snd_card_disconnect_sync(9), snd_card_free_when_closed(9), snd_card_free(9), snd_card_set_id(9), snd_card_add_dev_attr(9), snd_card_register(9), snd_component_add(9), snd_card_file_add(9), snd_card_file_remove(9), snd_power_ref_and_wait(9), snd_power_wait(9).
okay thatβs the whole page π byeee! this one lives in ./sound/core, dated October 2026, and yeah β snd_devm_card_new(9) is the manual-page main character π
π¦ 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