From: Axel Lin <axel.lin@gmail.com>
To: linux-kernel <linux-kernel@vger.kernel.org>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>,
Liam Girdwood <lrg@slimlogic.co.uk>
Subject: [PATCH 3/4] regulator/wm831x-ldo: fix potential NULL dereference
Date: Fri, 20 Aug 2010 10:01:24 +0800 [thread overview]
Message-ID: <1282269684.31048.6.camel@mola> (raw)
In-Reply-To: <1282269518.31048.2.camel@mola>
pdata is dereferenced earlier than tested for being NULL.
Thus move the dereference of "pdata" below the check for NULL.
Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
drivers/regulator/wm831x-ldo.c | 27 ++++++++++++++++++---------
1 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c
index e686cdb..040515d 100644
--- a/drivers/regulator/wm831x-ldo.c
+++ b/drivers/regulator/wm831x-ldo.c
@@ -303,14 +303,17 @@ static __devinit int wm831x_gp_ldo_probe(struct platform_device *pdev)
{
struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
struct wm831x_pdata *pdata = wm831x->dev->platform_data;
- int id = pdev->id % ARRAY_SIZE(pdata->ldo);
struct wm831x_ldo *ldo;
struct resource *res;
- int ret, irq;
+ int id, ret, irq;
+ if (pdata == NULL)
+ return -ENODEV;
+
+ id = pdev->id % ARRAY_SIZE(pdata->ldo);
dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
- if (pdata == NULL || pdata->ldo[id] == NULL)
+ if (pdata->ldo[id] == NULL)
return -ENODEV;
ldo = kzalloc(sizeof(struct wm831x_ldo), GFP_KERNEL);
@@ -563,14 +566,17 @@ static __devinit int wm831x_aldo_probe(struct platform_device *pdev)
{
struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
struct wm831x_pdata *pdata = wm831x->dev->platform_data;
- int id = pdev->id % ARRAY_SIZE(pdata->ldo);
struct wm831x_ldo *ldo;
struct resource *res;
- int ret, irq;
+ int id, ret, irq;
+
+ if (pdata == NULL)
+ return -ENODEV;
+ id = pdev->id % ARRAY_SIZE(pdata->ldo);
dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
- if (pdata == NULL || pdata->ldo[id] == NULL)
+ if (pdata->ldo[id] == NULL)
return -ENODEV;
ldo = kzalloc(sizeof(struct wm831x_ldo), GFP_KERNEL);
@@ -749,14 +755,17 @@ static __devinit int wm831x_alive_ldo_probe(struct platform_device *pdev)
{
struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
struct wm831x_pdata *pdata = wm831x->dev->platform_data;
- int id = pdev->id % ARRAY_SIZE(pdata->ldo);
struct wm831x_ldo *ldo;
struct resource *res;
- int ret;
+ int id, ret;
+
+ if (pdata == NULL)
+ return -ENODEV;
+ id = pdev->id % ARRAY_SIZE(pdata->ldo);
dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
- if (pdata == NULL || pdata->ldo[id] == NULL)
+ if (pdata->ldo[id] == NULL)
return -ENODEV;
ldo = kzalloc(sizeof(struct wm831x_ldo), GFP_KERNEL);
--
1.7.2
next prev parent reply other threads:[~2010-08-20 1:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-20 1:58 [PATCH 1/4] regulator/wm831x-dcdc: fix potential NULL dereference Axel Lin
2010-08-20 1:59 ` [PATCH 2/4] regulator/wm831x-isink: " Axel Lin
2010-08-20 2:01 ` Axel Lin [this message]
2010-08-20 2:02 ` [PATCH 4/4] regulator/wm8994-regulator: " Axel Lin
2010-08-20 9:03 ` [PATCH 1/4] regulator/wm831x-dcdc: " Mark Brown
2010-08-20 15:43 ` Axel Lin
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=1282269684.31048.6.camel@mola \
--to=axel.lin@gmail.com \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lrg@slimlogic.co.uk \
/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