Commit f3cea45a authored by Grant Likely's avatar Grant Likely

of: Fix iteration bug over CPU reg properties

The size of each hwid in a cpu nodes 'reg' property is defined by the
parents #address-cells property in the normal way. The cpu parsing code
has a bug where it will overrun the end of the property if
address-cells is greater than one. This commit fixes the problem by
adjusting the array size by the number of address cells. It also makes
sure address-cells isn't zero for that would cause an infinite loop.

v2: bail if #address-cells is zero instead of forcing to
    OF_ROOT_NODE_ADDR_CELLS_DEFAULT. Forcing it will cause the reg
    property to be parsed incorrectly.
Signed-off-by: default avatarGrant Likely <grant.likely@linaro.org>
Cc: Rob Herring <rob.herring@calxeda.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
parent d1cb9d1a
...@@ -265,9 +265,9 @@ static bool __of_find_n_match_cpu_property(struct device_node *cpun, ...@@ -265,9 +265,9 @@ static bool __of_find_n_match_cpu_property(struct device_node *cpun,
ac = of_n_addr_cells(cpun); ac = of_n_addr_cells(cpun);
cell = of_get_property(cpun, prop_name, &prop_len); cell = of_get_property(cpun, prop_name, &prop_len);
if (!cell) if (!cell || !ac)
return false; return false;
prop_len /= sizeof(*cell); prop_len /= sizeof(*cell) * ac;
for (tid = 0; tid < prop_len; tid++) { for (tid = 0; tid < prop_len; tid++) {
hwid = of_read_number(cell, ac); hwid = of_read_number(cell, ac);
if (arch_match_cpu_phys_id(cpu, hwid)) { if (arch_match_cpu_phys_id(cpu, hwid)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment