From: Dan Carpenter <dan.carpenter@oracle.com>
To: Arvind Yadav <arvind.yadav.cs@gmail.com>
Cc: rmfrfs@gmail.com, johan@kernel.org, elder@kernel.org,
gregkh@linuxfoundation.org, devel@driverdev.osuosl.org,
greybus-dev@lists.linaro.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] media: staging: greybus: Release memory obtained by kasprintf
Date: Thu, 21 Sep 2017 15:59:18 +0300 [thread overview]
Message-ID: <20170921125918.keiog5yd2jw342zc@mwanda> (raw)
In-Reply-To: <21ea1d2e0ef0c3d4d59b2e5d2e189533c8b1668a.1505991013.git.arvind.yadav.cs@gmail.com>
On Thu, Sep 21, 2017 at 05:05:27PM +0530, Arvind Yadav wrote:
> Free memory region, if gb_lights_channel_config is not successful.
>
The question I have is do we free this on module unload? I don't see
that we do. I feel like we should do a free after calling
__gb_lights_led_unregister(). But that's awkward because we call
__gb_lights_led_unregister() when this function fails so it would end
up being a double free.
> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
> ---
> drivers/staging/greybus/light.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c
> index 3f4148c..b00d47c 100644
> --- a/drivers/staging/greybus/light.c
> +++ b/drivers/staging/greybus/light.c
> @@ -984,7 +984,7 @@ static int gb_lights_channel_config(struct gb_light *light,
>
> ret = channel_attr_groups_set(channel, cdev);
> if (ret < 0)
> - return ret;
> + goto err;
>
> gb_lights_led_operations_set(channel, cdev);
>
> @@ -994,15 +994,18 @@ static int gb_lights_channel_config(struct gb_light *light,
> * configurations.
> */
> if (!is_channel_flash(channel))
> - return ret;
> + goto err;
"ret" is zero here. This is actually a success return. It would be
cleaner to just write "return 0;". Anyway, this patch introduces a use
after free so that doesn't work.
Also it's better to choose a label name which says what the label does
so in this case it would be "goto err_free_name" or "goto err_cdev_name"
or whatever, but something to indicate that it's to do with freeing
the cdev->name. Just "err" is too ambiguous.
>
> light->has_flash = true;
>
> ret = gb_lights_channel_flash_config(channel);
> if (ret < 0)
> - return ret;
> + goto err;
>
> return ret;
^^^^^^^^^^
Here as well, change this from "return ret;" to "return 0;".
regards,
dan carpenter
next prev parent reply other threads:[~2017-09-21 12:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-21 11:35 Arvind Yadav
2017-09-21 12:59 ` Dan Carpenter [this message]
2017-09-21 13:54 ` 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=20170921125918.keiog5yd2jw342zc@mwanda \
--to=dan.carpenter@oracle.com \
--cc=arvind.yadav.cs@gmail.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
all inboxes | Powered by JetHome®