of_parse_phandle_with_args(9)

๐Ÿ“ฆ version 7.3.1, in nixpkgs unstable

๐Ÿ’… of_parse_phandle_with_args(9) โ€” from the Kernel API Manual, bestie ๐ŸŽ€

okay so we're doing kernel device-tree stuff today and honestly? it's giving main character energy โœจ stay with me, this one's actually so good once it clicks.


๐ŸŒธ NAME ๐ŸŒธ

of_parse_phandle_with_args โ€” find a node pointed by a phandle in a list ๐Ÿ”๐Ÿ’–


โœจ SYNOPSIS โœจ

int of_parse_phandle_with_args (const struct device_node *np , const
       char *list_name , const char *cells_name , int index , struct
       of_phandle_args *out_args );

like, five args, one int back, no cap ๐Ÿซถ


๐Ÿฆ‹ ARGUMENTS ๐Ÿฆ‹

  • np โ€” pointer to a device tree node containing a list. this is the node you're snooping through, the one that's holding the list ๐Ÿ‘€
  • list_name โ€” property name that contains a list. literally just tell it which property to look at, bestie ๐Ÿ’…
  • cells_name โ€” property name that specifies phandles' arguments count. it's the property that says how many arg cells each phandle gets ๐Ÿงฎ
  • index โ€” index of a phandle to parse out. which one in the list you want, zero-indexed obviously ๐Ÿ™ˆ
  • out_args โ€” optional pointer to output arguments structure (will be filled). optional!! but if you pass it, it will get filled, that's the whole vibe โญ

๐Ÿ”ฅ DESCRIPTION ๐Ÿ”ฅ

so this function is useful to parse lists of phandles and their arguments. that's the whole job, and it ate ๐Ÿ’€โœจ

it returns 0 on success and fills out_args, and on error it returns the appropriate errno value. simple as that, fr fr.

โš ๏ธ important one, do not skip this: the caller is responsible to call of_node_put on the returned out_args->np pointer. like, that's on you, bestie. don't leave that node hanging ๐Ÿ˜ญ๐Ÿ”’

here's the example, and yes it's iconic:

 phandle1: node1 {
     #list-cells = <2>;
 };

 phandle2: node2 {
     #list-cells = <1>;
 };

 node3 {
     list = <phandle1 1 2 phandle2 3>;
 };

so node1 says its phandles carry 2 argument cells (#list-cells = <2>;), and node2 says its carry 1 (#list-cells = <1>;). then node3 has the actual list property: <phandle1 1 2 phandle2 3>. see how phandle1 grabs two values (1 2) and phandle2 grabs one (3)? that's the whole system working exactly as intended ๐Ÿ‘‘

so to get a device_node of the node2 node you may call this:

of_parse_phandle_with_args(node3, "list", "#list-cells", 1, args);

index 1 โ†’ node2. periodt ๐Ÿ’œ


๐Ÿ’– SEE ALSO ๐Ÿ’–

kernel file ./include/linux/of.h, plus the whole friend group:


๐ŸŒˆ and that's the page!! shipped straight out of ./include/linux, dated October 2026, in the Kernel API Manual. go read the source, call of_node_put, and slay ๐Ÿ’…๐ŸŽ€๐Ÿฆ‹
๐Ÿ“ฆ where this page comes from