Skip to contentSkip to conversation

base: dd: fix error return code of driver_sysfs_add()

PATCH Superseded Jia-Ju Bai 3 participants 4 messages Mar 5, 2021 – Mar 24, 2021 Driver core

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 base: dd: fix error return code of driver_sysfs_add()

When device_create_file() fails and returns a non-zero value, no error return code of driver_sysfs_add() is assigned. To fix this bug, ret is assigned with the return value of device_create_file(), and then ret is checked.

---
 drivers/base/dd.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/base/dd.c +5 -2
index 9179825ff646..f94bbef95258 100644
@@ -413,8 +413,11 @@ static int driver_sysfs_add(struct device *dev)
 	if (ret)
 		goto rm_dev;
 
-	if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump ||
-	    !device_create_file(dev, &dev_attr_coredump))
+	if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump)
+		return 0;
+	
+	ret = device_create_file(dev, &dev_attr_coredump);
+	if (!ret)
 		return 0;
 
 	sysfs_remove_link(&dev->kobj, "driver");
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jia-Ju Bai

When device_create_file() fails and returns a non-zero value, no error return code of driver_sysfs_add() is assigned. To fix this bug, ret is assigned with the return value of device_create_file(), and then ret is checked.

Quoted 25 lines
---
 drivers/base/dd.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/base/dd.c +5 -3
index 9179825ff646..f94bbef95258 100644
@@ -413,8 +413,11 @@ static int driver_sysfs_add(struct device *dev)
        if (ret)
                goto rm_dev;
 
-       if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump ||
-           !device_create_file(dev, &dev_attr_coredump))
+       if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump)
+               return 0;
+
+       ret = device_create_file(dev, &dev_attr_coredump);
+       if (!ret)
                return 0;
 
        sysfs_remove_link(&dev->kobj, "driver");
--

2.17.1

maintainer
#2 lore raw
In reply to Jia-Ju Bai
Quoted 16 lines · Jia-Ju Bai

When device_create_file() fails and returns a non-zero value, no error return code of driver_sysfs_add() is assigned. To fix this bug, ret is assigned with the return value of device_create_file(), and then ret is checked.

---
 drivers/base/dd.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/base/dd.c +0 -0
index 9179825ff646..f94bbef95258 100644

drivers/base/dd.c static int driver_sysfs_add(struct device *dev) · line 418

Quoted 8 lines
drivers/base/dd.c +3 -2
@@ -413,8 +413,11 @@ static int driver_sysfs_add(struct device *dev)
 	if (ret)
 		goto rm_dev;
 
-	if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump ||
-	    !device_create_file(dev, &dev_attr_coredump))
+	if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump)
+		return 0;
+	

Trailing whitespace :(

author
#3 lore raw
Quoted 20 lines · Greg KH
Quoted 19 lines · Jia-Ju Bai

When device_create_file() fails and returns a non-zero value, no error return code of driver_sysfs_add() is assigned. To fix this bug, ret is assigned with the return value of device_create_file(), and then ret is checked.

---
  drivers/base/dd.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
drivers/base/dd.c +0 -0
index 9179825ff646..f94bbef95258 100644
@@ -413,8 +413,11 @@ static int driver_sysfs_add(struct device *dev)
  	if (ret)
  		goto rm_dev;
 
Quoted 6 lines

drivers/base/dd.c static int driver_sysfs_add(struct device *dev) · line 418

Quoted 5 lines
drivers/base/dd.c +3 -2
-	if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump ||
-	    !device_create_file(dev, &dev_attr_coredump))
+	if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump)
+		return 0;
+	

Trailing whitespace :

Ah, sorry, I will send a V2 patch.

Best wishes,
Jia-Ju Bai