From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 6/7] fs: efi: replace allocation with local buffer
Date: Mon, 25 Nov 2024 16:29:26 +0100 [thread overview]
Message-ID: <20241125152927.546493-7-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20241125152927.546493-1-a.fatoum@pengutronix.de>
Currently, every probed EFI file system involves an unnecessary
allocation; either a string literal is duplicated or a /efiX path is
formatted.
Avoid that extra allocation by just formatting on the stack as the
buffer is not needed later anyway.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/efi.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/fs/efi.c b/fs/efi.c
index cb0eb40da4c2..2125d54ed632 100644
--- a/fs/efi.c
+++ b/fs/efi.c
@@ -451,11 +451,13 @@ static int efifs_init(void)
coredevice_initcall(efifs_init);
-static int index;
+static unsigned index;
static int efi_fs_probe(struct efi_device *efidev)
{
- char *path, *device;
+ char buf[sizeof("/efi4294967295")];
+ const char *path;
+ char *device;
int ret;
struct efi_file_io_interface *volume;
@@ -463,10 +465,13 @@ static int efi_fs_probe(struct efi_device *efidev)
BS->handle_protocol(efi_loaded_image->device_handle,
&efi_simple_file_system_protocol_guid, (void*)&volume);
- if (efi_loaded_image && efidev->protocol == volume)
- path = xstrdup("/boot");
- else
- path = basprintf("/efi%d", index);
+ if (efi_loaded_image && efidev->protocol == volume) {
+ path = "/boot";
+ } else {
+ snprintf(buf, sizeof(buf), "/efi%u", index);
+ path = buf;
+ }
+
device = basprintf("%s", dev_name(&efidev->dev));
ret = make_directory(path);
@@ -483,7 +488,6 @@ static int efi_fs_probe(struct efi_device *efidev)
ret = 0;
out:
- free(path);
free(device);
return ret;
--
2.39.5
next prev parent reply other threads:[~2024-11-25 15:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-25 15:29 [PATCH 0/7] add proper strdup_const support Ahmad Fatoum
2024-11-25 15:29 ` [PATCH 1/7] sandbox: hostfile: strdup device tree node names Ahmad Fatoum
2024-11-25 15:29 ` [PATCH 2/7] lds: implement is_barebox_rodata Ahmad Fatoum
2024-11-25 15:29 ` [PATCH 3/7] string: implement proper strdup_const/free_const Ahmad Fatoum
2024-11-25 15:29 ` [PATCH 4/7] treewide: replace basename with kbasename Ahmad Fatoum
2024-11-25 15:29 ` [PATCH 5/7] treewide: use strdup_const where appropriate Ahmad Fatoum
2024-11-25 15:29 ` Ahmad Fatoum [this message]
2024-11-25 15:29 ` [PATCH 7/7] cdev: fix string leaks in devfs links Ahmad Fatoum
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=20241125152927.546493-7-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.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