From: Andreas Gnau <andreas.gnau@iopsys.eu>
To: devicetree-compiler@vger.kernel.org
Cc: andreas.gnau@iopsys.eu
Subject: [PATCH v1 2/2] util: Once size is known, allocate fdt_totalsize
Date: Tue, 24 Sep 2024 16:50:52 +0200 [thread overview]
Message-ID: <20240924145320.613246-3-andreas.gnau@iopsys.eu> (raw)
In-Reply-To: <20240924145320.613246-1-andreas.gnau@iopsys.eu>
Instead of growing the buffer when reading a file by a factor of 2,
try to allocate the whole size of the FDT once the size is known after
having read the header. While the size is not known, use the existing
strategy of doubling the buffer's size.
Since the initial buffer size is 1024, which is greater than
FDT_V1_SIZE (and any later version header sizes such as FDT_V17_SIZE),
this reduces the number of allocations to two (one for the initial
buffer and one additional one for the full size of the FDT. The total
size of the buffer will be reduced as well by up to
(fdt_totalsize / 2) - 1 bytes.
Signed-off-by: Andreas Gnau <andreas.gnau@iopsys.eu>
---
util.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/util.c b/util.c
index 093303078d5f..c5873e91608e 100644
--- a/util.c
+++ b/util.c
@@ -263,7 +263,7 @@ int utilfdt_read_err(const char *filename, char **buffp, size_t *len)
do {
/* Expand the buffer to hold the next chunk */
if (offset == bufsize) {
- bufsize *= 2;
+ bufsize = (totalsize != UINT32_MAX) ? totalsize : 2 * bufsize;
buf = xrealloc(buf, bufsize);
}
--
2.46.1
prev parent reply other threads:[~2024-09-24 14:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-24 14:50 [PATCH v1 0/2] Reduce memory usage of FDT utils Andreas Gnau
2024-09-24 14:50 ` [PATCH v1 1/2] util: Only read files until fdt_totalsize Andreas Gnau
2024-09-25 2:04 ` David Gibson
2024-09-24 14:50 ` Andreas Gnau [this message]
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=20240924145320.613246-3-andreas.gnau@iopsys.eu \
--to=andreas.gnau@iopsys.eu \
--cc=devicetree-compiler@vger.kernel.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).