efi_get_device_by_path(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– efi_get_device_by_path(9) πŸ’–

okay so this is a page from the Kernel API Manual β€” it's efi_get_device_by_path(9), and yes it's as iconic as it sounds πŸ”₯


✨ NAME ✨

efi_get_device_by_path β€” find device by EFI Device Path πŸ¦‹


🌸 SYNOPSIS 🌸

struct device * efi_get_device_by_path (const struct efi_dev_path **node
, size_t *len );

πŸŽ€ ARGUMENTS πŸŽ€

  • node β€” the EFI Device Path, bestie. That's the thing you're handing over.
  • len β€” maximum length of the EFI Device Path, in bytes. Like, the byte budget πŸ’…

πŸ‘‘ DESCRIPTION πŸ‘‘

So what it does is: it parses a whole series of EFI Device Path nodes sitting at node and goes looking for the corresponding device. Literally a scavenger hunt.

If the device was found, its reference count gets incremented and you get a pointer to it back. Pickup line: the caller needs to drop that reference with put_device after use. Don't ghost it, fr fr β€” that's a leak.

The node pointer also gets updated to point to the location immediately after the "End of Hardware Device Path" node. Slay, moving on.

If another Device Path instance follows, len is decremented by the number of bytes consumed. Otherwise len is set to 0. Simple as.

If a Device Path node is malformed or its corresponding device is not found, node is updated to point at this offending node and an ERR_PTR is returned. Rude but fair πŸ™ˆ

And here's the cute bit β€” if len is initially 0, the function returns NULL. So to iterate over all instances in a path, this idiom is what you use:

while (!IS_ERR_OR_NULL(dev = efi_get_device_by_path(node, len))) { // do something with dev put_device(dev); } if (IS_ERR(dev)) // report error
Lowkey important: devices can only be found if they're already instantiated. Most buses instantiate devices in the "subsys" initcall level, hence the earliest initcall level in which this function should be called is "fs". No skipping ahead, bestie ⭐

Returns the device on success, or ERR_PTR(-ENODEV) if no device was found, ERR_PTR(-EINVAL) if a node is malformed or exceeds len, and ERR_PTR(-ENOTSUPP) if support for a node type is not yet implemented. The way these error codes are all just sitting there waiting for you 😭


πŸ’œ SEE ALSO πŸ’œ

  • Kernel file ./drivers/firmware/efi/dev-path-parser.c β€” go read it, it's giving main character energy 🌈

kisses, this page lived in ./drivers/firmware/efi, stamped October 2026, and its whole name is efi_get_device_by_path(9) πŸ’…βœ¨πŸ«Ά

πŸ“¦ where this page comes from