Skip to contentSkip to conversation

powerpc/powernv: add NULL check after kzalloc in opal_add_one_export

PATCH Superseded Qiujun Huang 2 participants 3 messages Apr 5, 2020 PowerPC

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/powernv: add NULL check after kzalloc in opal_add_one_export

Here needs a NULL check.

Issue found by coccinelle.

---
 arch/powerpc/platforms/powernv/opal.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/powerpc/platforms/powernv/opal.c +5 -0
index 2b3dfd0b6cdd..09443ae3a86e 100644
@@ -811,6 +811,11 @@ static int opal_add_one_export(struct kobject *parent, const char *export_name,
 		goto out;
 
 	attr = kzalloc(sizeof(*attr), GFP_KERNEL);
+	if (!attr) {
+		rc = -ENOMEM;
+		goto out;
+	}
+
 	name = kstrdup(export_name, GFP_KERNEL);
 	if (!name) {
 		rc = -ENOMEM;
Signature · 1 line
2.17.1
#1 lore raw

Le 05/04/2020 à 09:51, Qiujun Huang a écrit :

Quoted 14 lines

Here needs a NULL check.

Issue found by coccinelle.

---
  arch/powerpc/platforms/powernv/opal.c | 5 +++++
  1 file changed, 5 insertions(+)
arch/powerpc/platforms/powernv/opal.c +0 -0
index 2b3dfd0b6cdd..09443ae3a86e 100644

arch/powerpc/platforms/powernv/opal.c static int opal_add_one_export(struct kobject *parent, const char *export_name, · line 816

Quoted 6 lines
arch/powerpc/platforms/powernv/opal.c +3 -0
@@ -811,6 +811,11 @@ static int opal_add_one_export(struct kobject *parent, const char *export_name,
  		goto out;
 
  	attr = kzalloc(sizeof(*attr), GFP_KERNEL);
+	if (!attr) {
+		rc = -ENOMEM;
+		goto out;

You don't need to go to out:, there is nothing to do. You should do:

	if (!attr)
		return -ENOMEM;

arch/powerpc/platforms/powernv/opal.c static int opal_add_one_export(struct kobject *parent, const char *export_name, · line 821

Quoted 6 lines
arch/powerpc/platforms/powernv/opal.c +2 -0
+	}
+
  	name = kstrdup(export_name, GFP_KERNEL);
  	if (!name) {
  		rc = -ENOMEM;

Christophe

#2 lore raw
Quoted 27 lines · Christophe Leroy
Quoted 14 lines · Qiujun Huang

Here needs a NULL check.

Issue found by coccinelle.

---
  arch/powerpc/platforms/powernv/opal.c | 5 +++++
  1 file changed, 5 insertions(+)
arch/powerpc/platforms/powernv/opal.c +0 -0
index 2b3dfd0b6cdd..09443ae3a86e 100644

arch/powerpc/platforms/powernv/opal.c static int opal_add_one_export(struct kobject *parent, const char *export_name, · line 816

Quoted 6 lines
arch/powerpc/platforms/powernv/opal.c +3 -0
@@ -811,6 +811,11 @@ static int opal_add_one_export(struct kobject *parent, const char *export_name,
              goto out;
 
      attr = kzalloc(sizeof(*attr), GFP_KERNEL);
+     if (!attr) {
+             rc = -ENOMEM;
+             goto out;

You don't need to go to out:, there is nothing to do. You should do:

Quoted 2 lines
        if (!attr)
                return -ENOMEM;

Yeah, I get that. Thanks.

Quoted 9 lines

arch/powerpc/platforms/powernv/opal.c static int opal_add_one_export(struct kobject *parent, const char *export_name, · line 821

Quoted 7 lines
arch/powerpc/platforms/powernv/opal.c +2 -0
+     }
+
      name = kstrdup(export_name, GFP_KERNEL);
      if (!name) {
              rc = -ENOMEM;

Christophe