From: Grant Likely <grant.likely@linaro.org>
To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Grant Likely <grant.likely@linaro.org>,
Rob Herring <rob.herring@calxeda.com>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: [PATCH] of: fix iteration bug over CPU reg properties
Date: Fri, 4 Oct 2013 17:40:02 +0100 [thread overview]
Message-ID: <1380904802-10432-1-git-send-email-grant.likely@linaro.org> (raw)
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.
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
next reply other threads:[~2013-10-07 12:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-04 16:40 Grant Likely [this message]
2013-10-21 12:38 ` Sudeep KarkadaNagesha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1380904802-10432-1-git-send-email-grant.likely@linaro.org \
--to=grant.likely@linaro.org \
--cc=benh@kernel.crashing.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rob.herring@calxeda.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®