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@xxxxxxxxxxxxxx> --- 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