OF_FINDDEVICE(9)
π OF_FINDDEVICE(9) π
okay bestie, this is a Kernel Developer's Manual page, section 9, and we're talking about OF_finddevice π
πΈ NAME πΈ
OF_finddevice β find a node in the device tree π
β¨ SYNOPSIS β¨
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
phandle_t
OF_finddevice(const char *path);
π¦ DESCRIPTION π¦
So basically, OF_finddevice() hands you back the phandle for whatever node the path points at. That's it, that's the whole vibe. π
But if that path literally cannot be found anywhere in the tree? It returns -1. Not found, bestie, it's giving ghosted. π»
π CAVEATS π
okay this part is important, no cap, please actually read it π
The return value should only be checked with equality operators β equal to, not equal to β and never with relational comparison (less than, greater than). Like, do not do that. Periodt.
Here's the tea β: there's a whole discrepancy between the IEEE 1275 standard and FreeBSD's internal representation of a phandle. IEEE 1275 requires that the return value of this function be -1 when the path isn't found. But here's the plot twist β phandle_t is an unsigned type, so it literally cannot be relationally compared with -1 or 0. That comparison is always true or always false. π Every single time. It's a trap and it will not warn you. π©
β οΈ fr fr: use==and!=only. Relational operators on this return value are undefined nonsense dressed up as logic. π
π EXAMPLES π
phandle_t root, i2c;
root = OF_finddevice("/");
i2c = OF_finddevice("/soc/axi/i2c@a0e0000");
if (i2c != -1) {
...
}
see how the check is !=? that's the equality-operator energy we were just talking about. main character move. π
π«Ά SEE ALSO π«Ά
π AUTHORS π
This manual page was written by Oleksandr Tymoshenko <gonzo@FreeBSD.org> π
that's the whole page, bestie β go forth and find your devices. the Debian version of this lil cutie landed on April 9, 2018, and it's filed under OF_FINDDEVICE(9). mwah π
β¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2018 Oleksandr Tymoshenko <gonzo@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms