Skip to contentSkip to conversation

HID: hid-lenovo-go-s: Multiple bug fixes

PATCH In review Ethan Tidmore 2 participants 7 messages Feb 27 – Mar 6

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

cover HID: hid-lenovo-go-s: Multiple bug fixes

Here are three simple bug fixes found with Smatch.

Ethan Tidmore (3):
HID: hid-lenovo-go-s: Fix signedness bug
HID: hid-lenovo-go-s: Remove impossible condition
HID: hid-lenovo-go-s: Fix positive promotion bug

 drivers/hid/hid-lenovo-go-s.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/3 HID: hid-lenovo-go-s: Fix signedness bug

The function get_endpoint_address() returns type u8 but in its error path returns -ENODEV. Also, every variable that is assigned from this function is type int.

Change return type to int from u8.

Detected by Smatch:
drivers/hid/hid-lenovo-go-s.c:391 get_endpoint_address() warn:
signedness bug returning '(-19)'

Fixes 4325fdab5dbbf ("HID: hid-lenovo-go-s: Add Lenovo Legion Go S Series HID Driver")
---
 drivers/hid/hid-lenovo-go-s.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-lenovo-go-s.c +1 -1
index cacc5bd5ed2b..0ef98ba68d86 100644
@@ -377,7 +377,7 @@ static int hid_gos_set_event_return(struct command_report *cmd_rep)
 	return 0;
 }
 
-static u8 get_endpoint_address(struct hid_device *hdev)
+static int get_endpoint_address(struct hid_device *hdev)
 {
 	struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
 	struct usb_host_endpoint *ep;
Signature · 1 line
2.53.0
#3 lore raw

PATCH 2/3 HID: hid-lenovo-go-s: Remove impossible condition

In reply to Ethan Tidmore

The variable val is of type u8, so it can only be 0-255.

Remove this condition.

Detected by Smatch:
drivers/hid/hid-lenovo-go-s.c:508 gamepad_property_store() warn:
impossible condition '(val > 255) => (0-255 > 255)'

---
 drivers/hid/hid-lenovo-go-s.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/hid/hid-lenovo-go-s.c +0 -3
index 0ef98ba68d86..a24737170f83 100644
@@ -504,9 +504,6 @@ static ssize_t gamepad_property_store(struct device *dev,
 		ret = kstrtou8(buf, 10, &val);
 		if (ret)
 			return ret;
-
-		if (val < 0 || val > 255)
-			return -EINVAL;
 		break;
 	case FEATURE_IMU_ENABLE:
 		ret = sysfs_match_string(feature_enabled_text, buf);
Signature · 1 line
2.53.0
#5 lore raw

PATCH 3/3 HID: hid-lenovo-go-s: Fix positive promotion bug

In reply to Ethan Tidmore

The function mcu_property_out() returns type int and returns negative error codes. The variable count is assigned from it and checked with (count < 0) but this check would always be false because count can never be less than zero as it is size_t.

Change count to ssize_t.

Detected by Smatch:
drivers/hid/hid-lenovo-go-s.c:583 gamepad_property_show() warn:
unsigned 'count' is never less than zero.

drivers/hid/hid-lenovo-go-s.c:583 gamepad_property_show() warn:
error code type promoted to positive: 'count'

Fixes 14651777fd675 ("HID: hid-lenovo-go-s: Add Feature Status Attributes")
---
 drivers/hid/hid-lenovo-go-s.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-lenovo-go-s.c +1 -1
index a24737170f83..4596c18037a9 100644
@@ -573,7 +573,7 @@ static ssize_t gamepad_property_show(struct device *dev,
 				     struct device_attribute *attr, char *buf,
 				     enum feature_status_index index)
 {
-	size_t count = 0;
+	ssize_t count = 0;
 	u8 i;
 
 	count = mcu_property_out(drvdata.hdev, GET_GAMEPAD_CFG, index, 0, 0);
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] HID: hid-lenovo-go-s: Fix signedness bug

In reply to Ethan Tidmore
Quoted 31 lines · Ethan Tidmore

The function get_endpoint_address() returns type u8 but in its error path returns -ENODEV. Also, every variable that is assigned from this function is type int.

Change return type to int from u8.

Detected by Smatch:
drivers/hid/hid-lenovo-go-s.c:391 get_endpoint_address() warn:
signedness bug returning '(-19)'

Fixes 4325fdab5dbbf ("HID: hid-lenovo-go-s: Add Lenovo Legion Go S Series HID Driver")
---
 drivers/hid/hid-lenovo-go-s.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-lenovo-go-s.c +1 -2
index cacc5bd5ed2b..0ef98ba68d86 100644
@@ -377,7 +377,7 @@ static int hid_gos_set_event_return(struct command_report *cmd_rep)
        return 0;
 }
 
-static u8 get_endpoint_address(struct hid_device *hdev)
+static int get_endpoint_address(struct hid_device *hdev)
 {
        struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
        struct usb_host_endpoint *ep;
--
Quoted 2 lines

2.53.0

Hmm, odd that I did this correctly in the Go driver. Thanks.

maintainer Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] HID: hid-lenovo-go-s: Remove impossible condition

In reply to Ethan Tidmore
Quoted 29 lines · Ethan Tidmore

The variable val is of type u8, so it can only be 0-255.

Remove this condition.

Detected by Smatch:
drivers/hid/hid-lenovo-go-s.c:508 gamepad_property_store() warn:
impossible condition '(val > 255) => (0-255 > 255)'

---
 drivers/hid/hid-lenovo-go-s.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/hid/hid-lenovo-go-s.c +0 -4
index 0ef98ba68d86..a24737170f83 100644
@@ -504,9 +504,6 @@ static ssize_t gamepad_property_store(struct device *dev,
                ret = kstrtou8(buf, 10, &val);
                if (ret)
                        return ret;
-
-               if (val < 0 || val > 255)
-                       return -EINVAL;
                break;
        case FEATURE_IMU_ENABLE:
                ret = sysfs_match_string(feature_enabled_text, buf);
--
Quoted 2 lines

2.53.0

maintainer Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] HID: hid-lenovo-go-s: Fix positive promotion bug

In reply to Ethan Tidmore
Quoted 35 lines · Ethan Tidmore

The function mcu_property_out() returns type int and returns negative error codes. The variable count is assigned from it and checked with (count < 0) but this check would always be false because count can never be less than zero as it is size_t.

Change count to ssize_t.

Detected by Smatch:
drivers/hid/hid-lenovo-go-s.c:583 gamepad_property_show() warn:
unsigned 'count' is never less than zero.

drivers/hid/hid-lenovo-go-s.c:583 gamepad_property_show() warn:
error code type promoted to positive: 'count'

Fixes 14651777fd675 ("HID: hid-lenovo-go-s: Add Feature Status Attributes")
---
 drivers/hid/hid-lenovo-go-s.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-lenovo-go-s.c +1 -2
index a24737170f83..4596c18037a9 100644
@@ -573,7 +573,7 @@ static ssize_t gamepad_property_show(struct device *dev,
                                     struct device_attribute *attr, char *buf,
                                     enum feature_status_index index)
 {
-       size_t count = 0;
+       ssize_t count = 0;
        u8 i;
 
        count = mcu_property_out(drvdata.hdev, GET_GAMEPAD_CFG, index, 0, 0);
--
Quoted 2 lines

2.53.0