From: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
To: Laxman Dewangan <ldewangan@nvidia.com>
Cc: broonie@opensource.wolfsonmicro.com, lrg@ti.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] regulator: core: avoid memory access after freeing it
Date: Tue, 6 Nov 2012 11:12:56 +0000 [thread overview]
Message-ID: <20121106111256.GA2512@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1352198049-5941-1-git-send-email-ldewangan@nvidia.com>
On Tue, Nov 06, 2012 at 04:04:09PM +0530, Laxman Dewangan wrote:
> When regulator_register() failed due to non availability of
> mutex_unlock(®ulator_list_mutex);
...
> }
> EXPORT_SYMBOL_GPL(regulator_put);
> @@ -3453,11 +3460,10 @@ scrub:
> gpio_free(rdev->ena_gpio);
> kfree(rdev->constraints);
> wash:
> + if (rdev->supply)
> + __regulator_put_locked(rdev->supply);
> device_unregister(&rdev->dev);
> -
> mutex_unlock(®ulator_list_mutex);
> - if (rdev->supply)
> - regulator_put(rdev->supply);
>
> /* device core frees rdev */
> rdev = ERR_PTR(ret);
Here would it not make sense to go slightly further and basically
revert my original change. This feels sensible as it keeps it at
only one location where the mutex is unlocked and removes the
second exit point I added. This would effectively make the code
look like:
scrub:
if (rdev->supply)
__regulator_put_locked(rdev->supply);
if (rdev->ena_gpio)
gpio_free(rdev->ena_gpio);
kfree(rdev->constraints);
device_unregister(&rdev->dev);
/* device core frees rdev */
rdev = ERR_PTR(ret);
goto out;
Otherwise the change looks great to me.
> --
> 1.7.1.1
>
next prev parent reply other threads:[~2012-11-06 11:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-06 10:34 [PATCH] regulator: core: avoid memory access after freeing it Laxman Dewangan
2012-11-06 11:12 ` Charles Keepax [this message]
2012-11-06 11:31 ` Mark Brown
2012-11-13 16:30 ` [PATCH] regulator: core: Add locked version of regulator_put to avoid deadlock Charles Keepax
2012-11-13 17:16 ` Laxman Dewangan
2012-11-13 23:25 ` Mark Brown
2012-11-14 9:39 ` [PATCH v2] regulator: core: Avoid deadlock when regulator_register fails Charles Keepax
2012-11-14 10:01 ` Mark Brown
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=20121106111256.GA2512@opensource.wolfsonmicro.com \
--to=ckeepax@opensource.wolfsonmicro.com \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=ldewangan@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lrg@ti.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;
as well as URLs for NNTP newsgroup(s).