[PATCH 6/7] fs: efi: replace allocation with local buffer

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Nov 25 07:29:26 PST 2024


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 at 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




More information about the barebox mailing list