Skip to contentSkip to conversation

platform/x86: uniwill-laptop: Fix signedness bug

PATCH In review Ethan Tidmore 2 participants 2 messages Apr 3 – Apr 9

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86: uniwill-laptop: Fix signedness bug

The function sysfs_match_string() can return negative error codes and the variable assigned to it is the enum 'option'. Which could be an unsigned int due to different compiler implementations.

Assign signed variable 'ret' to sysfs_match_string(), check for error, then assign ret to option.

Detected by Smatch:
drivers/platform/x86/uniwill/uniwill-acpi.c:919 usb_c_power_priority_store()
warn: unsigned 'option' is never less than zero.

Fixes 03ae0a0d0973b ("platform/x86: uniwill-laptop: Implement USB-C power priority setting")
---
 drivers/platform/x86/uniwill/uniwill-acpi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/platform/x86/uniwill/uniwill-acpi.c +4 -3
index faade4cf08be..945df5092637 100644
@@ -915,10 +915,11 @@ static ssize_t usb_c_power_priority_store(struct device *dev,
 	unsigned int value;
 	int ret;
 
-	option = sysfs_match_string(usb_c_power_priority_text, buf);
-	if (option < 0)
-		return option;
+	ret = sysfs_match_string(usb_c_power_priority_text, buf);
+	if (ret < 0)
+		return ret;
 
+	option = ret;
 	value = usb_c_power_priority_value[option];
 
 	guard(mutex)(&data->usb_c_power_priority_lock);
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 8 lines · Ethan Tidmore

The function sysfs_match_string() can return negative error codes and the variable assigned to it is the enum 'option'. Which could be an unsigned int due to different compiler implementations.

Assign signed variable 'ret' to sysfs_match_string(), check for error, then assign ret to option.

[...]

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

The list of commits applied:
[1/1] platform/x86: uniwill-laptop: Fix signedness bug

      commit: 6b0567dc4c9ad140044400e06dd97fdce12c204f

--
i.