tpm: Put the TCPA table buf after using it
Subsystems (2)
PATCH 1/3 tpm: Put the TCPA table buf after using it
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.
--- drivers/char/tpm/eventlog/acpi.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/char/tpm/eventlog/acpi.c +3 -0
@@ -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 ;
Signature · 1 line
1.7.12.4
PATCH 2/3 tpm: tpm_crb: Put the TPM2 table after using it
The ACPI table buffer should be put to release the table mapping if the buffer is not used for runtime.
--- drivers/char/tpm/tpm_crb.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
drivers/char/tpm/tpm_crb.c +19 -9
@@ -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)
Signature · 1 line
1.7.12.4
PATCH 3/3 tpm: tpm_tis: Put the TPM2 table after using it
In reply to Hanjun GuoThe ACPI table buffer should be put to release the table mapping.
--- drivers/char/tpm/tpm_tis.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/char/tpm/tpm_tis.c +5 -4
@@ -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)
Signature · 1 line
1.7.12.4
Quoted 5 lines · Hanjun Guo
The
acpi_get_table()should be coupled withacpi_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 <[email protected]>
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
Quoted 11 lines · Jarkko Sakkinen
Quoted 5 lines · Hanjun Guo
The
acpi_get_table()should be coupled withacpi_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 <[email protected]>In a commit message you should first describe the action taken and then the rationale of doing that e.g. "Couple
acpi_get_table()withacpi_put_table()in order to prevent a memory leak."
Quoted 5 lines
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