linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Liu Shuo <b35362@freescale.com>,
	Prabhakar Kushwaha <prabhakar@freescale.com>,
	Li Yang <leoyang.li@nxp.com>,
	Dipen Dudhat <Dipen.Dudhat@freescale.com>,
	linux-kernel@vger.kernel.org, Raghav Dogra <raghav.dogra@nxp.com>
Subject: Re: [RFT PATCH 2/2] memory: fsl_ifc: fix leak of private memory on probe failure
Date: Thu, 27 May 2021 11:19:30 -0400	[thread overview]
Message-ID: <e1f9d072-872b-3301-5a3e-b40c2150f10d@canonical.com> (raw)
In-Reply-To: <20210527150109.GO24442@kadam>

On 27/05/2021 11:01, Dan Carpenter wrote:
> On Thu, May 27, 2021 at 10:42:40AM -0400, Krzysztof Kozlowski wrote:
>> On probe error the driver should free the memory allocated for private
>> structure.  Fix this by using resource-managed allocation.
>>
>> Fixes: a20cbdeffce2 ("powerpc/fsl: Add support for Integrated Flash Controller")
>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
>>
>> ---
>>
>> Only build tested.
>> ---
>>  drivers/memory/fsl_ifc.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/memory/fsl_ifc.c b/drivers/memory/fsl_ifc.c
>> index a6324044a085..3ee7183b20fb 100644
>> --- a/drivers/memory/fsl_ifc.c
>> +++ b/drivers/memory/fsl_ifc.c
>> @@ -209,7 +209,8 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
>>  
>>  	dev_info(&dev->dev, "Freescale Integrated Flash Controller\n");
>>  
>> -	fsl_ifc_ctrl_dev = kzalloc(sizeof(*fsl_ifc_ctrl_dev), GFP_KERNEL);
>> +	fsl_ifc_ctrl_dev = devm_kzalloc(&dev->dev, sizeof(*fsl_ifc_ctrl_dev),
>> +					GFP_KERNEL);
>>  	if (!fsl_ifc_ctrl_dev)
>>  		return -ENOMEM;
> 
> You'd need to remove the kfree(ctrl) in the remove function as well or
> it will lead to a double free.

Yeah, thanks, I spotted it now also looking for more leaks.
> 
> Unrelated to your patch but related to Smatch.  The Smatch check for
> resource leaks which I mentioned check_unwind.c doesn't look for
> kmalloc() leaks because those are quite complicated to deal with.
> kmalloc() allocations are so much more common and that if you have a 5%
> false positive rate, then it's just overwhelming.  There is a separate
> Smatch check for that but it's garbage and I need to re-write it.

Indeed I was thinking about this kmalloc. It should be the last one -
the IRQs seem to be handled.



Best regards,
Krzysztof

      reply	other threads:[~2021-05-27 15:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-27 14:42 [RFT PATCH 1/2] memory: fsl_ifc: fix leaking IO mapping on probe failure Krzysztof Kozlowski
2021-05-27 14:42 ` [RFT PATCH 2/2] memory: fsl_ifc: fix leak of private memory " Krzysztof Kozlowski
2021-05-27 15:01   ` Dan Carpenter
2021-05-27 15:19     ` Krzysztof Kozlowski [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=e1f9d072-872b-3301-5a3e-b40c2150f10d@canonical.com \
    --to=krzysztof.kozlowski@canonical.com \
    --cc=Dipen.Dudhat@freescale.com \
    --cc=b35362@freescale.com \
    --cc=dan.carpenter@oracle.com \
    --cc=leoyang.li@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=prabhakar@freescale.com \
    --cc=raghav.dogra@nxp.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;
as well as URLs for NNTP newsgroup(s).