public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Shawn Guo <shawn.guo@linaro.org>
To: Vladislav Efanov <VEfanov@ispras.ru>
Cc: Andy Gross <agross@kernel.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konrad.dybcio@linaro.org>,
	Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org
Subject: Re: [PATCH] usb: dwc3: qcom: Fix potential memory leak
Date: Thu, 18 May 2023 15:08:30 +0800	[thread overview]
Message-ID: <20230518070830.GA1182568@dragon> (raw)
In-Reply-To: <20230517172518.442591-1-VEfanov@ispras.ru>

On Wed, May 17, 2023 at 08:25:18PM +0300, Vladislav Efanov wrote:
> Function dwc3_qcom_probe() allocates memory for resource structure
> which is pointed by parent_res pointer. This memory is not
> freed. This leads to memory leak. Use stack memory to prevent
> memory leak.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: 2bc02355f8ba ("usb: dwc3: qcom: Add support for booting with ACPI")
> Signed-off-by: Vladislav Efanov <VEfanov@ispras.ru>

Acked-by: Shawn Guo <shawn.guo@linaro.org>

> ---
>  drivers/usb/dwc3/dwc3-qcom.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index 959fc925ca7c..f52241883694 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -791,6 +791,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>  	struct device		*dev = &pdev->dev;
>  	struct dwc3_qcom	*qcom;
>  	struct resource		*res, *parent_res = NULL;
> +	struct resource		local_res;
>  	int			ret, i;
>  	bool			ignore_pipe_clk;
>  	bool			wakeup_source;
> @@ -842,9 +843,8 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>  	if (np) {
>  		parent_res = res;
>  	} else {
> -		parent_res = kmemdup(res, sizeof(struct resource), GFP_KERNEL);
> -		if (!parent_res)
> -			return -ENOMEM;
> +		memcpy(&local_res, res, sizeof(struct resource));
> +		parent_res = &local_res;
>  
>  		parent_res->start = res->start +
>  			qcom->acpi_pdata->qscratch_base_offset;
> -- 
> 2.34.1
> 

      reply	other threads:[~2023-05-18  7:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-17 17:25 [PATCH] usb: dwc3: qcom: Fix potential memory leak Vladislav Efanov
2023-05-18  7:08 ` Shawn Guo [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=20230518070830.GA1182568@dragon \
    --to=shawn.guo@linaro.org \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=VEfanov@ispras.ru \
    --cc=agross@kernel.org \
    --cc=andersson@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=konrad.dybcio@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    /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