checks: Add an interrupt-map check
PATCH 1/2 checks: Add an interrupt-map check
Add a check for parsing 'interrupt-map' properties. The check primarily tests parsing 'interrupt-map' properties which depends on and the parent interrupt controller (or another map) node.
Note that this does not require '#address-cells' in the interrupt-map parent, but treats missing '#address-cells' as 0 which is how the Linux kernel parses it. There's numerous cases that expect this behavior.
---
v3:
- Exit check on unresolved phandle when an overlay
v2:
- Rework '#interrupt-cells' and '#address-cells' checks to rely on other checks (interrupt_provider and addr_size_cells)
--- checks.c | 85 ++++++++++++++++++++++++++++++ tests/bad-interrupt-map-mask.dts | 20 +++++++ tests/bad-interrupt-map-parent.dts | 17 ++++++ tests/bad-interrupt-map.dts | 19 +++++++ tests/run_tests.sh | 3 ++ 5 files changed, 144 insertions(+) create mode 100644 tests/bad-interrupt-map-mask.dts create mode 100644 tests/bad-interrupt-map-parent.dts create mode 100644 tests/bad-interrupt-map.dts
checks.c +85 -0
@@ -1590,6 +1590,90 @@ static void check_interrupt_provider(struct check *c, }WARNING (interrupt_provider, check_interrupt_provider,NULL , &interrupts_extended_is_cell); +static void check_interrupt_map (struct check *c, +struct dt_info *dti, +struct node *node) +{ +struct node *root = dti->dt; +struct property *prop, *irq_map_prop; +size_t cellsize, cell, map_cells; + + irq_map_prop =get_property (node,"interrupt-map" ); +if (!irq_map_prop) +return ; + +if (node->addr_cells <0 ) { +FAIL (c, dti, node, +"Missing '#address-cells' in interrupt-map provider" ); +return ; + } + cellsize =node_addr_cells (node); + cellsize +=propval_cell (get_property (node,"#interrupt-cells" )); + + prop =get_property (node,"interrupt-map-mask" ); +if (prop && (prop->val.len != (cellsize *sizeof (cell_t)))) +FAIL_PROP (c, dti, node, prop, +"property size (%d) is invalid, expected %zu" , + prop->val.len, cellsize *sizeof (cell_t)); + +if (!is_multiple_of (irq_map_prop->val.len,sizeof (cell_t))) { +FAIL_PROP (c, dti, node, irq_map_prop, +"property size (%d) is invalid, expected multiple of %zu" , + irq_map_prop->val.len,sizeof (cell_t)); +return ; + } + + map_cells = irq_map_prop->val.len /sizeof (cell_t); +for (cell =0 ; cell < map_cells; ) { +struct node *provider_node; +struct property *cellprop; +int phandle; +size_t parent_cellsize; + +if ((cell + cellsize) >= map_cells) { +FAIL_PROP (c, dti, node, irq_map_prop, +"property size (%d) too small, expected > %zu" , + irq_map_prop->val.len, (cell + cellsize) *sizeof (cell_t)); +break ; + } + cell += cellsize; + + phandle =propval_cell_n (irq_map_prop, cell); +if (!phandle_is_valid (phandle)) { +/* Give up if this is an overlay with external references */ +if (!(dti->dtsflags &DTSF_PLUGIN )) +FAIL_PROP (c, dti, node, irq_map_prop, +"Cell %zu is not a phandle(%d)" , + cell, phandle); +break ; + } + + provider_node =get_node_by_phandle (root, phandle); +if (!provider_node) { +FAIL_PROP (c, dti, node, irq_map_prop, +"Could not get phandle(%d) node for (cell %zu)" , + phandle, cell); +break ; + } + + cellprop =get_property (provider_node,"#interrupt-cells" ); +if (cellprop) { + parent_cellsize =propval_cell (cellprop); + }else { +FAIL (c, dti, node,"Missing property '#interrupt-cells' in node %s or bad phandle (referred from interrupt-map[%zu])" , + provider_node->fullpath, cell); +break ; + } + + cellprop =get_property (provider_node,"#address-cells" ); +if (cellprop) + parent_cellsize +=propval_cell (cellprop); + + cell +=1 + parent_cellsize; + } +} +WARNING (interrupt_map, check_interrupt_map,NULL , &phandle_references, &addr_size_cells, &interrupt_provider); +static void check_interrupts_property (struct check *c,struct dt_info *dti,struct node *node)
@@ -1888,6 +1972,7 @@ static struct check *check_table[] = { &gpios_property, &interrupts_property, &interrupt_provider, + &interrupt_map, &alias_paths,
tests/bad-interrupt-map-mask.dts new file +20 -0
@@ -0,0 +1,20 @@ +/dts-v1/; + +/ { + interrupt-parent = <&intc>; + intc: interrupt-controller { + #interrupt-cells = <3>; + interrupt-controller; + }; + + node { + #address-cells = <0>; + #interrupt-cells = <1>; + interrupt-map = <1 &intc 1 2 3>; + interrupt-map-mask = <0 0>; + + child { + interrupts = <1>; + }; + }; +};
tests/bad-interrupt-map-parent.dts new file +17 -0
@@ -0,0 +1,17 @@ +/dts-v1/; + +/ { + interrupt-parent = <&intc>; + intc: interrupt-controller { + }; + + node { + #address-cells = <0>; + #interrupt-cells = <1>; + interrupt-map = <1 &intc 1 2 3>; + + child { + interrupts = <1>; + }; + }; +};
tests/bad-interrupt-map.dts new file +19 -0
@@ -0,0 +1,19 @@ +/dts-v1/; + +/ { + interrupt-parent = <&intc>; + intc: interrupt-controller { + #interrupt-cells = <3>; + interrupt-controller; + }; + + node { + /* Missing #address-cells = <0>; */ + #interrupt-cells = <1>; + interrupt-map = <1 &intc 1 2 3>; + + child { + interrupts = <1>; + }; + }; +};
tests/run_tests.sh +3 -0
@@ -717,6 +717,9 @@ dtc_tests () { run_sh_test "$SRCDIR/dtc-checkfails.sh" -n deprecated_gpio_property -- -Wdeprecated_gpio_property -I dts -O dtb "$SRCDIR/good-gpio.dts" check_tests "$SRCDIR/bad-interrupt-cells.dts" interrupts_property check_tests "$SRCDIR/bad-interrupt-controller.dts" interrupt_provider + check_tests "$SRCDIR/bad-interrupt-map.dts" interrupt_map + check_tests "$SRCDIR/bad-interrupt-map-parent.dts" interrupt_map + check_tests "$SRCDIR/bad-interrupt-map-mask.dts" interrupt_map run_sh_test "$SRCDIR/dtc-checkfails.sh" node_name_chars -- -I dtb -O dtb bad_node_char.dtb run_sh_test "$SRCDIR/dtc-checkfails.sh" node_name_format -- -I dtb -O dtb bad_node_format.dtb run_sh_test "$SRCDIR/dtc-checkfails.sh" property_name_chars -- -I dtb -O dtb bad_prop_char.dtb
Signature · 1 line
2.30.2
PATCH 2/2 checks: Add a sanity check for #.*-cells property value
In reply to a message not in the archiveWhile in theory any value of number of cells is allowed for a #.*-cells property, for all practical purposes the number of cells is never more than a few cells. Add a check that the value is less than 255. This will catch cases like this which will currently pass:
#foo-cells = "bar";
---
v3:
- Rename check_is_cell to check_is_provider_cell
v2:
- new patch
--- checks.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
checks.c +12 -5
@@ -250,8 +250,9 @@ static void check_is_string_list(struct check *c, struct dt_info *dti,#define ERROR_IF_NOT_STRING_LIST (nm, propname) \ ERROR(nm, check_is_string_list, (propname)) -static void check_is_cell (struct check *c,struct dt_info *dti, -struct node *node) +/* A check for provider '#.*-cells' properties */ +static void check_is_provider_cell (struct check *c,struct dt_info *dti, +struct node *node) {struct property *prop;char *propname = c->data;
@@ -260,13 +261,19 @@ static void check_is_cell(struct check *c, struct dt_info *dti,if (!prop)return ;/* Not present, assumed ok */ -if (prop->val.len !=sizeof (cell_t)) +if (prop->val.len !=sizeof (cell_t)) {FAIL_PROP (c, dti, node, prop,"property is not a single cell" ); +return ; + } + +/* Sanity test for reasonable number of cells */ +if (propval_cell (prop) >255 ) +FAIL_PROP (c, dti, node, prop,"cell size out of range (>255)" ); }#define WARNING_IF_NOT_CELL (nm, propname) \ - WARNING(nm, check_is_cell, (propname)) + WARNING(nm, check_is_provider_cell, (propname))#define ERROR_IF_NOT_CELL (nm, propname) \ - ERROR(nm, check_is_cell, (propname)) + ERROR(nm, check_is_provider_cell, (propname))/* * Structural check functions
Signature · 1 line
2.30.2
David Gibson
AppliedQuoted 10 lines · Rob Herring
Add a check for parsing 'interrupt-map' properties. The check primarily tests parsing 'interrupt-map' properties which depends on and the parent interrupt controller (or another map) node.
Note that this does not require '#address-cells' in the interrupt-map parent, but treats missing '#address-cells' as 0 which is how the Linux kernel parses it. There's numerous cases that expect this behavior.
Cc Andre Przywara <[email protected]>Signed-off-by Rob Herring <[email protected]>
Applied, thanks.
Quoted 208 lines
---
v3:
- Exit check on unresolved phandle when an overlay
v2:
- Rework '#interrupt-cells' and '#address-cells' checks to rely on other checks (interrupt_providerandaddr_size_cells)--- checks.c | 85 ++++++++++++++++++++++++++++++ tests/bad-interrupt-map-mask.dts | 20 +++++++ tests/bad-interrupt-map-parent.dts | 17 ++++++ tests/bad-interrupt-map.dts | 19 +++++++ tests/run_tests.sh | 3 ++ 5 files changed, 144 insertions(+) create mode 100644 tests/bad-interrupt-map-mask.dts create mode 100644 tests/bad-interrupt-map-parent.dts create mode 100644 tests/bad-interrupt-map.dtschecks.c +85
-0@@ -1590,6 +1590,90 @@ static void check_interrupt_provider(struct check *c, }WARNING (interrupt_provider, check_interrupt_provider,NULL , &interrupts_extended_is_cell); +static void check_interrupt_map (struct check *c, +struct dt_info *dti, +struct node *node) +{ +struct node *root = dti->dt; +struct property *prop, *irq_map_prop; +size_t cellsize, cell, map_cells; + + irq_map_prop =get_property (node,"interrupt-map" ); +if (!irq_map_prop) +return ; + +if (node->addr_cells <0 ) { +FAIL (c, dti, node, +"Missing '#address-cells' in interrupt-map provider" ); +return ; + } + cellsize =node_addr_cells (node); + cellsize +=propval_cell (get_property (node,"#interrupt-cells" )); + + prop =get_property (node,"interrupt-map-mask" ); +if (prop && (prop->val.len != (cellsize *sizeof (cell_t)))) +FAIL_PROP (c, dti, node, prop, +"property size (%d) is invalid, expected %zu" , + prop->val.len, cellsize *sizeof (cell_t)); + +if (!is_multiple_of (irq_map_prop->val.len,sizeof (cell_t))) { +FAIL_PROP (c, dti, node, irq_map_prop, +"property size (%d) is invalid, expected multiple of %zu" , + irq_map_prop->val.len,sizeof (cell_t)); +return ; + } + + map_cells = irq_map_prop->val.len /sizeof (cell_t); +for (cell =0 ; cell < map_cells; ) { +struct node *provider_node; +struct property *cellprop; +int phandle; +size_t parent_cellsize; + +if ((cell + cellsize) >= map_cells) { +FAIL_PROP (c, dti, node, irq_map_prop, +"property size (%d) too small, expected > %zu" , + irq_map_prop->val.len, (cell + cellsize) *sizeof (cell_t)); +break ; + } + cell += cellsize; + + phandle =propval_cell_n (irq_map_prop, cell); +if (!phandle_is_valid (phandle)) { +/* Give up if this is an overlay with external references */ +if (!(dti->dtsflags &DTSF_PLUGIN )) +FAIL_PROP (c, dti, node, irq_map_prop, +"Cell %zu is not a phandle(%d)" , + cell, phandle); +break ; + } + + provider_node =get_node_by_phandle (root, phandle); +if (!provider_node) { +FAIL_PROP (c, dti, node, irq_map_prop, +"Could not get phandle(%d) node for (cell %zu)" , + phandle, cell); +break ; + } + + cellprop =get_property (provider_node,"#interrupt-cells" ); +if (cellprop) { + parent_cellsize =propval_cell (cellprop); + }else { +FAIL (c, dti, node,"Missing property '#interrupt-cells' in node %s or bad phandle (referred from interrupt-map[%zu])" , + provider_node->fullpath, cell); +break ; + } + + cellprop =get_property (provider_node,"#address-cells" ); +if (cellprop) + parent_cellsize +=propval_cell (cellprop); + + cell +=1 + parent_cellsize; + } +} +WARNING (interrupt_map, check_interrupt_map,NULL , &phandle_references, &addr_size_cells, &interrupt_provider); +static void check_interrupts_property (struct check *c,struct dt_info *dti,struct node *node)@@ -1888,6 +1972,7 @@ static struct check *check_table[] = { &gpios_property, &interrupts_property, &interrupt_provider, + &interrupt_map, &alias_paths,tests/bad-interrupt-map-mask.dts new file +20
-0@@ -0,0 +1,20 @@ +/dts-v1/; + +/ { + interrupt-parent = <&intc>; + intc: interrupt-controller { + #interrupt-cells = <3>; + interrupt-controller; + }; + + node { + #address-cells = <0>; + #interrupt-cells = <1>; + interrupt-map = <1 &intc 1 2 3>; + interrupt-map-mask = <0 0>; + + child { + interrupts = <1>; + }; + }; +};tests/bad-interrupt-map-parent.dts new file +17
-0@@ -0,0 +1,17 @@ +/dts-v1/; + +/ { + interrupt-parent = <&intc>; + intc: interrupt-controller { + }; + + node { + #address-cells = <0>; + #interrupt-cells = <1>; + interrupt-map = <1 &intc 1 2 3>; + + child { + interrupts = <1>; + }; + }; +};tests/bad-interrupt-map.dts new file +19
-0@@ -0,0 +1,19 @@ +/dts-v1/; + +/ { + interrupt-parent = <&intc>; + intc: interrupt-controller { + #interrupt-cells = <3>; + interrupt-controller; + }; + + node { + /* Missing #address-cells = <0>; */ + #interrupt-cells = <1>; + interrupt-map = <1 &intc 1 2 3>; + + child { + interrupts = <1>; + }; + }; +};tests/run_tests.sh +3
-0@@ -717,6 +717,9 @@ dtc_tests () { run_sh_test "$SRCDIR/dtc-checkfails.sh" -n deprecated_gpio_property -- -Wdeprecated_gpio_property -I dts -O dtb "$SRCDIR/good-gpio.dts" check_tests "$SRCDIR/bad-interrupt-cells.dts" interrupts_property check_tests "$SRCDIR/bad-interrupt-controller.dts" interrupt_provider + check_tests "$SRCDIR/bad-interrupt-map.dts" interrupt_map + check_tests "$SRCDIR/bad-interrupt-map-parent.dts" interrupt_map + check_tests "$SRCDIR/bad-interrupt-map-mask.dts" interrupt_map run_sh_test "$SRCDIR/dtc-checkfails.sh" node_name_chars -- -I dtb -O dtb bad_node_char.dtb run_sh_test "$SRCDIR/dtc-checkfails.sh" node_name_format -- -I dtb -O dtb bad_node_format.dtb run_sh_test "$SRCDIR/dtc-checkfails.sh" property_name_chars -- -I dtb -O dtb bad_prop_char.dtb
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [PATCH 2/2] checks: Add a sanity check for #.*-cells property value
In reply to a message not in the archiveQuoted 8 lines · Rob Herring
While in theory any value of number of cells is allowed for a #.*-cells property, for all practical purposes the number of cells is never more than a few cells. Add a check that the value is less than 255. This will catch cases like this which will currently pass:
#foo-cells = "bar";Signed-off-by Rob Herring <[email protected]>
Sorry, can you rename the macros as well. If anything they're *more* misleading than the function name with this change.
Quoted 48 lines
---
v3:
- Renamecheck_is_celltocheck_is_provider_cell
v2:
- new patch--- checks.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)checks.c +12
-5@@ -250,8 +250,9 @@ static void check_is_string_list(struct check *c, struct dt_info *dti,#define ERROR_IF_NOT_STRING_LIST (nm, propname) \ ERROR(nm, check_is_string_list, (propname)) -static void check_is_cell (struct check *c,struct dt_info *dti, -struct node *node) +/* A check for provider '#.*-cells' properties */ +static void check_is_provider_cell (struct check *c,struct dt_info *dti, +struct node *node) {struct property *prop;char *propname = c->data;@@ -260,13 +261,19 @@ static void check_is_cell(struct check *c, struct dt_info *dti,if (!prop)return ;/* Not present, assumed ok */ -if (prop->val.len !=sizeof (cell_t)) +if (prop->val.len !=sizeof (cell_t)) {FAIL_PROP (c, dti, node, prop,"property is not a single cell" ); +return ; + } + +/* Sanity test for reasonable number of cells */ +if (propval_cell (prop) >255 ) +FAIL_PROP (c, dti, node, prop,"cell size out of range (>255)" ); }#define WARNING_IF_NOT_CELL (nm, propname) \ - WARNING(nm, check_is_cell, (propname)) + WARNING(nm, check_is_provider_cell, (propname))#define ERROR_IF_NOT_CELL (nm, propname) \ - ERROR(nm, check_is_cell, (propname)) + ERROR(nm, check_is_provider_cell, (propname))/* * Structural check functions
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson