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: 355a070b09 ("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>
This commit is contained in:
Jia-Ju Bai 2022-03-02 18:24:21 -08:00 коммит произвёл Hans de Goede
Родитель e1c21608e3
Коммит c91a5b1c22
1 изменённых файлов: 10 добавлений и 3 удалений

Просмотреть файл

@ -470,10 +470,17 @@ static DEVICE_ATTR_RW(charge_control_thresholds);
static int huawei_wmi_battery_add(struct power_supply *battery) static int huawei_wmi_battery_add(struct power_supply *battery)
{ {
device_create_file(&battery->dev, &dev_attr_charge_control_start_threshold); int err = 0;
device_create_file(&battery->dev, &dev_attr_charge_control_end_threshold);
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) static int huawei_wmi_battery_remove(struct power_supply *battery)