Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tpm: Use managed allocation for bios event log

Since the bios event log is freed in the device release function,
let devres handle the deallocation. This will allow other memory
allocation/mapping functions to be used for the bios event log.

Signed-off-by: Eddie James <eajames@linux.ibm.com>
Tested-by: Jarkko Sakkinen <jarkko@kernel.org>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>

authored by

Eddie James and committed by
Jarkko Sakkinen
441b7152 40078327

+12 -10
+3 -2
drivers/char/tpm/eventlog/acpi.c
··· 14 14 * Access to the event log extended by the TCG BIOS of PC platform 15 15 */ 16 16 17 + #include <linux/device.h> 17 18 #include <linux/seq_file.h> 18 19 #include <linux/fs.h> 19 20 #include <linux/security.h> ··· 136 135 } 137 136 138 137 /* malloc EventLog space */ 139 - log->bios_event_log = kmalloc(len, GFP_KERNEL); 138 + log->bios_event_log = devm_kmalloc(&chip->dev, len, GFP_KERNEL); 140 139 if (!log->bios_event_log) 141 140 return -ENOMEM; 142 141 ··· 161 160 return format; 162 161 163 162 err: 164 - kfree(log->bios_event_log); 163 + devm_kfree(&chip->dev, log->bios_event_log); 165 164 log->bios_event_log = NULL; 166 165 return ret; 167 166 }
+7 -6
drivers/char/tpm/eventlog/efi.c
··· 6 6 * Thiebaud Weksteen <tweek@google.com> 7 7 */ 8 8 9 + #include <linux/device.h> 9 10 #include <linux/efi.h> 10 11 #include <linux/tpm_eventlog.h> 11 12 ··· 56 55 } 57 56 58 57 /* malloc EventLog space */ 59 - log->bios_event_log = kmemdup(log_tbl->log, log_size, GFP_KERNEL); 58 + log->bios_event_log = devm_kmemdup(&chip->dev, log_tbl->log, log_size, GFP_KERNEL); 60 59 if (!log->bios_event_log) { 61 60 ret = -ENOMEM; 62 61 goto out; ··· 77 76 MEMREMAP_WB); 78 77 if (!final_tbl) { 79 78 pr_err("Could not map UEFI TPM final log\n"); 80 - kfree(log->bios_event_log); 79 + devm_kfree(&chip->dev, log->bios_event_log); 81 80 ret = -ENOMEM; 82 81 goto out; 83 82 } ··· 92 91 * Allocate memory for the 'combined log' where we will append the 93 92 * 'final events log' to. 94 93 */ 95 - tmp = krealloc(log->bios_event_log, 96 - log_size + final_events_log_size, 97 - GFP_KERNEL); 94 + tmp = devm_krealloc(&chip->dev, log->bios_event_log, 95 + log_size + final_events_log_size, 96 + GFP_KERNEL); 98 97 if (!tmp) { 99 - kfree(log->bios_event_log); 98 + devm_kfree(&chip->dev, log->bios_event_log); 100 99 ret = -ENOMEM; 101 100 goto out; 102 101 }
+2 -1
drivers/char/tpm/eventlog/of.c
··· 10 10 * Read the event log created by the firmware on PPC64 11 11 */ 12 12 13 + #include <linux/device.h> 13 14 #include <linux/slab.h> 14 15 #include <linux/of.h> 15 16 #include <linux/tpm_eventlog.h> ··· 66 65 return -EIO; 67 66 } 68 67 69 - log->bios_event_log = kmemdup(__va(base), size, GFP_KERNEL); 68 + log->bios_event_log = devm_kmemdup(&chip->dev, __va(base), size, GFP_KERNEL); 70 69 if (!log->bios_event_log) 71 70 return -ENOMEM; 72 71
-1
drivers/char/tpm/tpm-chip.c
··· 267 267 idr_remove(&dev_nums_idr, chip->dev_num); 268 268 mutex_unlock(&idr_lock); 269 269 270 - kfree(chip->log.bios_event_log); 271 270 kfree(chip->work_space.context_buf); 272 271 kfree(chip->work_space.session_buf); 273 272 kfree(chip->allocated_banks);