[PATCH] arm: mach-omap2: potential NULL dereference

Subsystems: arm port, omap2+ support, the rest

STALE5711d

4 messages, 3 authors, 2011-01-19 · open the first message on its own page

[PATCH] arm: mach-omap2: potential NULL dereference

From: Vasiliy Kulikov <hidden>
Date: 2011-01-17 10:09:44

kzalloc() may fail, if so return -ENOMEM.

Signed-off-by: Vasiliy Kulikov <redacted>
---
 Cannot compile this driver, so it is not tested at all.

 arch/arm/mach-omap2/smartreflex.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/arch/arm/mach-omap2/smartreflex.c b/arch/arm/mach-omap2/smartreflex.c
index 77ecebf..871bca9 100644
--- a/arch/arm/mach-omap2/smartreflex.c
+++ b/arch/arm/mach-omap2/smartreflex.c
@@ -260,7 +260,10 @@ static int sr_late_init(struct omap_sr *sr_info)
 	if (sr_class->class_type == SR_CLASS2 &&
 		sr_class->notify_flags && sr_info->irq) {
 
+		ret = -ENOMEM;
 		name = kzalloc(SMARTREFLEX_NAME_LEN + 1, GFP_KERNEL);
+		if (name == NULL)
+			goto error;
 		strcpy(name, "sr_");
 		strcat(name, sr_info->voltdm->name);
 		ret = request_irq(sr_info->irq, sr_interrupt,
-- 
1.7.0.4

Re: [PATCH] arm: mach-omap2: potential NULL dereference

From: walter harms <hidden>
Date: 2011-01-17 10:38:54


Am 17.01.2011 11:08, schrieb Vasiliy Kulikov:
quoted hunk
kzalloc() may fail, if so return -ENOMEM.

Signed-off-by: Vasiliy Kulikov <redacted>
---
 Cannot compile this driver, so it is not tested at all.

 arch/arm/mach-omap2/smartreflex.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/arch/arm/mach-omap2/smartreflex.c b/arch/arm/mach-omap2/smartreflex.c
index 77ecebf..871bca9 100644
--- a/arch/arm/mach-omap2/smartreflex.c
+++ b/arch/arm/mach-omap2/smartreflex.c
@@ -260,7 +260,10 @@ static int sr_late_init(struct omap_sr *sr_info)
 	if (sr_class->class_type == SR_CLASS2 &&
 		sr_class->notify_flags && sr_info->irq) {
 
+		ret = -ENOMEM;
 		name = kzalloc(SMARTREFLEX_NAME_LEN + 1, GFP_KERNEL);
+		if (name == NULL)
+			goto error;
 		strcpy(name, "sr_");
 		strcat(name, sr_info->voltdm->name);
 		ret = request_irq(sr_info->irq, sr_interrupt,
maybe it is more readable to use:
	kasprint(&name,"sr_%s",sr_info->voltdm->name);

re,
 wh

Re: [PATCH] arm: mach-omap2: potential NULL dereference

From: Sergei Shtylyov <hidden>
Date: 2011-01-17 12:32:10

Hello.

On 17-01-2011 13:08, Vasiliy Kulikov wrote:
kzalloc() may fail, if so return -ENOMEM.
Signed-off-by: Vasiliy Kulikov<redacted>
[...]
quoted hunk
diff --git a/arch/arm/mach-omap2/smartreflex.c b/arch/arm/mach-omap2/smartreflex.c
index 77ecebf..871bca9 100644
--- a/arch/arm/mach-omap2/smartreflex.c
+++ b/arch/arm/mach-omap2/smartreflex.c
@@ -260,7 +260,10 @@ static int sr_late_init(struct omap_sr *sr_info)
  	if (sr_class->class_type == SR_CLASS2&&
  		sr_class->notify_flags&&  sr_info->irq) {

+		ret = -ENOMEM;
  		name = kzalloc(SMARTREFLEX_NAME_LEN + 1, GFP_KERNEL);
+		if (name == NULL)
+			goto error;
    Why not:

		if (name == NULL) {
			ret = -ENOMEM;
			goto error;
		}

WBR, Sergei

[PATCH v2] arm: mach-omap2: potential NULL dereference

From: Vasiliy Kulikov <hidden>
Date: 2011-01-19 12:57:31

kzalloc() may fail, if so return -ENOMEM.  Also Walter Harms suggested
to use kasprintf() instead of kzalloc+strcpy+strcat.

Signed-off-by: Vasiliy Kulikov <redacted>
---
 Cannot compile this driver, so it is not tested at all.

 arch/arm/mach-omap2/smartreflex.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/arch/arm/mach-omap2/smartreflex.c b/arch/arm/mach-omap2/smartreflex.c
index 77ecebf..697d8d4 100644
--- a/arch/arm/mach-omap2/smartreflex.c
+++ b/arch/arm/mach-omap2/smartreflex.c
@@ -260,9 +260,11 @@ static int sr_late_init(struct omap_sr *sr_info)
 	if (sr_class->class_type == SR_CLASS2 &&
 		sr_class->notify_flags && sr_info->irq) {
 
-		name = kzalloc(SMARTREFLEX_NAME_LEN + 1, GFP_KERNEL);
-		strcpy(name, "sr_");
-		strcat(name, sr_info->voltdm->name);
+		name = kasprintf(GFP_KERNEL, "sr_%s", sr_info->voltdm->name);
+		if (name == NULL) {
+			ret = -ENOMEM;
+			goto error;
+		}
 		ret = request_irq(sr_info->irq, sr_interrupt,
 				0, name, (void *)sr_info);
 		if (ret)
-- 
Vasiliy Kulikov
http://www.openwall.com - bringing security into open computing environments
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help