Commit 441b7152 authored by Eddie James's avatar Eddie James Committed by Jarkko Sakkinen

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: default avatarEddie James <eajames@linux.ibm.com>
Tested-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
parent 40078327
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
* Access to the event log extended by the TCG BIOS of PC platform * Access to the event log extended by the TCG BIOS of PC platform
*/ */
#include <linux/device.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/security.h> #include <linux/security.h>
...@@ -135,7 +136,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip) ...@@ -135,7 +136,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
} }
/* malloc EventLog space */ /* malloc EventLog space */
log->bios_event_log = kmalloc(len, GFP_KERNEL); log->bios_event_log = devm_kmalloc(&chip->dev, len, GFP_KERNEL);
if (!log->bios_event_log) if (!log->bios_event_log)
return -ENOMEM; return -ENOMEM;
...@@ -160,7 +161,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip) ...@@ -160,7 +161,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
return format; return format;
err: err:
kfree(log->bios_event_log); devm_kfree(&chip->dev, log->bios_event_log);
log->bios_event_log = NULL; log->bios_event_log = NULL;
return ret; return ret;
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* Thiebaud Weksteen <tweek@google.com> * Thiebaud Weksteen <tweek@google.com>
*/ */
#include <linux/device.h>
#include <linux/efi.h> #include <linux/efi.h>
#include <linux/tpm_eventlog.h> #include <linux/tpm_eventlog.h>
...@@ -55,7 +56,7 @@ int tpm_read_log_efi(struct tpm_chip *chip) ...@@ -55,7 +56,7 @@ int tpm_read_log_efi(struct tpm_chip *chip)
} }
/* malloc EventLog space */ /* malloc EventLog space */
log->bios_event_log = kmemdup(log_tbl->log, log_size, GFP_KERNEL); log->bios_event_log = devm_kmemdup(&chip->dev, log_tbl->log, log_size, GFP_KERNEL);
if (!log->bios_event_log) { if (!log->bios_event_log) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
...@@ -76,7 +77,7 @@ int tpm_read_log_efi(struct tpm_chip *chip) ...@@ -76,7 +77,7 @@ int tpm_read_log_efi(struct tpm_chip *chip)
MEMREMAP_WB); MEMREMAP_WB);
if (!final_tbl) { if (!final_tbl) {
pr_err("Could not map UEFI TPM final log\n"); pr_err("Could not map UEFI TPM final log\n");
kfree(log->bios_event_log); devm_kfree(&chip->dev, log->bios_event_log);
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
...@@ -91,11 +92,11 @@ int tpm_read_log_efi(struct tpm_chip *chip) ...@@ -91,11 +92,11 @@ int tpm_read_log_efi(struct tpm_chip *chip)
* Allocate memory for the 'combined log' where we will append the * Allocate memory for the 'combined log' where we will append the
* 'final events log' to. * 'final events log' to.
*/ */
tmp = krealloc(log->bios_event_log, tmp = devm_krealloc(&chip->dev, log->bios_event_log,
log_size + final_events_log_size, log_size + final_events_log_size,
GFP_KERNEL); GFP_KERNEL);
if (!tmp) { if (!tmp) {
kfree(log->bios_event_log); devm_kfree(&chip->dev, log->bios_event_log);
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
* Read the event log created by the firmware on PPC64 * Read the event log created by the firmware on PPC64
*/ */
#include <linux/device.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/tpm_eventlog.h> #include <linux/tpm_eventlog.h>
...@@ -65,7 +66,7 @@ int tpm_read_log_of(struct tpm_chip *chip) ...@@ -65,7 +66,7 @@ int tpm_read_log_of(struct tpm_chip *chip)
return -EIO; return -EIO;
} }
log->bios_event_log = kmemdup(__va(base), size, GFP_KERNEL); log->bios_event_log = devm_kmemdup(&chip->dev, __va(base), size, GFP_KERNEL);
if (!log->bios_event_log) if (!log->bios_event_log)
return -ENOMEM; return -ENOMEM;
......
...@@ -267,7 +267,6 @@ static void tpm_dev_release(struct device *dev) ...@@ -267,7 +267,6 @@ static void tpm_dev_release(struct device *dev)
idr_remove(&dev_nums_idr, chip->dev_num); idr_remove(&dev_nums_idr, chip->dev_num);
mutex_unlock(&idr_lock); mutex_unlock(&idr_lock);
kfree(chip->log.bios_event_log);
kfree(chip->work_space.context_buf); kfree(chip->work_space.context_buf);
kfree(chip->work_space.session_buf); kfree(chip->work_space.session_buf);
kfree(chip->allocated_banks); kfree(chip->allocated_banks);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment