Skip to content

Commit c91a5b1

Browse files
XidianGeneraljwrdegoede
authored andcommitted
platform/x86: huawei-wmi: check the return value of device_create_file()
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>
1 parent e1c2160 commit c91a5b1

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

drivers/platform/x86/huawei-wmi.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,17 @@ static DEVICE_ATTR_RW(charge_control_thresholds);
470470

471471
static int huawei_wmi_battery_add(struct power_supply *battery)
472472
{
473-
device_create_file(&battery->dev, &dev_attr_charge_control_start_threshold);
474-
device_create_file(&battery->dev, &dev_attr_charge_control_end_threshold);
473+
int err = 0;
475474

476-
return 0;
475+
err = device_create_file(&battery->dev, &dev_attr_charge_control_start_threshold);
476+
if (err)
477+
return err;
478+
479+
err = device_create_file(&battery->dev, &dev_attr_charge_control_end_threshold);
480+
if (err)
481+
device_remove_file(&battery->dev, &dev_attr_charge_control_start_threshold);
482+
483+
return err;
477484
}
478485

479486
static int huawei_wmi_battery_remove(struct power_supply *battery)

0 commit comments

Comments
 (0)