Skip to content

Commit

Permalink
platform/x86: huawei-wmi: check the return value of device_create_file()
Browse files Browse the repository at this point in the history
The function device_create_file() in huawei_wmi_battery_add() can fail,
so its return value should be checked.

Fixes: 355a070 ("platform/x86: huawei-wmi: Add battery charging thresholds")
Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Link: https://lore.kernel.org/r/20220303022421.313-1-baijiaju1990@gmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  • Loading branch information
Jia-Ju Bai authored and Hans de Goede committed Mar 8, 2022
1 parent e1c2160 commit c91a5b1
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions drivers/platform/x86/huawei-wmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,17 @@ static DEVICE_ATTR_RW(charge_control_thresholds);

static int huawei_wmi_battery_add(struct power_supply *battery)
{
device_create_file(&battery->dev, &dev_attr_charge_control_start_threshold);
device_create_file(&battery->dev, &dev_attr_charge_control_end_threshold);
int err = 0;

return 0;
err = device_create_file(&battery->dev, &dev_attr_charge_control_start_threshold);
if (err)
return err;

err = device_create_file(&battery->dev, &dev_attr_charge_control_end_threshold);
if (err)
device_remove_file(&battery->dev, &dev_attr_charge_control_start_threshold);

return err;
}

static int huawei_wmi_battery_remove(struct power_supply *battery)
Expand Down

0 comments on commit c91a5b1

Please sign in to comment.