device_link_add(9)
π device_link_add β a Kernel API Manual moment π
okay bestie, welcome to the <pink>Kernel API Manual</pink> page for device_link_add(9) β¨ this one's all about setting up a relationship between two devices, and honestly it's giving matchmaker energy π«Ά
πΈ NAME πΈ
device_link_add β Create a link between two devices. literally just pairing them up π
β¨ SYNOPSIS β¨
struct device_link * device_link_add (struct device *consumer , struct
struct device *supplier , u32 flags );
no cap, that's the whole signature β three args, one pointer back π
π¦ ARGUMENTS π¦
consumerβ the consumer end of the link, aka the one doing the consuming πsupplierβ the supplier end of the link, aka the one providing πflagsβ the link flags, this is where all the personality lives β
π RETURN π
On success you get a device_link struct handed right back to you π but on error, or if the flag settings are invalid, you get NULL. sad but true π NULL is the vibe check fail.
π DESCRIPTION π
okay so first thing, and this is important: the caller is responsible for the proper synchronization of the link creation with runtime PM. that's on you, bestie, nobody's coming to save you π
First up: setting the DL_FLAG_PM_RUNTIME flag will cause the runtime PM framework to take the link into account. β¨
Second: if the DL_FLAG_RPM_ACTIVE flag is set in addition to it, the supplier devices will be forced into the active meta state and reference-counted upon the creation of the link. π₯ And listen β if DL_FLAG_PM_RUNTIME is not set, then DL_FLAG_RPM_ACTIVE will be ignored. like, fully ignored, it just doesn't get a turn π
If DL_FLAG_STATELESS is set in flags, the caller of this function is expected to release the link returned by it directly with the help of either device_link_del or device_link_remove. π
If that flag is not set, however, the caller of this function is handing the management of the link over to the driver core entirely, and its return value can only be used to check whether or not the link is present. In that case, the DL_FLAG_AUTOREMOVE_CONSUMER and DL_FLAG_AUTOREMOVE_SUPPLIER device link flags can be used to indicate to the driver core when the link can be safely deleted. π
Namely β setting one of them in flags indicates to the driver core that the link is not going to be used (by the given caller of this function) after unbinding the consumer or supplier driver, respectively, from its device, so the link can be deleted at that point.
And if none of them is set, the link will be maintained until one of the devices pointed to by it (either the consumer or the supplier) is unregistered. fr fr, it just hangs around. π¦
Also! If DL_FLAG_STATELESS, DL_FLAG_AUTOREMOVE_CONSUMER and DL_FLAG_AUTOREMOVE_SUPPLIER are not set in flags (that is, a persistent managed device link is being added), the DL_FLAG_AUTOPROBE_CONSUMER flag can be used to request the driver core to automatically probe for a consumer driver after successfully binding a driver to the supplier device. that's the good stuff β¨
β οΈ the invalid combo, pay attention bestie β the combination ofDL_FLAG_STATELESSand one ofDL_FLAG_AUTOREMOVE_CONSUMER,DL_FLAG_AUTOREMOVE_SUPPLIER, orDL_FLAG_AUTOPROBE_CONSUMERset inflagsat the same time is invalid and will causeNULLto be returned upfront. π
However β and this is the plot twist β if a device link between the given consumer and supplier pair exists already when this function is called for them, the existing link will be returned regardless of its current type and status (the link's flags may be modified then). π The caller of this function is then expected to treat the link as though it has just been created, so (in particular) if DL_FLAG_STATELESS was passed in flags, the link needs to be released explicitly when not needed any more (as stated above). don't forget it, i'm begging π«Ά
A side effect of the link creation is re-ordering of dpm_list and the devices_kset list by moving the consumer device and all devices depending on it to the ends of these lists (that does not happen to devices that have not been registered when this function is called). πΈ like, they get moved to the back of the line, respectfully.
The supplier device is required to be registered when this function is called and NULL will be returned if that is not the case. π¨ The consumer device need not be registered, however. main character supplier energy only π
π₯ SEE ALSO π₯
so many friends, so many cross-references, i'm obsessed with how thorough this is π§
Kernel file ./drivers/base/core.c:
__fwnode_link_add(9)__fwnode_link_del(9)__fwnode_link_cycle(9)fwnode_links_purge_suppliers(9)fwnode_links_purge_consumers(9)fwnode_links_purge(9)__fwnode_links_move_consumers(9)__fw_devlink_pickup_dangling_consumers(9)fw_devlink_refresh_fwnode(9)device_is_dependent(9)device_pm_move_to_tail(9)device_link_wait_removal(9)device_link_del(9)device_link_remove(9)device_links_check_suppliers(9)__device_links_queue_sync_state(9)device_links_flush_sync_list(9)device_links_force_bind(9)device_links_driver_bound(9)__device_links_no_driver(9)device_links_no_driver(9)device_links_driver_cleanup(9)device_links_busy(9)device_links_unbind_consumers(9)device_links_purge(9)wait_for_init_devices_probe(9)fwnode_is_ancestor_of(9)fwnode_get_next_parent_dev(9)__fw_devlink_relax_cycles(9)fw_devlink_create_devlink(9)__fw_devlink_link_to_consumers(9)__fw_devlink_link_to_suppliers(9)dev_driver_string(9)device_release(9)devm_device_add_group(9)devices_kset_move_before(9)devices_kset_move_after(9)devices_kset_move_last(9)device_create_file(9)device_remove_file(9)device_remove_file_self(9)device_create_bin_file(9)device_remove_bin_file(9)device_initialize(9)kobject_has_children(9)dev_set_name(9)device_add(9)device_register(9)get_device(9)put_device(9)device_del(9)device_unregister(9)device_get_devnode(9)device_for_each_child(9)device_for_each_child_reverse(9)device_for_each_child_reverse_from(9)device_find_child(9)device_offline(9)device_online(9)__root_device_register(9)root_device_unregister(9)device_create(9)device_create_with_groups(9)device_destroy(9)device_rename(9)device_move(9)device_change_owner(9)device_shutdown(9)dev_err_probe(9)dev_warn_probe(9)set_primary_fwnode(9)set_secondary_fwnode(9)device_remove_of_node(9)device_add_of_node(9)device_set_of_node_from_dev(9)get_dev_from_fwnode(9)
and that's the whole page, bestie π this one came from ./drivers/base and it's dated October 2026 β so go forth, link those devices, and don't forget to release your DL_FLAG_STATELESS links πβ¨
π¦ 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