From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Cc: Devicetree Compiler
<devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH v4 5/6] libfdt: Add support for disabling version checks
Date: Tue, 28 Jan 2020 19:37:09 +1100 [thread overview]
Message-ID: <20200128083709.GK42099@umbus.fritz.box> (raw)
In-Reply-To: <20191113015422.67210-6-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 7497 bytes --]
On Tue, Nov 12, 2019 at 06:54:21PM -0700, Simon Glass wrote:
> Allow enabling FDT_ASSUME_LATEST to disable version checks.
>
> Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
LGTM, one minor comment below.
> ---
>
> Changes in v4: None
> Changes in v3: None
> Changes in v2: None
>
> libfdt/fdt.c | 34 +++++++++++++++++++++-------------
> libfdt/fdt_ro.c | 16 ++++++++--------
> libfdt/fdt_rw.c | 6 +++---
> 3 files changed, 32 insertions(+), 24 deletions(-)
>
> diff --git a/libfdt/fdt.c b/libfdt/fdt.c
> index d89c0e0..78dbe58 100644
> --- a/libfdt/fdt.c
> +++ b/libfdt/fdt.c
> @@ -21,10 +21,13 @@ int32_t fdt_ro_probe_(const void *fdt)
>
> if (fdt_magic(fdt) == FDT_MAGIC) {
> /* Complete tree */
> - if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
> - return -FDT_ERR_BADVERSION;
> - if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION)
> - return -FDT_ERR_BADVERSION;
> + if (!can_assume(LATEST)) {
> + if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
> + return -FDT_ERR_BADVERSION;
> + if (fdt_last_comp_version(fdt) >
> + FDT_LAST_SUPPORTED_VERSION)
> + return -FDT_ERR_BADVERSION;
> + }
> } else if (fdt_magic(fdt) == FDT_SW_MAGIC) {
> /* Unfinished sequential-write blob */
> if (fdt_size_dt_struct(fdt) == 0)
> @@ -72,7 +75,8 @@ size_t fdt_header_size_(uint32_t version)
>
> size_t fdt_header_size(const void *fdt)
> {
> - return fdt_header_size_(fdt_version(fdt));
> + return can_assume(LATEST) ? FDT_V17_SIZE :
> + fdt_header_size_(fdt_version(fdt));
> }
>
> int fdt_check_header(const void *fdt)
> @@ -81,11 +85,14 @@ int fdt_check_header(const void *fdt)
>
> if (fdt_magic(fdt) != FDT_MAGIC)
> return -FDT_ERR_BADMAGIC;
> - if ((fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
> - || (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION))
> - return -FDT_ERR_BADVERSION;
> - if (fdt_version(fdt) < fdt_last_comp_version(fdt))
> - return -FDT_ERR_BADVERSION;
> + if (!can_assume(LATEST)) {
> + if ((fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
> + || (fdt_last_comp_version(fdt) >
> + FDT_LAST_SUPPORTED_VERSION))
> + return -FDT_ERR_BADVERSION;
> + if (fdt_version(fdt) < fdt_last_comp_version(fdt))
> + return -FDT_ERR_BADVERSION;
> + }
> hdrsize = fdt_header_size(fdt);
> if (!can_assume(SANE)) {
>
> @@ -101,7 +108,7 @@ int fdt_check_header(const void *fdt)
>
> if (!can_assume(SANE)) {
> /* Bounds check structure block */
> - if (fdt_version(fdt) < 17) {
> + if (!can_assume(LATEST) && fdt_version(fdt) < 17) {
I wonder if we should make fdt_version() return 17 unconditionally in
the can_assume() case, which might make some of these tests redundant.
> if (!check_off_(hdrsize, fdt_totalsize(fdt),
> fdt_off_dt_struct(fdt)))
> return -FDT_ERR_TRUNCATED;
> @@ -132,7 +139,7 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
> || (absoffset + len) > fdt_totalsize(fdt))
> return NULL;
>
> - if (fdt_version(fdt) >= 0x11)
> + if (can_assume(LATEST) || fdt_version(fdt) >= 0x11)
> if (((offset + len) < offset)
> || ((offset + len) > fdt_size_dt_struct(fdt)))
> return NULL;
> @@ -172,7 +179,8 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
> /* skip-name offset, length and value */
> offset += sizeof(struct fdt_property) - FDT_TAGSIZE
> + fdt32_to_cpu(*lenp);
> - if (fdt_version(fdt) < 0x10 && fdt32_to_cpu(*lenp) >= 8 &&
> + if (!can_assume(LATEST) &&
> + fdt_version(fdt) < 0x10 && fdt32_to_cpu(*lenp) >= 8 &&
> ((offset - fdt32_to_cpu(*lenp)) % 8) != 0)
> offset += 4;
> break;
> diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
> index 5615bff..13b63c3 100644
> --- a/libfdt/fdt_ro.c
> +++ b/libfdt/fdt_ro.c
> @@ -60,7 +60,7 @@ const char *fdt_get_string(const void *fdt, int stroffset, int *lenp)
> if (fdt_magic(fdt) == FDT_MAGIC) {
> if (stroffset < 0)
> goto fail;
> - if (fdt_version(fdt) >= 17) {
> + if (can_assume(LATEST) || fdt_version(fdt) >= 17) {
> if (stroffset >= fdt_size_dt_strings(fdt))
> goto fail;
> if ((fdt_size_dt_strings(fdt) - stroffset) < len)
> @@ -308,7 +308,7 @@ const char *fdt_get_name(const void *fdt, int nodeoffset, int *len)
>
> nameptr = nh->name;
>
> - if (fdt_version(fdt) < 0x10) {
> + if (!can_assume(LATEST) && fdt_version(fdt) < 0x10) {
> /*
> * For old FDT versions, match the naming conventions of V16:
> * give only the leaf name (after all /). The actual tree
> @@ -381,7 +381,7 @@ const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
> /* Prior to version 16, properties may need realignment
> * and this API does not work. fdt_getprop_*() will, however. */
>
> - if (fdt_version(fdt) < 0x10) {
> + if (!can_assume(LATEST) && fdt_version(fdt) < 0x10) {
> if (lenp)
> *lenp = -FDT_ERR_BADVERSION;
> return NULL;
> @@ -428,7 +428,7 @@ const struct fdt_property *fdt_get_property_namelen(const void *fdt,
> {
> /* Prior to version 16, properties may need realignment
> * and this API does not work. fdt_getprop_*() will, however. */
> - if (fdt_version(fdt) < 0x10) {
> + if (!can_assume(LATEST) && fdt_version(fdt) < 0x10) {
> if (lenp)
> *lenp = -FDT_ERR_BADVERSION;
> return NULL;
> @@ -459,8 +459,8 @@ const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
> return NULL;
>
> /* Handle realignment */
> - if (fdt_version(fdt) < 0x10 && (poffset + sizeof(*prop)) % 8 &&
> - fdt32_ld(&prop->len) >= 8)
> + if (!can_assume(LATEST) && fdt_version(fdt) < 0x10 &&
> + (poffset + sizeof(*prop)) % 8 && fdt32_ld(&prop->len) >= 8)
> return prop->data + 4;
> return prop->data;
> }
> @@ -492,8 +492,8 @@ const void *fdt_getprop_by_offset(const void *fdt, int offset,
> }
>
> /* Handle realignment */
> - if (fdt_version(fdt) < 0x10 && (offset + sizeof(*prop)) % 8 &&
> - fdt32_ld(&prop->len) >= 8)
> + if (!can_assume(LATEST) && fdt_version(fdt) < 0x10 &&
> + (offset + sizeof(*prop)) % 8 && fdt32_ld(&prop->len) >= 8)
> return prop->data + 4;
> return prop->data;
> }
> diff --git a/libfdt/fdt_rw.c b/libfdt/fdt_rw.c
> index fe61e63..4ff7942 100644
> --- a/libfdt/fdt_rw.c
> +++ b/libfdt/fdt_rw.c
> @@ -30,12 +30,12 @@ static int fdt_rw_probe_(void *fdt)
> return 0;
> FDT_RO_PROBE(fdt);
>
> - if (fdt_version(fdt) < 17)
> + if (!can_assume(LATEST) && fdt_version(fdt) < 17)
> return -FDT_ERR_BADVERSION;
> if (fdt_blocks_misordered_(fdt, sizeof(struct fdt_reserve_entry),
> fdt_size_dt_struct(fdt)))
> return -FDT_ERR_BADLAYOUT;
> - if (fdt_version(fdt) > 17)
> + if (!can_assume(LATEST) && fdt_version(fdt) > 17)
> fdt_set_version(fdt, 17);
>
> return 0;
> @@ -427,7 +427,7 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
> mem_rsv_size = (fdt_num_mem_rsv(fdt)+1)
> * sizeof(struct fdt_reserve_entry);
>
> - if (fdt_version(fdt) >= 17) {
> + if (can_assume(LATEST) || fdt_version(fdt) >= 17) {
> struct_size = fdt_size_dt_struct(fdt);
> } else {
> struct_size = 0;
--
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2020-01-28 8:37 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20191113015422.67210-1-sjg@chromium.org>
[not found] ` <20191113015422.67210-3-sjg@chromium.org>
[not found] ` <20191113015422.67210-3-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2020-01-12 18:39 ` [PATCH v4 2/6] Add a way to control the level of checks in the code Simon Glass
2020-01-28 8:28 ` David Gibson
[not found] ` <20200128082819.GH42099-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2020-01-31 18:14 ` Simon Glass
[not found] ` <CAPnjgZ2x7yi3tgzRkM9m-2JBpYVqaXz42KLNiyUA6nPHu3KjqA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-02-03 0:41 ` David Gibson
[not found] ` <20191113015422.67210-2-sjg@chromium.org>
[not found] ` <20191120035121.GD5582@umbus.fritz.box>
[not found] ` <CAPnjgZ0bP3Hmk7daknD275J0SxJR6XoxNXPustqKJ4k3POPqiw@mail.gmail.com>
[not found] ` <CAPnjgZ0bP3Hmk7daknD275J0SxJR6XoxNXPustqKJ4k3POPqiw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-01-28 8:24 ` [PATCH v4 1/6] libfdt: De-inline fdt_header_size() David Gibson
[not found] ` <20200128082402.GG42099-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2020-01-31 18:14 ` Simon Glass
[not found] ` <CAPnjgZ2MUorvc1+MY2mBozQn+kYA1Q=SLFhPPGXixoSZshUGsg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-02-02 3:12 ` David Gibson
[not found] ` <20200202031201.GB20412-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2020-02-05 20:57 ` Simon Glass
[not found] ` <CAPnjgZ2r9wNFpcGJ47pk4mj4sGP_t+eDki7_stqwn0-tE1dATQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-02-06 4:44 ` David Gibson
[not found] ` <20200206044424.GL60221-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2020-02-06 5:03 ` Simon Glass
[not found] ` <CAPnjgZ1_UwW_5OYY-r-2OCoYKXpMHn0QuvVEwVNECqcYvc3CBg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-02-06 5:32 ` David Gibson
[not found] ` <20200206053201.GO60221-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2020-02-06 5:38 ` Simon Glass
[not found] ` <20191113015422.67210-4-sjg@chromium.org>
[not found] ` <20191113015422.67210-4-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2020-01-28 8:33 ` [PATCH v4 3/6] libfdt: Add support for disabling sanity checks David Gibson
[not found] ` <20191113015422.67210-5-sjg@chromium.org>
[not found] ` <20191113015422.67210-5-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2020-01-28 8:34 ` [PATCH v4 4/6] libfdt: Add support for disabling rollback handling David Gibson
[not found] ` <20191113015422.67210-6-sjg@chromium.org>
[not found] ` <20191113015422.67210-6-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2020-01-28 8:37 ` David Gibson [this message]
[not found] ` <20200128083709.GK42099-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2020-01-31 18:14 ` [PATCH v4 5/6] libfdt: Add support for disabling version checks Simon Glass
[not found] ` <CAPnjgZ02B2pu9vSh2uUf-4e5HZCWq2nOcpMXrrnXJTv98oScEw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-02-02 6:23 ` David Gibson
[not found] ` <20191113015422.67210-7-sjg@chromium.org>
[not found] ` <20191113015422.67210-7-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2020-01-28 8:37 ` [PATCH v4 6/6] libfdt: Allow exclusion of fdt_check_full() 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=20200128083709.GK42099@umbus.fritz.box \
--to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=sjg-F7+t8E8rja9g9hUCZPvPmw@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 NNTP newsgroup(s).