From: segoon@openwall.com (Vasiliy Kulikov)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] arm: mach-omap2: potential NULL dereference
Date: Mon, 17 Jan 2011 13:08:32 +0300 [thread overview]
Message-ID: <1295258913-31048-1-git-send-email-segoon@openwall.com> (raw)
If kzalloc() failed, return -ENOMEM.
sr_dev_init() should signal by return value that there is an error.
Signed-off-by: Vasiliy Kulikov <segoon@openwall.com>
---
Cannot compile this driver, so it is not tested at all.
arch/arm/mach-omap2/sr_device.c | 19 +++++++++++++++----
1 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/arch/arm/mach-omap2/sr_device.c b/arch/arm/mach-omap2/sr_device.c
index b1e0af1..20fccfb 100644
--- a/arch/arm/mach-omap2/sr_device.c
+++ b/arch/arm/mach-omap2/sr_device.c
@@ -40,7 +40,7 @@ static struct omap_device_pm_latency omap_sr_latency[] = {
};
/* Read EFUSE values from control registers for OMAP3430 */
-static void __init sr_set_nvalues(struct omap_volt_data *volt_data,
+static int __init sr_set_nvalues(struct omap_volt_data *volt_data,
struct omap_sr_data *sr_data)
{
struct omap_sr_nvalue_table *nvalue_table;
@@ -51,6 +51,8 @@ static void __init sr_set_nvalues(struct omap_volt_data *volt_data,
nvalue_table = kzalloc(sizeof(struct omap_sr_nvalue_table)*count,
GFP_KERNEL);
+ if (nvalue_table == NULL)
+ return -ENOMEM;
for (i = 0; i < count; i++) {
u32 v;
@@ -75,6 +77,8 @@ static void __init sr_set_nvalues(struct omap_volt_data *volt_data,
sr_data->nvalue_table = nvalue_table;
sr_data->nvalue_count = count;
+
+ return 0;
}
static int sr_dev_init(struct omap_hwmod *oh, void *user)
@@ -84,15 +88,18 @@ static int sr_dev_init(struct omap_hwmod *oh, void *user)
struct omap_volt_data *volt_data;
char *name = "smartreflex";
static int i;
+ int err = 0;
sr_data = kzalloc(sizeof(struct omap_sr_data), GFP_KERNEL);
if (!sr_data) {
+ err = -ENOMEM;
pr_err("%s: Unable to allocate memory for %s sr_data.Error!\n",
__func__, oh->name);
- return -ENOMEM;
+ goto exit;
}
if (!oh->vdd_name) {
+ err = -EINVAL;
pr_err("%s: No voltage domain specified for %s."
"Cannot initialize\n", __func__, oh->name);
goto exit;
@@ -104,6 +111,7 @@ static int sr_dev_init(struct omap_hwmod *oh, void *user)
sr_data->voltdm = omap_voltage_domain_lookup(oh->vdd_name);
if (IS_ERR(sr_data->voltdm)) {
+ err = PTR_ERR(sr_data->voltdm);
pr_err("%s: Unable to get voltage domain pointer for VDD %s\n",
__func__, oh->vdd_name);
goto exit;
@@ -111,12 +119,15 @@ static int sr_dev_init(struct omap_hwmod *oh, void *user)
omap_voltage_get_volttable(sr_data->voltdm, &volt_data);
if (!volt_data) {
+ err = -EINVAL;
pr_warning("%s: No Voltage table registerd fo VDD%d."
"Something really wrong\n\n", __func__, i + 1);
goto exit;
}
- sr_set_nvalues(volt_data, sr_data);
+ err = sr_set_nvalues(volt_data, sr_data);
+ if (err)
+ goto exit;
sr_data->enable_on_init = sr_enable_on_init;
@@ -129,7 +140,7 @@ static int sr_dev_init(struct omap_hwmod *oh, void *user)
exit:
i++;
kfree(sr_data);
- return 0;
+ return err;
}
/*
--
1.7.0.4
next reply other threads:[~2011-01-17 10:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-17 10:08 Vasiliy Kulikov [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-01-17 10:08 [PATCH] arm: mach-omap2: potential NULL dereference Vasiliy Kulikov
2011-01-17 10:38 ` walter harms
2011-01-17 12:30 ` Sergei Shtylyov
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=1295258913-31048-1-git-send-email-segoon@openwall.com \
--to=segoon@openwall.com \
--cc=linux-arm-kernel@lists.infradead.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).