From: Krzysztof Kozlowski <k.kozlowski@samsung.com>
To: Belisko Marek <marek.belisko@gmail.com>
Cc: Dmitry Artamonow <mad_soft@inbox.ru>,
Cezary Jackiewicz <cezary.jackiewicz@gmail.com>,
Darren Hart <dvhart@infradead.org>,
Sebastian Reichel <sre@kernel.org>,
Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>,
David Woodhouse <dwmw2@infradead.org>,
platform-driver-x86@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
Linux PM mailing list <linux-pm@vger.kernel.org>,
stable@vger.kernel.org
Subject: Re: [RFT PATCH 1/4] power_supply: twl4030_madc: Check return value of power_supply_register
Date: Wed, 28 Jan 2015 08:58:41 +0100 [thread overview]
Message-ID: <1422431921.8854.4.camel@AMDC1943> (raw)
In-Reply-To: <CAAfyv34YoUG8dyq10mFZRQ-uf6-oT_KAbwZ1UQQ0FvFrs10BrQ@mail.gmail.com>
On wto, 2015-01-27 at 22:06 +0100, Belisko Marek wrote:
> Hi Krzystof,
>
> On Tue, Jan 27, 2015 at 12:30 PM, Krzysztof Kozlowski
> <k.kozlowski@samsung.com> wrote:
> > The return value of power_supply_register() call was not checked and
> > even on error probe() function returned 0. If registering failed then
> > during unbind the driver tried to unregister power supply which was not
> > actually registered.
> >
> > This could lead to memory corruption because power_supply_unregister()
> > unconditionally cleans up given power supply.
> >
> > Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> > Fixes: da0a00ebc239 ("power: Add twl4030_madc battery driver.")
> > Cc: <stable@vger.kernel.org>
> > ---
> > drivers/power/twl4030_madc_battery.c | 7 +++++--
> > 1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/power/twl4030_madc_battery.c b/drivers/power/twl4030_madc_battery.c
> > index 7ef445a6cfa6..cf907609ec49 100644
> > --- a/drivers/power/twl4030_madc_battery.c
> > +++ b/drivers/power/twl4030_madc_battery.c
> > @@ -192,6 +192,7 @@ static int twl4030_madc_battery_probe(struct platform_device *pdev)
> > {
> > struct twl4030_madc_battery *twl4030_madc_bat;
> > struct twl4030_madc_bat_platform_data *pdata = pdev->dev.platform_data;
> > + int ret = 0;
> >
> > twl4030_madc_bat = kzalloc(sizeof(*twl4030_madc_bat), GFP_KERNEL);
> > if (!twl4030_madc_bat)
> > @@ -216,9 +217,11 @@ static int twl4030_madc_battery_probe(struct platform_device *pdev)
> >
> > twl4030_madc_bat->pdata = pdata;
> > platform_set_drvdata(pdev, twl4030_madc_bat);
> > - power_supply_register(&pdev->dev, &twl4030_madc_bat->psy);
> > + ret = power_supply_register(&pdev->dev, &twl4030_madc_bat->psy);
> > + if (ret < 0)
> > + kfree(twl4030_madc_bat);
> I post update twl4030_madc to iio some time ago [1] where this change
> was incorporated.
> I plan to respin in next week so we can drop this one (or take and
> I'll rebase on top).
Hi,
I am fine with both solutions (especially that I am not able to test my
change). However there is one benefit of my fix: after applying it could
be backported to stable kernels (3.11+?).
Best regards,
Krzysztof
> >
> > - return 0;
> > + return ret;
> > }
> >
> > static int twl4030_madc_battery_remove(struct platform_device *pdev)
> > --
> > 1.9.1
> >
>
> [1] - https://lkml.org/lkml/2014/3/5/284
>
> BR,
>
> marek
>
next prev parent reply other threads:[~2015-01-29 2:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-27 11:30 [RFT PATCH 0/4] Check return value of power_supply_register Krzysztof Kozlowski
2015-01-27 11:30 ` [RFT PATCH 1/4] power_supply: twl4030_madc: " Krzysztof Kozlowski
2015-01-27 21:06 ` Belisko Marek
2015-01-28 7:58 ` Krzysztof Kozlowski [this message]
2015-01-27 11:30 ` [RFT PATCH 2/4] compal-laptop: " Krzysztof Kozlowski
2015-02-07 2:42 ` Darren Hart
2015-02-09 7:56 ` Krzysztof Kozlowski
2015-01-27 11:30 ` [RFT PATCH 3/4] power_supply: ipaq_micro_battery: Fix leaking workqueue Krzysztof Kozlowski
2015-01-27 11:30 ` [RFT PATCH 4/4] power_supply: ipaq_micro_battery: Check return values in probe Krzysztof Kozlowski
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=1422431921.8854.4.camel@AMDC1943 \
--to=k.kozlowski@samsung.com \
--cc=cezary.jackiewicz@gmail.com \
--cc=dbaryshkov@gmail.com \
--cc=dvhart@infradead.org \
--cc=dwmw2@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mad_soft@inbox.ru \
--cc=marek.belisko@gmail.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=sre@kernel.org \
--cc=stable@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;
as well as URLs for NNTP newsgroup(s).