Skip to content

Commit

Permalink
base: dd: fix error return code of driver_sysfs_add()
Browse files Browse the repository at this point in the history
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.

Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Link: https://lore.kernel.org/r/20210324023405.12465-1-baijiaju1990@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jia-Ju Bai authored and Greg Kroah-Hartman committed Mar 28, 2021
1 parent e611f8c commit d225ef6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/base/dd.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,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");
Expand Down

0 comments on commit d225ef6

Please sign in to comment.