public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: Jerry Snitselaar <jsnitsel@redhat.com>,
	Rafael Mendonca <rafaelmendsr@gmail.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>, Vinod Koul <vkoul@kernel.org>,
	dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dmaengine: idxd: Fix memory leak in idxd_alloc()
Date: Fri, 16 Sep 2022 08:49:25 -0700	[thread overview]
Message-ID: <a486a70a-6238-567a-d6a2-32e1269711cd@intel.com> (raw)
In-Reply-To: <20220916153640.qtb74i63upcncpuw@cantor>


On 9/16/2022 8:36 AM, Jerry Snitselaar wrote:
> On Wed, Sep 14, 2022 at 08:08:14PM -0300, Rafael Mendonca wrote:
>> If the IDA id allocation fails, then the allocated memory for the
>> idxd_device struct doesn't get freed before returning NULL, which leads to
>> a memleak.
>>
>> Fixes: 47c16ac27d4c ("dmaengine: idxd: fix idxd conf_dev 'struct device' lifetime")
>> Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>
> I think there needs to be a kfree(idxd) where it checks rc < 0 after the call to dev_set_name() as well, yes?
The idxd_conf_device_release() should take care of freeing idxd with the 
put_device(). So I think we are good here.
>
> Regards,
> Jerry
>
>> ---
>>   drivers/dma/idxd/init.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
>> index aa3478257ddb..fdc97519b8fb 100644
>> --- a/drivers/dma/idxd/init.c
>> +++ b/drivers/dma/idxd/init.c
>> @@ -445,8 +445,10 @@ static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_d
>>   	idxd->data = data;
>>   	idxd_dev_set_type(&idxd->idxd_dev, idxd->data->type);
>>   	idxd->id = ida_alloc(&idxd_ida, GFP_KERNEL);
>> -	if (idxd->id < 0)
>> +	if (idxd->id < 0) {
>> +		kfree(idxd);
>>   		return NULL;
>> +	}
>>   
>>   	device_initialize(conf_dev);
>>   	conf_dev->parent = dev;
>> -- 
>> 2.34.1
>>

  reply	other threads:[~2022-09-16 15:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-14 23:08 [PATCH] dmaengine: idxd: Fix memory leak in idxd_alloc() Rafael Mendonca
2022-09-16 15:36 ` Jerry Snitselaar
2022-09-16 15:49   ` Dave Jiang [this message]
2022-09-16 16:16     ` Jerry Snitselaar
2022-09-16 15:50 ` Dave Jiang
2022-09-16 16:17 ` Jerry Snitselaar
2022-09-29 16:37 ` Vinod Koul

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=a486a70a-6238-567a-d6a2-32e1269711cd@intel.com \
    --to=dave.jiang@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=fenghua.yu@intel.com \
    --cc=jsnitsel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafaelmendsr@gmail.com \
    --cc=vkoul@kernel.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