* [PATCH] platform: x86: huawei-wmi: check the return value of device_create_file()
@ 2022-02-25 13:04 Jia-Ju Bai
2022-03-02 14:31 ` Hans de Goede
0 siblings, 1 reply; 3+ messages in thread
From: Jia-Ju Bai @ 2022-02-25 13:04 UTC (permalink / raw)
To: hdegoede, markgross; +Cc: platform-driver-x86, linux-kernel, Jia-Ju Bai
The function device_create_file() in huawei_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 <oslab@tsinghua.edu.cn>
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
drivers/platform/x86/huawei-wmi.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c
index a2d846c4a7ee..2ffd3840f3e8 100644
--- a/drivers/platform/x86/huawei-wmi.c
+++ b/drivers/platform/x86/huawei-wmi.c
@@ -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)
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] platform: x86: huawei-wmi: check the return value of device_create_file()
2022-02-25 13:04 [PATCH] platform: x86: huawei-wmi: check the return value of device_create_file() Jia-Ju Bai
@ 2022-03-02 14:31 ` Hans de Goede
2022-03-03 1:45 ` Jia-Ju Bai
0 siblings, 1 reply; 3+ messages in thread
From: Hans de Goede @ 2022-03-02 14:31 UTC (permalink / raw)
To: Jia-Ju Bai, markgross; +Cc: platform-driver-x86, linux-kernel
Hi,
On 2/25/22 14:04, Jia-Ju Bai wrote:
> The function device_create_file() in huawei_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 <oslab@tsinghua.edu.cn>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Please run check-patch.pl your patches before submitting them.
> ---
> drivers/platform/x86/huawei-wmi.c | 15 ++++++++++++---
> 1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c
> index a2d846c4a7ee..2ffd3840f3e8 100644
> --- a/drivers/platform/x86/huawei-wmi.c
> +++ b/drivers/platform/x86/huawei-wmi.c
> @@ -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,
> + 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.
> + if (err)
> + return err;
Empty line here.
> + err = device_create_file(&battery->dev,
> + &dev_attr_charge_control_end_threshold);
Please make this a single line.
> + if (err) {
> + device_remove_file(&battery->dev,
> + &dev_attr_charge_control_start_threshold);
> + }
No need for {} here.
>
> - return 0;
> + return err;
> }
>
> static int huawei_wmi_battery_remove(struct power_supply *battery)
Regards,
Hans
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] platform: x86: huawei-wmi: check the return value of device_create_file()
2022-03-02 14:31 ` Hans de Goede
@ 2022-03-03 1:45 ` Jia-Ju Bai
0 siblings, 0 replies; 3+ messages in thread
From: Jia-Ju Bai @ 2022-03-03 1:45 UTC (permalink / raw)
To: Hans de Goede, markgross; +Cc: platform-driver-x86, linux-kernel
Hi Hans,
Thanks for the advice!
I will send a V2 patch.
Best wishes,
Jia-Ju Bai
On 2022/3/2 22:31, Hans de Goede wrote:
> Hi,
>
> On 2/25/22 14:04, Jia-Ju Bai wrote:
>> The function device_create_file() in huawei_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 <oslab@tsinghua.edu.cn>
>> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> Please run check-patch.pl your patches before submitting them.
>
>
>> ---
>> drivers/platform/x86/huawei-wmi.c | 15 ++++++++++++---
>> 1 file changed, 12 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c
>> index a2d846c4a7ee..2ffd3840f3e8 100644
>> --- a/drivers/platform/x86/huawei-wmi.c
>> +++ b/drivers/platform/x86/huawei-wmi.c
>> @@ -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,
>> + 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.
>
>> + if (err)
>> + return err;
> Empty line here.
>
>> + err = device_create_file(&battery->dev,
>> + &dev_attr_charge_control_end_threshold);
> Please make this a single line.
>
>> + if (err) {
>> + device_remove_file(&battery->dev,
>> + &dev_attr_charge_control_start_threshold);
>> + }
> No need for {} here.
>
>>
>> - return 0;
>> + return err;
>> }
>>
>> static int huawei_wmi_battery_remove(struct power_supply *battery)
> Regards,
>
> Hans
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-03 1:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-25 13:04 [PATCH] platform: x86: huawei-wmi: check the return value of device_create_file() Jia-Ju Bai
2022-03-02 14:31 ` Hans de Goede
2022-03-03 1:45 ` Jia-Ju Bai
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.