From: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Andre Przywara <andre.przywara-5wv7dgnIgG8@public.gmane.org>
Subject: [PATCH 2/2] checks: Add a sanity check for #.*-cells property value
Date: Fri, 15 Oct 2021 16:35:27 -0500 [thread overview]
Message-ID: <20211015213527.2237774-2-robh@kernel.org> (raw)
In-Reply-To: <20211015213527.2237774-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
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 <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
v3:
- Rename check_is_cell to check_is_provider_cell
v2:
- new patch
---
checks.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/checks.c b/checks.c
index 781ba1129a8e..704e99ebd66c 100644
--- a/checks.c
+++ b/checks.c
@@ -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
--
2.30.2
next prev parent reply other threads:[~2021-10-15 21:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-15 21:35 [PATCH 1/2] checks: Add an interrupt-map check Rob Herring
[not found] ` <20211015213527.2237774-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-10-15 21:35 ` Rob Herring [this message]
[not found] ` <20211015213527.2237774-2-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-10-21 4:51 ` [PATCH 2/2] checks: Add a sanity check for #.*-cells property value David Gibson
2021-10-21 4:49 ` [PATCH 1/2] checks: Add an interrupt-map check David Gibson
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=20211015213527.2237774-2-robh@kernel.org \
--to=robh-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
--cc=andre.przywara-5wv7dgnIgG8@public.gmane.org \
--cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).