public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: balbi@ti.com (Felipe Balbi)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: OMAP-USB: Fix possible memory leak
Date: Thu, 2 May 2013 19:40:58 +0300	[thread overview]
Message-ID: <20130502164058.GC8577@arwen.pp.htv.fi> (raw)
In-Reply-To: <1367512124.978518915@f372.mail.ru>

Hi,

On Thu, May 02, 2013 at 08:28:44PM +0400, Alexander Shiyan wrote:
> > On 20:03-20130502, Alexander Shiyan wrote:
> > > 
> > > Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> > > ---
> > >  arch/arm/mach-omap2/usb-host.c | 21 +++++++++++++++++----
> > >  1 file changed, 17 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/arch/arm/mach-omap2/usb-host.c b/arch/arm/mach-omap2/usb-host.c
> > > index aa27d7f..8d17a0d 100644
> > > --- a/arch/arm/mach-omap2/usb-host.c
> > > +++ b/arch/arm/mach-omap2/usb-host.c
> > > @@ -570,8 +570,10 @@ static int usbhs_add_regulator(char *name, char *dev_id, char *dev_supply,
> > >  	supplies->dev_name = dev_id;
> > >  
> > >  	reg_data = kzalloc(sizeof(*reg_data), GFP_KERNEL);
> > > -	if (!reg_data)
> > > +	if (!reg_data) {
> > > +		kfree(supplies);
> > >  		return -ENOMEM;
> > > +	}
> > >  
> > >  	reg_data->constraints.valid_ops_mask = REGULATOR_CHANGE_STATUS;
> > >  	reg_data->consumer_supplies = supplies;
> > > @@ -579,8 +581,11 @@ static int usbhs_add_regulator(char *name, char *dev_id, char *dev_supply,
> > >  
> > >  	config = kmemdup(&hsusb_reg_config, sizeof(hsusb_reg_config),
> > >  			GFP_KERNEL);
> > > -	if (!config)
> > > +	if (!config) {
> > > +		kfree(supplies);
> > > +		kfree(reg_data);
> > >  		return -ENOMEM;
> > > +	}
> > >  
> > >  	config->supply_name = name;
> > >  	config->gpio = gpio;
> > > @@ -589,17 +594,25 @@ static int usbhs_add_regulator(char *name, char *dev_id, char *dev_supply,
> > >  
> > >  	/* create a regulator device */
> > >  	pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
> > > -	if (!pdev)
> > > +	if (!pdev) {
> > > +		kfree(supplies);
> > > +		kfree(reg_data);
> > > +		kfree(config);
> > >  		return -ENOMEM;
> > > +	}
> > >  
> > >  	pdev->id = PLATFORM_DEVID_AUTO;
> > >  	pdev->name = reg_name;
> > >  	pdev->dev.platform_data = config;
> > >  
> > >  	ret = platform_device_register(pdev);
> > > -	if (ret)
> > > +	if (ret) {
> > >  		pr_err("%s: Failed registering regulator %s for %s\n",
> > >  				__func__, name, dev_id);
> > > +		kfree(supplies);
> > > +		kfree(reg_data);
> > > +		kfree(config);
> > > +	}
> > 
> > Might be better to switch to devm_XXX managed functions?

I don't think it makes sense since the platform_device hasn't been
registered yet.

Still, patch can be improved with proper goto labels instead of
sprinkling different kfree() calls in every single error branch.

> If anyone can rewrite driver to use devm_xx, it would have been better.
> I'm not going to redo the patch yet, let it be so, I just showed a point
> for OMAP-developers.

fair enough.

-- 
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130502/4c5991d0/attachment.sig>

  reply	other threads:[~2013-05-02 16:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-02 16:03 [PATCH] ARM: OMAP-USB: Fix possible memory leak Alexander Shiyan
2013-05-02 16:24 ` Nishanth Menon
2013-05-02 16:28   ` Re[2]: " Alexander Shiyan
2013-05-02 16:40     ` Felipe Balbi [this message]
2013-05-02 23:13       ` Russell King - ARM Linux
2013-05-03  6:21         ` Felipe Balbi
2013-05-03  6:25           ` Felipe Balbi
2013-05-03  6:25             ` Felipe Balbi
2013-05-03  8:15           ` Russell King - ARM Linux
2013-05-03  8:30             ` Felipe Balbi
2013-05-03  8:33               ` Russell King - ARM Linux
2013-05-03  8:32           ` Russell King - ARM Linux
2013-05-03  8:39             ` Felipe Balbi
2013-05-03  8:43               ` Russell King - ARM Linux
2013-05-02 19:52   ` Russell King - ARM Linux

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=20130502164058.GC8577@arwen.pp.htv.fi \
    --to=balbi@ti.com \
    --cc=linux-arm-kernel@lists.infradead.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