platform: x86: huawei-wmi: check the return value of device_create_file()
PATCH 1/1 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.
--- drivers/platform/x86/huawei-wmi.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/platform/x86/huawei-wmi.c +12 -3
@@ -470,10 +470,19 @@ 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 ; + 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 0 ; +return err; }static int huawei_wmi_battery_remove (struct power_supply *battery)
Signature · 1 line
2.17.1
Hi,
Quoted 6 lines · Jia-Ju Bai
The function
device_create_file()inhuawei_wmi_battery_add()can fail, so its return value should be checked.Fixes 355a070b09ab ("platform/x86: huawei-wmi: Add battery charging thresholds")Reported-by TOTE Robot <[email protected]>Signed-off-by Jia-Ju Bai <[email protected]>
Please run check-patch.pl your patches before submitting them.
Quoted 9 lines
--- drivers/platform/x86/huawei-wmi.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)drivers/platform/x86/huawei-wmi.c +0
-0
drivers/platform/x86/huawei-wmi.c static DEVICE_ATTR_RW(charge_control_thresholds); · line 473
Quoted 6 lines
drivers/platform/x86/huawei-wmi.c +1
-2@@ -470,10 +470,19 @@ 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 ;
There needs to be an empty line here,
drivers/platform/x86/huawei-wmi.c static DEVICE_ATTR_RW(charge_control_thresholds); · line 475
Quoted 2 lines
drivers/platform/x86/huawei-wmi.c +2
-0+ err =device_create_file (&battery->dev, + &dev_attr_charge_control_start_threshold);
Why the weird continuation of the call on another line? Please make this a single line.
drivers/platform/x86/huawei-wmi.c static DEVICE_ATTR_RW(charge_control_thresholds); · line 477
Quoted 2 lines
drivers/platform/x86/huawei-wmi.c +2
-0+if (err) +return err;
Empty line here.
drivers/platform/x86/huawei-wmi.c static DEVICE_ATTR_RW(charge_control_thresholds); · line 479
Quoted 2 lines
drivers/platform/x86/huawei-wmi.c +2
-0+ err =device_create_file (&battery->dev, + &dev_attr_charge_control_end_threshold);
Please make this a single line.
drivers/platform/x86/huawei-wmi.c static DEVICE_ATTR_RW(charge_control_thresholds); · line 483
Quoted 4 lines
drivers/platform/x86/huawei-wmi.c +4
-0+if (err) { +device_remove_file (&battery->dev, + &dev_attr_charge_control_start_threshold); + }
No need for {} here.
drivers/platform/x86/huawei-wmi.c static DEVICE_ATTR_RW(charge_control_thresholds); · line 488
Quoted 6 lines
drivers/platform/x86/huawei-wmi.c +1
-1-return 0 ; +return err; }static int huawei_wmi_battery_remove (struct power_supply *battery)
Regards,
Hans
Hi Hans,
Thanks for the advice!
I will send a V2 patch.
Best wishes,
Jia-Ju Bai
Quoted 56 lines · Hans de Goede
Hi,
Quoted 6 lines · Jia-Ju Bai
The function
device_create_file()inhuawei_wmi_battery_add()can fail, so its return value should be checked.Fixes 355a070b09ab ("platform/x86: huawei-wmi: Add battery charging thresholds")Reported-by TOTE Robot <[email protected]>Signed-off-by Jia-Ju Bai <[email protected]>Please run check-patch.pl your patches before submitting them.
Quoted 9 lines
--- drivers/platform/x86/huawei-wmi.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)drivers/platform/x86/huawei-wmi.c +0
-0drivers/platform/x86/huawei-wmi.c static DEVICE_ATTR_RW(charge_control_thresholds); · line 473
Quoted 6 lines
drivers/platform/x86/huawei-wmi.c +1
-2@@ -470,10 +470,19 @@ 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 ;There needs to be an empty line here,
drivers/platform/x86/huawei-wmi.c static DEVICE_ATTR_RW(charge_control_thresholds); · line 475
Quoted 2 lines
drivers/platform/x86/huawei-wmi.c +2
-0+ err =device_create_file (&battery->dev, + &dev_attr_charge_control_start_threshold);Why the weird continuation of the call on another line? Please make this a single line.
drivers/platform/x86/huawei-wmi.c static DEVICE_ATTR_RW(charge_control_thresholds); · line 477
Quoted 2 lines
drivers/platform/x86/huawei-wmi.c +2
-0+if (err) +return err;Empty line here.
drivers/platform/x86/huawei-wmi.c static DEVICE_ATTR_RW(charge_control_thresholds); · line 479
Quoted 2 lines
drivers/platform/x86/huawei-wmi.c +2
-0+ err =device_create_file (&battery->dev, + &dev_attr_charge_control_end_threshold);Please make this a single line.
drivers/platform/x86/huawei-wmi.c static DEVICE_ATTR_RW(charge_control_thresholds); · line 483
Quoted 4 lines
drivers/platform/x86/huawei-wmi.c +4
-0+if (err) { +device_remove_file (&battery->dev, + &dev_attr_charge_control_start_threshold); + }No need for {} here.
drivers/platform/x86/huawei-wmi.c static DEVICE_ATTR_RW(charge_control_thresholds); · line 488
Quoted 6 lines
drivers/platform/x86/huawei-wmi.c +1
-1-return 0 ; +return err; }static int huawei_wmi_battery_remove (struct power_supply *battery)Regards,
Hans