get_dev_from_fwnode(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– get_dev_from_fwnode β€” Kernel API Manual ✨

okay so bestie, welcome to the get_dev_from_fwnode(9) page πŸ’… this one lives in the Kernel API Manual, and it's short but it has lore, so buckle up πŸŽ€


🌸 NAME 🌸

get_dev_from_fwnode β€” grab yourself a reference count of the struct device that a struct fwnode_handle is associated with 🫢


✨ SYNOPSIS ✨

struct device * get_dev_from_fwnode (struct fwnode_handle *fwnode );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • fwnode β€” the pointer to the struct fwnode_handle that you wanna obtain the struct device reference count of πŸ‘‘

πŸ”₯ DESCRIPTION πŸ”₯

So what this function does: it obtains a reference count of the device that the device pointer embedded in the struct fwnode_handle points to 🌈

Now here's the part where you gotta pay attention, bestie, because it's giving plot twist 😭

⚠️ Heads up: the struct device pointer embedded in struct fwnode_handle does not have a reference count of the struct device itself.

Which means… yeah. It is a UAF (and thus a bug πŸ’€) to call this function if the caller can't guarantee that the last reference count of the corresponding struct device is not dropped concurrently. Not me being dramatic β€” that's literally the rule πŸ™ˆ

How is that even possible? Because struct fwnode_handle has its own reference count, and hence it can out-live the struct device it is associated with ⭐ so like, the fwnode is still out here thriving while the device is gone. main character energy, but make it a memory-safety problem πŸ’…


πŸ‘‘ SEE ALSO πŸ‘‘

Kernel file ./drivers/base/core.c β€” and literally all of these, no cap, I'm not skipping a single one πŸ“


and that's the whole page, bestie 🧚✨ it's from ./drivers/base, dated October 2026, filed under the Kernel API Manual β€” anyway ily, go get that reference count (safely!!) πŸ’œπŸŽ€

πŸ“¦ where this page comes from