mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: shangxiaojing <shangxiaojing@huawei.com>
To: Ian Abbott <abbotti@mev.co.uk>, <hsweeten@visionengravers.com>,
	<gregkh@linuxfoundation.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] comedi: drivers: pcl730: Fix potential memory leak in pcl730_attach()
Date: Tue, 22 Nov 2022 20:24:09 +0800	[thread overview]
Message-ID: <2f4dc5e8-1b2c-e071-a363-d3f509cc4ccc@huawei.com> (raw)
In-Reply-To: <94fee07a-0ac4-fba7-23cb-0a9da42e25d0@mev.co.uk>



On 2022/11/22 20:18, Ian Abbott wrote:
> On 22/11/2022 12:04, Shang XiaoJing wrote:
>> pcl730_attach() calls comedi_request_region() and won't release the
>> resource allocated by alloc_resource() when pcl730_attach() failed 
>> latter.
>> Add release_region() to prevent memory leak.
>>
>> Fixes: 6f9aa29b47f6 ("staging: comedi: pcl730: use 
>> comedi_request_region()")
>> Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
>> ---
>>   drivers/comedi/drivers/pcl730.c | 8 +++++++-
>>   1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/comedi/drivers/pcl730.c 
>> b/drivers/comedi/drivers/pcl730.c
>> index d2733cd5383d..c463de8a14e1 100644
>> --- a/drivers/comedi/drivers/pcl730.c
>> +++ b/drivers/comedi/drivers/pcl730.c
>> @@ -274,8 +274,14 @@ static int pcl730_attach(struct comedi_device *dev,
>>           return ret;
>>       ret = comedi_alloc_subdevices(dev, board->n_subdevs);
>> -    if (ret)
>> +    if (ret) {
>> +        if (dev->iobase && dev->iolen) {
>> +            release_region(dev->iobase, dev->iolen);
>> +            dev->iobase = 0;
>> +            dev->iolen = 0;
>> +        }
>>           return ret;
>> +    }
>>       subdev = 0;
> 
> This is not needed.  If the 'attach' handler pcl730_attach() returns an 
> error, the 'detach' handler comedi_legacy_detach() will be called to 
> clean up the allocated resources.  All the comedi drivers work that way. 
> (A lot of them have an 'auto_attach' handler instead of an 'attach' 
> handler, but the error handling is basically the same.)
> 

ok, thanks for the advice!

Thanks,
-- 
Shang XiaoJing

      reply	other threads:[~2022-11-22 12:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-22 12:04 Shang XiaoJing
2022-11-22 12:18 ` Ian Abbott
2022-11-22 12:24   ` shangxiaojing [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=2f4dc5e8-1b2c-e071-a363-d3f509cc4ccc@huawei.com \
    --to=shangxiaojing@huawei.com \
    --cc=abbotti@mev.co.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=hsweeten@visionengravers.com \
    --cc=linux-kernel@vger.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

all inboxes | Powered by JetHome®