Skip to content

Commit 906ac47

Browse files
Eddie Jamesgregkh
Eddie James
authored andcommitted
tpm: Use managed allocation for bios event log
[ Upstream commit 441b715 ] 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> Stable-dep-of: a3a860bc0fd6 ("tpm: Change to kvalloc() in eventlog/acpi.c") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5e8bee0 commit 906ac47

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

drivers/char/tpm/eventlog/acpi.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* Access to the event log extended by the TCG BIOS of PC platform
1515
*/
1616

17+
#include <linux/device.h>
1718
#include <linux/seq_file.h>
1819
#include <linux/fs.h>
1920
#include <linux/security.h>
@@ -135,7 +136,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
135136
}
136137

137138
/* malloc EventLog space */
138-
log->bios_event_log = kmalloc(len, GFP_KERNEL);
139+
log->bios_event_log = devm_kmalloc(&chip->dev, len, GFP_KERNEL);
139140
if (!log->bios_event_log)
140141
return -ENOMEM;
141142

@@ -164,7 +165,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
164165
return format;
165166

166167
err:
167-
kfree(log->bios_event_log);
168+
devm_kfree(&chip->dev, log->bios_event_log);
168169
log->bios_event_log = NULL;
169170
return ret;
170171
}

drivers/char/tpm/eventlog/efi.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Thiebaud Weksteen <tweek@google.com>
77
*/
88

9+
#include <linux/device.h>
910
#include <linux/efi.h>
1011
#include <linux/tpm_eventlog.h>
1112

@@ -55,7 +56,7 @@ int tpm_read_log_efi(struct tpm_chip *chip)
5556
}
5657

5758
/* malloc EventLog space */
58-
log->bios_event_log = kmemdup(log_tbl->log, log_size, GFP_KERNEL);
59+
log->bios_event_log = devm_kmemdup(&chip->dev, log_tbl->log, log_size, GFP_KERNEL);
5960
if (!log->bios_event_log) {
6061
ret = -ENOMEM;
6162
goto out;
@@ -76,7 +77,7 @@ int tpm_read_log_efi(struct tpm_chip *chip)
7677
MEMREMAP_WB);
7778
if (!final_tbl) {
7879
pr_err("Could not map UEFI TPM final log\n");
79-
kfree(log->bios_event_log);
80+
devm_kfree(&chip->dev, log->bios_event_log);
8081
ret = -ENOMEM;
8182
goto out;
8283
}
@@ -91,11 +92,11 @@ int tpm_read_log_efi(struct tpm_chip *chip)
9192
* Allocate memory for the 'combined log' where we will append the
9293
* 'final events log' to.
9394
*/
94-
tmp = krealloc(log->bios_event_log,
95-
log_size + final_events_log_size,
96-
GFP_KERNEL);
95+
tmp = devm_krealloc(&chip->dev, log->bios_event_log,
96+
log_size + final_events_log_size,
97+
GFP_KERNEL);
9798
if (!tmp) {
98-
kfree(log->bios_event_log);
99+
devm_kfree(&chip->dev, log->bios_event_log);
99100
ret = -ENOMEM;
100101
goto out;
101102
}

drivers/char/tpm/eventlog/of.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Read the event log created by the firmware on PPC64
1111
*/
1212

13+
#include <linux/device.h>
1314
#include <linux/slab.h>
1415
#include <linux/of.h>
1516
#include <linux/tpm_eventlog.h>
@@ -65,7 +66,7 @@ int tpm_read_log_of(struct tpm_chip *chip)
6566
return -EIO;
6667
}
6768

68-
log->bios_event_log = kmemdup(__va(base), size, GFP_KERNEL);
69+
log->bios_event_log = devm_kmemdup(&chip->dev, __va(base), size, GFP_KERNEL);
6970
if (!log->bios_event_log)
7071
return -ENOMEM;
7172

drivers/char/tpm/tpm-chip.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ static void tpm_dev_release(struct device *dev)
267267
idr_remove(&dev_nums_idr, chip->dev_num);
268268
mutex_unlock(&idr_lock);
269269

270-
kfree(chip->log.bios_event_log);
271270
kfree(chip->work_space.context_buf);
272271
kfree(chip->work_space.session_buf);
273272
kfree(chip->allocated_banks);

0 commit comments

Comments
 (0)