linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Hanjun Guo <guohanjun@huawei.com>
Cc: linux-integrity@vger.kernel.org, Peter Huewe <peterhuewe@gmx.de>
Subject: Re: [PATCH 3/3] tpm: tpm_tis: Add the missed acpi_put_table() to fix memory leak
Date: Wed, 16 Nov 2022 01:52:36 +0200	[thread overview]
Message-ID: <Y3QmRNk6rPuoWQjA@kernel.org> (raw)
In-Reply-To: <1667966622-19711-4-git-send-email-guohanjun@huawei.com>

On Wed, Nov 09, 2022 at 12:03:42PM +0800, Hanjun Guo wrote:
> In check_acpi_tpm2(), we get the TPM2 table just to make
> sure the table is there, not used after the init, so the
> acpi_put_table() should be added to release the ACPI memory.
> 
> Fixes: 4cb586a188d4 ("tpm_tis: Consolidate the platform and acpi probe flow")
> 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 bcff642..ed5dabd 100644
> --- a/drivers/char/tpm/tpm_tis.c
> +++ b/drivers/char/tpm/tpm_tis.c
> @@ -125,6 +125,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;
> @@ -132,8 +133,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;
> @@ -141,9 +141,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
> 

Ditto.

BR, Jarkko

      reply	other threads:[~2022-11-15 23:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09  4:03 [PATCH 0/3] ACPI table release for TPM drivers Hanjun Guo
2022-11-09  4:03 ` [PATCH 1/3] tpm: acpi: Call acpi_put_table() to fix memory leak Hanjun Guo
2022-11-15 23:51   ` Jarkko Sakkinen
2022-11-17  9:16     ` Hanjun Guo
2022-11-09  4:03 ` [PATCH 2/3] tpm: tpm_crb: Add the missed " Hanjun Guo
2022-11-15 23:52   ` Jarkko Sakkinen
2022-11-09  4:03 ` [PATCH 3/3] tpm: tpm_tis: " Hanjun Guo
2022-11-15 23:52   ` Jarkko Sakkinen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y3QmRNk6rPuoWQjA@kernel.org \
    --to=jarkko@kernel.org \
    --cc=guohanjun@huawei.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).