Skip to content

Commit 8e80632

Browse files
committed
efi/esrt: Use efi_mem_reserve() and avoid a kmalloc()
We can use the new efi_mem_reserve() API to mark the ESRT table as reserved forever and save ourselves the trouble of copying the data out into a kmalloc buffer. The added advantage is that now the ESRT driver will work across kexec reboot. Tested-by: Dave Young <[email protected]> [kexec/kdump] Tested-by: Ard Biesheuvel <[email protected]> [arm] Acked-by: Ard Biesheuvel <[email protected]> Cc: Leif Lindholm <[email protected]> Cc: Peter Jones <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Mark Rutland <[email protected]> Signed-off-by: Matt Fleming <[email protected]>
1 parent 31ce8cc commit 8e80632

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

drivers/firmware/efi/esrt.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static struct attribute_group esrt_attr_group = {
235235
};
236236

237237
/*
238-
* remap the table, copy it to kmalloced pages, and unmap it.
238+
* remap the table, validate it, mark it reserved and unmap it.
239239
*/
240240
void __init efi_esrt_init(void)
241241
{
@@ -335,7 +335,7 @@ void __init efi_esrt_init(void)
335335

336336
end = esrt_data + size;
337337
pr_info("Reserving ESRT space from %pa to %pa.\n", &esrt_data, &end);
338-
memblock_reserve(esrt_data, esrt_data_size);
338+
efi_mem_reserve(esrt_data, esrt_data_size);
339339

340340
pr_debug("esrt-init: loaded.\n");
341341
err_memunmap:
@@ -382,28 +382,18 @@ static void cleanup_entry_list(void)
382382
static int __init esrt_sysfs_init(void)
383383
{
384384
int error;
385-
struct efi_system_resource_table __iomem *ioesrt;
386385

387386
pr_debug("esrt-sysfs: loading.\n");
388387
if (!esrt_data || !esrt_data_size)
389388
return -ENOSYS;
390389

391-
ioesrt = ioremap(esrt_data, esrt_data_size);
392-
if (!ioesrt) {
390+
esrt = ioremap(esrt_data, esrt_data_size);
391+
if (!esrt) {
393392
pr_err("ioremap(%pa, %zu) failed.\n", &esrt_data,
394393
esrt_data_size);
395394
return -ENOMEM;
396395
}
397396

398-
esrt = kmalloc(esrt_data_size, GFP_KERNEL);
399-
if (!esrt) {
400-
pr_err("kmalloc failed. (wanted %zu bytes)\n", esrt_data_size);
401-
iounmap(ioesrt);
402-
return -ENOMEM;
403-
}
404-
405-
memcpy_fromio(esrt, ioesrt, esrt_data_size);
406-
407397
esrt_kobj = kobject_create_and_add("esrt", efi_kobj);
408398
if (!esrt_kobj) {
409399
pr_err("Firmware table registration failed.\n");
@@ -429,8 +419,6 @@ static int __init esrt_sysfs_init(void)
429419
if (error)
430420
goto err_cleanup_list;
431421

432-
memblock_remove(esrt_data, esrt_data_size);
433-
434422
pr_debug("esrt-sysfs: loaded.\n");
435423

436424
return 0;

0 commit comments

Comments
 (0)