From patchwork Mon Jun 11 16:24:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 138258 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4256017lji; Mon, 11 Jun 2018 09:26:38 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJkp1LY3Pa0limgXfMgrMkK+ntWx0x4i0SSCHJAtqZ9u0RcltvXBj1YCJZKyj4da6jprdXu X-Received: by 2002:a0c:cd13:: with SMTP id b19-v6mr15606720qvm.83.1528734398269; Mon, 11 Jun 2018 09:26:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528734398; cv=none; d=google.com; s=arc-20160816; b=nusqjlwilVTUe7S7OXdAAeYHXySwE8NzahlUita96GyGME3Bo8cLHRSd+T5rK7/Ite iG4CY6Ay970HWtF4EMyWWlFHidAdUxIfgwoJSf8WKZ4Dx6JbbBBh2bdE/+V10BxAZzkW naLWEXlfvsXiaWJC+NjIIxkTesw4Ea9yS+XITzUs/QkHHqREaXy7zF1DuM15kHljE/p2 bFjhPEWWtY/WQ6gC2uiPou4NrUU+6QnxaT6TP3LEa2wMUne6ERlJCqS3gSxJWRiotd+o 5n84Ijq4gPpP8OaXKyjRCOua1rPlyEZ8DQaiUKl8m0LyHYY+eMZkQ1ukCqlBQjAajdli stAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from:dkim-signature:arc-authentication-results; bh=445GinKz4IC6oqPUbXEXdOxglgxp5ACZ2uv86FjG6gY=; b=rfBw0yw2+h64ObYd7Hd+NMMqEonkT/pAVoO+EENFZXW/xCJoTQIe5cz4gxugzSbEpg TQ8ctktsmmiB8vbpsWjMnlFh2MkHs+rYdK4vklMqhWRy6HsK5kTeTS2/nQM6ZGKLWqdi CdPydtJbOiAIlMJP3nBZzaiMalCmkM9Ju8uFx6IZvaQ2aR50VbD5bMUTCFvXR4pO3esR pTgn80MjZpThsY4Tv46n83wcyR9iy4eAIccTW1p4kfAvB9QBPgTvqBCjP4wWGF8epjm4 9/HaU4vwhuEukRw8OVDTZGOsg5RUENcgbVqtu7+ktCDDWCVpmKEl0eom1zLIuWT7f5qQ Ks3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=EYBxUWHN; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id n89-v6si4714681qva.105.2018.06.11.09.26.38 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 11 Jun 2018 09:26:38 -0700 (PDT) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=EYBxUWHN; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50088 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSPeP-0005JF-NT for patch@linaro.org; Mon, 11 Jun 2018 12:26:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSPcy-0004ma-Bi for grub-devel@gnu.org; Mon, 11 Jun 2018 12:25:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSPcv-0007n4-Mo for grub-devel@gnu.org; Mon, 11 Jun 2018 12:25:08 -0400 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]:37053) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fSPcv-0007m1-Dj for grub-devel@gnu.org; Mon, 11 Jun 2018 12:25:05 -0400 Received: by mail-wm0-x22c.google.com with SMTP id r125-v6so17678077wmg.2 for ; Mon, 11 Jun 2018 09:25:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Y3QxyfsxrzlbvHTMpL1XPvCWlQo8OMun0kDexsyswN4=; b=EYBxUWHNmkW71wQ3nEsr5Pm8z3629DEmoYOod7TjIoSCnqThQDWfyASIPz0IAOWo50 cC9Ea9uVrPuUqhFvC3pzfx6GNgDd1dIm/Pkvn1RLghDu+sTtcHrt3oI97IIbg742Atdp i9Xo6ARwpFhnEF3Dvzxb4wxaQUViR/MRY0qjI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Y3QxyfsxrzlbvHTMpL1XPvCWlQo8OMun0kDexsyswN4=; b=U8m8X+NekVCvLwO1QC5ujYeah8sHedesaZNnCnG1S3gNQF/o+EOCfpXjZ3R1ak5d5W 4AUjfXt2rH2IqklekZr5dnI7tfiTkdmrGVgUE1tirlhZitTRWVIY1vnOQ8a28Po79i/3 w8K+oHTaZW0zwJitlk73YYfJgBy6Dl1NzPep2XyDrLcGbdpgyYKwthLzRfDgximXIcm6 GS2KL84ge06TTpLvypMzBju/lvuGTcan3rXnWcaL21/+qF7NXWIZcsKTV0Je67DmBNQ0 sOdz50SPfm5noQNDPibObRHuqs53hcJeAdWSD/p5m1VOhpGdeaWwtiM8Wzz3RuJI/7WK clGg== X-Gm-Message-State: APt69E2/Gg9zBRhgmKIGJhXNA4uni67KEU7cYI0u/kn8IurrGXrmGtTw BKbLRhrO6CNREyY10yUEGQtus8NfhTs= X-Received: by 2002:a1c:e90f:: with SMTP id q15-v6mr9324266wmc.149.1528734304106; Mon, 11 Jun 2018 09:25:04 -0700 (PDT) Received: from vanye.hemma.eciton.net (cpc92302-cmbg19-2-0-cust304.5-4.cable.virginm.net. [82.1.209.49]) by smtp.gmail.com with ESMTPSA id s191-v6sm16460925wmd.27.2018.06.11.09.25.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jun 2018 09:25:02 -0700 (PDT) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 1/2] fdt: move prop_entry_size to fdt.h Date: Mon, 11 Jun 2018 17:24:58 +0100 Message-Id: <20180611162459.9178-2-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180611162459.9178-1-leif.lindholm@linaro.org> References: <20180611162459.9178-1-leif.lindholm@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22c X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: Daniel Kiper MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" To be able to resuse the prop_entry_size macro, move it to and rename it grub_fdt_prop_entry_size. Signed-off-by: Leif Lindholm --- grub-core/lib/fdt.c | 25 ++++++++++--------------- include/grub/fdt.h | 5 +++++ 2 files changed, 15 insertions(+), 15 deletions(-) -- 2.11.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/lib/fdt.c b/grub-core/lib/fdt.c index 2705f2629..0d371c563 100644 --- a/grub-core/lib/fdt.c +++ b/grub-core/lib/fdt.c @@ -41,11 +41,6 @@ GRUB_MOD_LICENSE ("GPLv3+"); (2 * sizeof(grub_uint32_t) \ + ALIGN_UP (grub_strlen (name) + 1, sizeof(grub_uint32_t))) -/* Size needed by a property entry: 1 token (FDT_PROPERTY), plus len and nameoff - fields, plus the property value, plus padding if needed. */ -#define prop_entry_size(prop_len) \ - (3 * sizeof(grub_uint32_t) + ALIGN_UP(prop_len, sizeof(grub_uint32_t))) - #define SKIP_NODE_NAME(name, token, end) \ name = (char *) ((token) + 1); \ while (name < (char *) end) \ @@ -86,7 +81,7 @@ static grub_uint32_t *get_next_node (const void *fdt, char *node_name) case FDT_PROP: /* Skip property token and following data (len, nameoff and property value). */ - token += prop_entry_size(grub_be_to_cpu32(*(token + 1))) + token += grub_fdt_prop_entry_size(grub_be_to_cpu32(*(token + 1))) / sizeof(*token); break; case FDT_NOP: @@ -150,7 +145,7 @@ static int add_subnode (void *fdt, int parentoffset, const char *name) { case FDT_PROP: /* Skip len, nameoff and property value. */ - token += prop_entry_size(grub_be_to_cpu32(*(token + 1))) + token += grub_fdt_prop_entry_size(grub_be_to_cpu32(*(token + 1))) / sizeof(*token); break; case FDT_BEGIN_NODE: @@ -249,12 +244,12 @@ static grub_uint32_t *find_prop (const void *fdt, unsigned int nodeoffset, && !grub_strcmp (name, (char *) fdt + grub_fdt_get_off_dt_strings (fdt) + nameoff)) { - if (prop + prop_entry_size(grub_be_to_cpu32(*(prop + 1))) + if (prop + grub_fdt_prop_entry_size(grub_be_to_cpu32(*(prop + 1))) / sizeof (*prop) >= end) return NULL; return prop; } - prop += prop_entry_size(grub_be_to_cpu32(*(prop + 1))) / sizeof (*prop); + prop += grub_fdt_prop_entry_size(grub_be_to_cpu32(*(prop + 1))) / sizeof (*prop); } else if (grub_be_to_cpu32(*prop) == FDT_NOP) prop++; @@ -319,7 +314,7 @@ advance_token (const void *fdt, const grub_uint32_t *token, const grub_uint32_t value). */ if (token >= end - 1) return 0; - token += prop_entry_size(grub_be_to_cpu32(*(token + 1))) + token += grub_fdt_prop_entry_size(grub_be_to_cpu32(*(token + 1))) / sizeof(*token); break; case FDT_NOP: @@ -467,12 +462,12 @@ int grub_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name, unsigned int needed_space = 0; if (!prop) - needed_space = prop_entry_size(len); + needed_space = grub_fdt_prop_entry_size(len); if (!prop_name_present) needed_space += grub_strlen (name) + 1; if (needed_space > get_free_space (fdt)) return -1; - if (rearrange_blocks (fdt, !prop ? prop_entry_size(len) : 0) < 0) + if (rearrange_blocks (fdt, !prop ? grub_fdt_prop_entry_size(len) : 0) < 0) return -1; } if (!prop_name_present) { @@ -489,10 +484,10 @@ int grub_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name, + sizeof(grub_uint32_t)); prop = (void *) (node_name + ALIGN_UP(grub_strlen(node_name) + 1, 4)); - grub_memmove (prop + prop_entry_size(len) / sizeof(*prop), prop, + grub_memmove (prop + grub_fdt_prop_entry_size(len) / sizeof(*prop), prop, struct_end(fdt) - (grub_addr_t) prop); grub_fdt_set_size_dt_struct (fdt, grub_fdt_get_size_dt_struct (fdt) - + prop_entry_size(len)); + + grub_fdt_prop_entry_size(len)); *prop = grub_cpu_to_be32_compile_time (FDT_PROP); *(prop + 2) = grub_cpu_to_be32 (nameoff); } @@ -500,7 +495,7 @@ int grub_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name, /* Insert padding bytes at the end of the value; if they are not needed, they will be overwritten by the following memcpy. */ - *(prop + prop_entry_size(len) / sizeof(grub_uint32_t) - 1) = 0; + *(prop + grub_fdt_prop_entry_size(len) / sizeof(grub_uint32_t) - 1) = 0; grub_memcpy (prop + 3, val, len); return 0; diff --git a/include/grub/fdt.h b/include/grub/fdt.h index 75525fa31..158b1bc4b 100644 --- a/include/grub/fdt.h +++ b/include/grub/fdt.h @@ -50,6 +50,11 @@ struct grub_fdt_empty_tree { #define GRUB_FDT_EMPTY_TREE_SZ sizeof (struct grub_fdt_empty_tree) +/* Size needed by a property entry: 1 token (FDT_PROPERTY), plus len and nameoff + fields, plus the property value, plus padding if needed. */ +#define grub_fdt_prop_entry_size(prop_len) \ + (3 * sizeof(grub_uint32_t) + ALIGN_UP(prop_len, sizeof(grub_uint32_t))) + #define grub_fdt_get_header(fdt, field) \ grub_be_to_cpu32(((const grub_fdt_header_t *)(fdt))->field) #define grub_fdt_set_header(fdt, field, value) \