* [PATCH] of: fix iteration bug over CPU reg properties
@ 2013-10-04 16:40 Grant Likely
2013-10-21 12:38 ` Sudeep KarkadaNagesha
0 siblings, 1 reply; 2+ messages in thread
From: Grant Likely @ 2013-10-04 16:40 UTC (permalink / raw)
To: devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
Cc: Grant Likely, Rob Herring, Benjamin Herrenschmidt
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.
Signed-off-by: Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Cc: Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
Cc: Benjamin Herrenschmidt <benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
---
I discovered this during code inspection. I don't think it is an actual
bug seen in the wild, but the code does look wrong. I'd appreciate
someone take a look and confirm that I've read the code right.
drivers/of/base.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index e4c9945..470b871 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -263,11 +263,11 @@ static bool __of_find_n_match_cpu_property(struct device_node *cpun,
int ac, prop_len, tid;
u64 hwid;
- ac = of_n_addr_cells(cpun);
+ ac = of_n_addr_cells(cpun) ? : OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
cell = of_get_property(cpun, prop_name, &prop_len);
if (!cell)
return false;
- prop_len /= sizeof(*cell);
+ prop_len /= sizeof(*cell) * ac;
for (tid = 0; tid < prop_len; tid++) {
hwid = of_read_number(cell, ac);
if (arch_match_cpu_phys_id(cpu, hwid)) {
--
1.8.1.2
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] of: fix iteration bug over CPU reg properties
2013-10-04 16:40 [PATCH] of: fix iteration bug over CPU reg properties Grant Likely
@ 2013-10-21 12:38 ` Sudeep KarkadaNagesha
0 siblings, 0 replies; 2+ messages in thread
From: Sudeep KarkadaNagesha @ 2013-10-21 12:38 UTC (permalink / raw)
To: Grant Likely, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: rob.herring@calxeda.com, Benjamin Herrenschmidt,
Sudeep KarkadaNagesha
Hi Grant,
On 04/10/13 17:40, Grant Likely wrote:
> 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.
>
> Signed-off-by: Grant Likely <grant.likely@linaro.org>
> Cc: Rob Herring <rob.herring@calxeda.com>
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> ---
>
> I discovered this during code inspection. I don't think it is an actual
> bug seen in the wild, but the code does look wrong. I'd appreciate
> someone take a look and confirm that I've read the code right.
>
Thanks for finding and fixing the bug.
I have tested this on ARM64 with 2 cell reg value using [1].
Tested-by: Sudeep KarkadaNagesha <sudeep.karkadanagesha@arm.com>
Regards,
Sudeep
[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2013-October/206401.html
> drivers/of/base.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index e4c9945..470b871 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -263,11 +263,11 @@ static bool __of_find_n_match_cpu_property(struct device_node *cpun,
> int ac, prop_len, tid;
> u64 hwid;
>
> - ac = of_n_addr_cells(cpun);
> + ac = of_n_addr_cells(cpun) ? : OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
> cell = of_get_property(cpun, prop_name, &prop_len);
> if (!cell)
> return false;
> - prop_len /= sizeof(*cell);
> + prop_len /= sizeof(*cell) * ac;
> for (tid = 0; tid < prop_len; tid++) {
> hwid = of_read_number(cell, ac);
> if (arch_match_cpu_phys_id(cpu, hwid)) {
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-10-21 12:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-04 16:40 [PATCH] of: fix iteration bug over CPU reg properties Grant Likely
2013-10-21 12:38 ` Sudeep KarkadaNagesha
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).