snd_devm_card_new(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

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 before snd_card_register is called and there have been other devres resources, you’d need to free the card manually via snd_card_free call in the error; otherwise it may lead to UAF due to devres call orders. You can use snd_card_free_on_error helper 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