mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	markgross@kernel.org
Cc: platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org, Dan Carpenter <error27@gmail.com>
Subject: Re: [PATCH] platform/x86/intel/tpmi: Fix double free reported by Smatch
Date: Wed, 1 Mar 2023 13:42:29 +0100	[thread overview]
Message-ID: <984e2340-6d9d-f7b6-a638-b70a3ed40a32@redhat.com> (raw)
In-Reply-To: <20230227140614.2913474-1-srinivas.pandruvada@linux.intel.com>

Hi,

On 2/27/23 15:06, Srinivas Pandruvada wrote:
> Fix warning:
> drivers/platform/x86/intel/tpmi.c:253 tpmi_create_device()
> 	warn: 'feature_vsec_dev' was already freed.
> 
> If there is some error, feature_vsec_dev memory is freed as part
> of resource managed call intel_vsec_add_aux(). So, additional
> kfree() call is not required.
> 
> Reordered res allocation and feature_vsec_dev, so that on error
> only res is freed.
> 
> Reported-by: Dan Carpenter <error27@gmail.com>
> Link: https://lore.kernel.org/platform-driver-x86/Y%2FxYR7WGiPayZu%2FR@kili/T/#u
> Fixes: 47731fd2865f ("platform/x86/intel: Intel TPMI enumeration driver")
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>

Thanks, I've applied this patch to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

I'll rebase that branch once 6.3-rc1 is out and then push the rebased
patch to the fixes branch and include it in my next 6.3 fixes pull-req
to Linus.

Regards,

Hans





> ---
>  drivers/platform/x86/intel/tpmi.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/platform/x86/intel/tpmi.c b/drivers/platform/x86/intel/tpmi.c
> index c60733261c89..c999732b0f1e 100644
> --- a/drivers/platform/x86/intel/tpmi.c
> +++ b/drivers/platform/x86/intel/tpmi.c
> @@ -209,14 +209,14 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info,
>  	if (!name)
>  		return -EOPNOTSUPP;
>  
> -	feature_vsec_dev = kzalloc(sizeof(*feature_vsec_dev), GFP_KERNEL);
> -	if (!feature_vsec_dev)
> +	res = kcalloc(pfs->pfs_header.num_entries, sizeof(*res), GFP_KERNEL);
> +	if (!res)
>  		return -ENOMEM;
>  
> -	res = kcalloc(pfs->pfs_header.num_entries, sizeof(*res), GFP_KERNEL);
> -	if (!res) {
> +	feature_vsec_dev = kzalloc(sizeof(*feature_vsec_dev), GFP_KERNEL);
> +	if (!feature_vsec_dev) {
>  		ret = -ENOMEM;
> -		goto free_vsec;
> +		goto free_res;
>  	}
>  
>  	snprintf(feature_id_name, sizeof(feature_id_name), "tpmi-%s", name);
> @@ -239,6 +239,8 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info,
>  	/*
>  	 * intel_vsec_add_aux() is resource managed, no explicit
>  	 * delete is required on error or on module unload.
> +	 * feature_vsec_dev memory is also freed as part of device
> +	 * delete.
>  	 */
>  	ret = intel_vsec_add_aux(vsec_dev->pcidev, &vsec_dev->auxdev.dev,
>  				 feature_vsec_dev, feature_id_name);
> @@ -249,8 +251,6 @@ static int tpmi_create_device(struct intel_tpmi_info *tpmi_info,
>  
>  free_res:
>  	kfree(res);
> -free_vsec:
> -	kfree(feature_vsec_dev);
>  
>  	return ret;
>  }


      reply	other threads:[~2023-03-01 12:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-27 14:06 Srinivas Pandruvada
2023-03-01 12:42 ` Hans de Goede [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=984e2340-6d9d-f7b6-a638-b70a3ed40a32@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=error27@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markgross@kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=srinivas.pandruvada@linux.intel.com \
    /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

all inboxes | Powered by JetHome®