Skip to contentSkip to conversation

drivers/base/cpu: remove redundant assignment of variable retval

PATCH In review Colin King 2 participants 2 messages Feb 18, 2021 – Feb 19, 2021

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH v2 1/1 drivers/base/cpu: remove redundant assignment of variable retval

From: Colin Ian King <[email protected]>

The variable retval is being initialized with a value that is never read and it is being updated later with a new value. Clean this up by initializing retval to -ENOMEM and remove the assignment to retval on the !dev failure path.

Kudos to Rafael for the improved fix suggestion.

---
V1: Remove initialization of retval
V2: Initialiation of retval with -ENOMEM and remove assignment in
!dev failure path.

---
 drivers/base/cpu.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/base/cpu.c +2 -4
index 8f1d6569564c..2b9e41377a07 100644
@@ -409,13 +409,11 @@ __cpu_device_create(struct device *parent, void *drvdata,
 		    const char *fmt, va_list args)
 {
 	struct device *dev = NULL;
-	int retval = -ENODEV;
+	int retval = -ENOMEM;
 
 	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
-	if (!dev) {
-		retval = -ENOMEM;
+	if (!dev)
 		goto error;
-	}
 
 	device_initialize(dev);
 	dev->parent = parent;
Signature · 1 line
2.30.0
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · Colin King

From: Colin Ian King <[email protected]>

The variable retval is being initialized with a value that is never read and it is being updated later with a new value. Clean this up by initializing retval to -ENOMEM and remove the assignment to retval on the !dev failure path.

Kudos to Rafael for the improved fix suggestion.

Quoted 31 lines

---
V1: Remove initialization of retval
V2: Initialiation of retval with -ENOMEM and remove assignment in
!dev failure path.

---
 drivers/base/cpu.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/base/cpu.c +2 -5
index 8f1d6569564c..2b9e41377a07 100644
@@ -409,13 +409,11 @@ __cpu_device_create(struct device *parent, void *drvdata,
                    const char *fmt, va_list args)
 {
        struct device *dev = NULL;
-       int retval = -ENODEV;
+       int retval = -ENOMEM;
 
        dev = kzalloc(sizeof(*dev), GFP_KERNEL);
-       if (!dev) {
-               retval = -ENOMEM;
+       if (!dev)
                goto error;
-       }
 
        device_initialize(dev);
        dev->parent = parent;
--

2.30.0