public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Rui Miguel Silva <rmfrfs@gmail.com>
Cc: devel@driverdev.osuosl.org, elder@kernel.org,
	Chen Zhou <chenzhou10@huawei.com>,
	gregkh@linuxfoundation.org, johan@kernel.org,
	linux-kernel@vger.kernel.org, greybus-dev@lists.linaro.org
Subject: Re: [PATCH -next] staging: greybus: fix a missing-check bug in gb_lights_light_config()
Date: Thu, 2 Apr 2020 17:22:37 +0300	[thread overview]
Message-ID: <20200402142237.GT2001@kadam> (raw)
In-Reply-To: <20200402131618.653dkeuz7c2vuujf@arch-thunder.localdomain>

On Thu, Apr 02, 2020 at 02:16:18PM +0100, Rui Miguel Silva wrote:
> > > --- a/drivers/staging/greybus/light.c
> > > +++ b/drivers/staging/greybus/light.c
> > > @@ -1026,7 +1026,8 @@ static int gb_lights_light_config(struct gb_lights *glights, u8 id)
> > >  
> > >  	light->channels_count = conf.channel_count;
> > >  	light->name = kstrndup(conf.name, NAMES_MAX, GFP_KERNEL);
> > > -
> > > +	if (!light->name)
> > > +		return -ENOMEM;
> > >  	light->channels = kcalloc(light->channels_count,
> > >  				  sizeof(struct gb_channel), GFP_KERNEL);
> > >  	if (!light->channels)
> > 
> > The clean up in this function is non-existant.  :(
> 
> Yeah, this have a central point to do the cleanups, gb_lights_release,
> since we may have other lights already configured at this point, we
> could cleanup this specific one here, but than would need to make sure
> all other already configure got clean also.

Central clean up functions never work correctly.

For example, we allocate "cdev->name" in gb_lights_channel_config()
before we register the channel later in gb_lights_register_all(glights);.
Now imagine that the register fails.  Then when we're freeing it in
__gb_lights_led_unregister() we see that the ->is_registered is false
so we don't kfree(cdev->name).

That's just a small memory leak.  But there are going to be tons of
little bugs like that.

Anyway it doesn't affect this patch so it's fine.

regards,
dan carpenter


  reply	other threads:[~2020-04-02 14:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-01  3:00 [PATCH -next] staging: greybus: fix a missing-check bug in gb_lights_light_config() Chen Zhou
2020-04-01 10:16 ` Rui Miguel Silva
2020-04-02 12:22 ` Dan Carpenter
2020-04-02 13:16   ` Rui Miguel Silva
2020-04-02 14:22     ` Dan Carpenter [this message]
2020-04-02 16:04       ` Rui Miguel Silva

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=20200402142237.GT2001@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=chenzhou10@huawei.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=elder@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=greybus-dev@lists.linaro.org \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rmfrfs@gmail.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