* [PATCH 1/3] tpm: Put the TCPA table buf after using it
@ 2020-07-17 11:45 Hanjun Guo
2020-07-17 11:45 ` [PATCH 2/3] tpm: tpm_crb: Put the TPM2 table " Hanjun Guo
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Hanjun Guo @ 2020-07-17 11:45 UTC (permalink / raw)
To: Peter Huewe, Jarkko Sakkinen, Jason Gunthorpe; +Cc: linux-integrity, Hanjun Guo
The acpi_get_table() should be coupled with acpi_put_table() if
the mapped table is not used for runtime to release the table
mapping, put the TCPA table buf after using it.
Signed-off-by: Hanjun Guo <guohanjun@huawei.com>
---
drivers/char/tpm/eventlog/acpi.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/char/tpm/eventlog/acpi.c b/drivers/char/tpm/eventlog/acpi.c
index 63ada5e..e8ac30b 100644
--- a/drivers/char/tpm/eventlog/acpi.c
+++ b/drivers/char/tpm/eventlog/acpi.c
@@ -79,6 +79,9 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
start = buff->client.log_start_addr;
break;
}
+
+ acpi_put_table((struct acpi_table_header *)buff);
+
if (!len) {
dev_warn(&chip->dev, "%s: TCPA log area empty\n", __func__);
return -EIO;
--
1.7.12.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] tpm: tpm_crb: Put the TPM2 table after using it
2020-07-17 11:45 [PATCH 1/3] tpm: Put the TCPA table buf after using it Hanjun Guo
@ 2020-07-17 11:45 ` Hanjun Guo
2020-07-17 11:45 ` [PATCH 3/3] tpm: tpm_tis: " Hanjun Guo
2020-07-23 3:21 ` [PATCH 1/3] tpm: Put the TCPA table buf " Jarkko Sakkinen
2 siblings, 0 replies; 5+ messages in thread
From: Hanjun Guo @ 2020-07-17 11:45 UTC (permalink / raw)
To: Peter Huewe, Jarkko Sakkinen, Jason Gunthorpe; +Cc: linux-integrity, Hanjun Guo
The ACPI table buffer should be put to release the table
mapping if the buffer is not used for runtime.
Signed-off-by: Hanjun Guo <guohanjun@huawei.com>
---
drivers/char/tpm/tpm_crb.c | 28 +++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
index a9dcf31..5bb4d11 100644
--- a/drivers/char/tpm/tpm_crb.c
+++ b/drivers/char/tpm/tpm_crb.c
@@ -676,12 +676,16 @@ static int crb_acpi_add(struct acpi_device *device)
/* Should the FIFO driver handle this? */
sm = buf->start_method;
- if (sm == ACPI_TPM2_MEMORY_MAPPED)
- return -ENODEV;
+ if (sm == ACPI_TPM2_MEMORY_MAPPED) {
+ rc = -ENODEV;
+ goto out;
+ }
priv = devm_kzalloc(dev, sizeof(struct crb_priv), GFP_KERNEL);
- if (!priv)
- return -ENOMEM;
+ if (!priv) {
+ rc = -ENOMEM;
+ goto out;
+ }
if (sm == ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC) {
if (buf->header.length < (sizeof(*buf) + sizeof(*crb_smc))) {
@@ -689,7 +693,8 @@ static int crb_acpi_add(struct acpi_device *device)
FW_BUG "TPM2 ACPI table has wrong size %u for start method type %d\n",
buf->header.length,
ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC);
- return -EINVAL;
+ rc = -EINVAL;
+ goto out;
}
crb_smc = ACPI_ADD_PTR(struct tpm2_crb_smc, buf, sizeof(*buf));
priv->smc_func_id = crb_smc->smc_func_id;
@@ -700,17 +705,22 @@ static int crb_acpi_add(struct acpi_device *device)
rc = crb_map_io(device, priv, buf);
if (rc)
- return rc;
+ goto out;
chip = tpmm_chip_alloc(dev, &tpm_crb);
- if (IS_ERR(chip))
- return PTR_ERR(chip);
+ if (IS_ERR(chip)) {
+ rc = PTR_ERR(chip);
+ goto out;
+ }
dev_set_drvdata(&chip->dev, priv);
chip->acpi_dev_handle = device->handle;
chip->flags = TPM_CHIP_FLAG_TPM2;
- return tpm_chip_register(chip);
+ rc = tpm_chip_register(chip);
+out:
+ acpi_put_table((struct acpi_table_header *)buf);
+ return rc;
}
static int crb_acpi_remove(struct acpi_device *device)
--
1.7.12.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] tpm: tpm_tis: Put the TPM2 table after using it
2020-07-17 11:45 [PATCH 1/3] tpm: Put the TCPA table buf after using it Hanjun Guo
2020-07-17 11:45 ` [PATCH 2/3] tpm: tpm_crb: Put the TPM2 table " Hanjun Guo
@ 2020-07-17 11:45 ` Hanjun Guo
2020-07-23 3:21 ` [PATCH 1/3] tpm: Put the TCPA table buf " Jarkko Sakkinen
2 siblings, 0 replies; 5+ messages in thread
From: Hanjun Guo @ 2020-07-17 11:45 UTC (permalink / raw)
To: Peter Huewe, Jarkko Sakkinen, Jason Gunthorpe; +Cc: linux-integrity, Hanjun Guo
The ACPI table buffer should be put to release the table
mapping.
Signed-off-by: Hanjun Guo <guohanjun@huawei.com>
---
drivers/char/tpm/tpm_tis.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index e7df342..59b25c1 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -102,6 +102,7 @@ static int check_acpi_tpm2(struct device *dev)
const struct acpi_device_id *aid = acpi_match_device(tpm_acpi_tbl, dev);
struct acpi_table_tpm2 *tbl;
acpi_status st;
+ int ret = 0;
if (!aid || aid->driver_data != DEVICE_IS_TPM2)
return 0;
@@ -109,8 +110,7 @@ static int check_acpi_tpm2(struct device *dev)
/* If the ACPI TPM2 signature is matched then a global ACPI_SIG_TPM2
* table is mandatory
*/
- st =
- acpi_get_table(ACPI_SIG_TPM2, 1, (struct acpi_table_header **)&tbl);
+ st = acpi_get_table(ACPI_SIG_TPM2, 1, (struct acpi_table_header **)&tbl);
if (ACPI_FAILURE(st) || tbl->header.length < sizeof(*tbl)) {
dev_err(dev, FW_BUG "failed to get TPM2 ACPI table\n");
return -EINVAL;
@@ -118,9 +118,10 @@ static int check_acpi_tpm2(struct device *dev)
/* The tpm2_crb driver handles this device */
if (tbl->start_method != ACPI_TPM2_MEMORY_MAPPED)
- return -ENODEV;
+ ret = -ENODEV;
- return 0;
+ acpi_put_table((struct acpi_table_header *)tbl);
+ return ret;
}
#else
static int check_acpi_tpm2(struct device *dev)
--
1.7.12.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/3] tpm: Put the TCPA table buf after using it
2020-07-17 11:45 [PATCH 1/3] tpm: Put the TCPA table buf after using it Hanjun Guo
2020-07-17 11:45 ` [PATCH 2/3] tpm: tpm_crb: Put the TPM2 table " Hanjun Guo
2020-07-17 11:45 ` [PATCH 3/3] tpm: tpm_tis: " Hanjun Guo
@ 2020-07-23 3:21 ` Jarkko Sakkinen
2020-07-23 3:43 ` Hanjun Guo
2 siblings, 1 reply; 5+ messages in thread
From: Jarkko Sakkinen @ 2020-07-23 3:21 UTC (permalink / raw)
To: Hanjun Guo; +Cc: Peter Huewe, Jason Gunthorpe, linux-integrity
On Fri, Jul 17, 2020 at 07:45:46PM +0800, Hanjun Guo wrote:
> The acpi_get_table() should be coupled with acpi_put_table() if
> the mapped table is not used for runtime to release the table
> mapping, put the TCPA table buf after using it.
>
> Signed-off-by: Hanjun Guo <guohanjun@huawei.com>
In a commit message you should first describe the action taken and
then the rationale of doing that e.g. "Couple acpi_get_table() with
acpi_put_table() in order to prevent a memory leak."
In addition, please put a fixes tag.
Please read the section two from the submitting patches guide:
https://www.kernel.org/doc/html/v4.17/process/submitting-patches.html
Thank you.
/Jarkko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/3] tpm: Put the TCPA table buf after using it
2020-07-23 3:21 ` [PATCH 1/3] tpm: Put the TCPA table buf " Jarkko Sakkinen
@ 2020-07-23 3:43 ` Hanjun Guo
0 siblings, 0 replies; 5+ messages in thread
From: Hanjun Guo @ 2020-07-23 3:43 UTC (permalink / raw)
To: Jarkko Sakkinen; +Cc: Peter Huewe, Jason Gunthorpe, linux-integrity
On 2020/7/23 11:21, Jarkko Sakkinen wrote:
> On Fri, Jul 17, 2020 at 07:45:46PM +0800, Hanjun Guo wrote:
>> The acpi_get_table() should be coupled with acpi_put_table() if
>> the mapped table is not used for runtime to release the table
>> mapping, put the TCPA table buf after using it.
>>
>> Signed-off-by: Hanjun Guo <guohanjun@huawei.com>
>
> In a commit message you should first describe the action taken and
> then the rationale of doing that e.g. "Couple acpi_get_table() with
> acpi_put_table() in order to prevent a memory leak."
>
> In addition, please put a fixes tag.
>
> Please read the section two from the submitting patches guide:
>
> https://www.kernel.org/doc/html/v4.17/process/submitting-patches.html
Thanks for the comments, I will update this patch set
and send a new version.
Thanks
Hanjun
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-07-23 3:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-17 11:45 [PATCH 1/3] tpm: Put the TCPA table buf after using it Hanjun Guo
2020-07-17 11:45 ` [PATCH 2/3] tpm: tpm_crb: Put the TPM2 table " Hanjun Guo
2020-07-17 11:45 ` [PATCH 3/3] tpm: tpm_tis: " Hanjun Guo
2020-07-23 3:21 ` [PATCH 1/3] tpm: Put the TCPA table buf " Jarkko Sakkinen
2020-07-23 3:43 ` Hanjun Guo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).