of_parse_phandle_with_args(9)
๐ 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 callof_node_puton the returnedout_args->nppointer. 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:
of_node_init(9)of_machine_is_compatible(9)of_parse_phandle(9)of_parse_phandle_with_fixed_args(9)of_parse_phandle_with_optional_args(9)of_phandle_args_equal(9)of_property_count_u8_elems(9)of_property_count_u16_elems(9)of_property_count_u32_elems(9)of_property_count_u64_elems(9)of_property_read_string_array(9)of_property_count_strings(9)of_property_read_string_index(9)of_property_present(9)of_property_read_u8_array(9)of_property_read_u16_array(9)of_property_read_u32_array(9)of_property_read_u64_array(9)struct of_changeset_entry(9)struct of_changeset(9)of_device_is_system_power_controller(9)of_have_populated_dt(9)
๐ and that's the page!! shipped straight out of./include/linux, dated October 2026, in theKernel API Manual. go read the source, callof_node_put, and slay ๐ ๐๐ฆ
๐ฆ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms