Skip to contentSkip to conversation

platform: x86: huawei-wmi: check the return value of device_create_file()

PATCH In review Jia-Ju Bai 2 participants 2 messages Mar 3, 2022 – Mar 8, 2022 x86 platform drivers

lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH v2 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.

Fixes 355a070b09ab ("platform/x86: huawei-wmi: Add battery charging thresholds")

---
v2:
* Fix the code format.
Thank Hans for good advice.

---
 drivers/platform/x86/huawei-wmi.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/platform/x86/huawei-wmi.c +10 -3
index a2d846c4a7ee..eac3e6b4ea11 100644
@@ -470,10 +470,17 @@ 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;
 
-	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)
Signature · 1 line
2.17.1
#1 lore raw

Hi,

Quoted 10 lines · 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")

---
v2:
* Fix the code format.
Thank Hans for good advice.

Thank you for your patch, I've applied this patch to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.

Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.

Regards,

Hans

Quoted 30 lines
---
 drivers/platform/x86/huawei-wmi.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/platform/x86/huawei-wmi.c +10 -3
index a2d846c4a7ee..eac3e6b4ea11 100644
@@ -470,10 +470,17 @@ 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;
 
-	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)