OF_FINDDEVICE(9)
π OF_FINDDEVICE(9) β like, the device-tree finder bestie
okay so this is a page from the Kernel Developer's Manual (section 9, kernel girlies only β¨) and it's all about OF_finddevice β the little function that goes hunting for a node in the device tree π³π
β¨ NAME β¨
OF_finddevice β find node in device tree π¦
πΈ SYNOPSIS πΈ
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
phandle_t
OF_finddevice(const char *path);
like, yes, you need both headers. iconic of them tbh π
π DESCRIPTION π
OF_finddevice() returns the phandle for the node specified by the path. That's it, that's the whole vibe π«Ά
Returns -1 if the path cannot be found in the tree. no node, no phandle, no slay π
π§ EXAMPLES π§
phandle_t root, i2c;
root = OF_finddevice("/");
i2c = OF_finddevice("/soc/axi/i2c@a0e0000");
if (i2c != -1) {
...
}
see how it's done?? find the root, find the i2c node, then check it isn't -1 before you touch it. main character energy fr fr π
π₯ SEE ALSO π₯
the whole device-tree friend group, we love a supporting cast π
π AUTHORS π
This manual page was written by Oleksandr Tymoshenko <gonzo@FreeBSD.org>. ty for the lore bestie ππ«Ά
π CAVEATS π
okay this is the important bit, pay attention, no cap:
The return value should only be checked with equality operators (equal to, not equal to) and not relational comparison (less than, greater than). π¨
There is a discrepancy between IEEE 1275 standard and FreeBSD's internal representation of a phandle: IEEE 1275 requires the return value of this function to be -1 if the path is not found. But phandle_t is an unsigned type, so it cannot be relationally compared with -1 or 0 β this comparison is always true or always false. π
so like...==and!=are your besties here,<and>are lowkey lying to you. it's giving unsigned type behaviour, and it is NOT the moment for relational comparisons, periodt π
anyway that's the whole page, hope you found your node π¦πΈβ β written by the Debian crew, dated April 9, 2018, and that's the whole footer moment, mwah πβ¨π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2018 Oleksandr Tymoshenko <gonzo@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms