lkml.org 
[lkml]   [2022]   [Feb]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] platform: x86: huawei-wmi: check the return value of device_create_file()
Date
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
\
 
 \ /
  Last update: 2022-02-25 14:05    [W:0.597 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site