HID: hid-lenovo-go-s: Multiple bug fixes
Subsystems (2)
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
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)'
--- drivers/hid/hid-lenovo-go-s.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-lenovo-go-s.c +1 -1
@@ -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
PATCH 2/3 HID: hid-lenovo-go-s: Remove impossible condition
In reply to Ethan TidmoreThe 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
@@ -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
PATCH 3/3 HID: hid-lenovo-go-s: Fix positive promotion bug
In reply to Ethan TidmoreThe 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'
--- drivers/hid/hid-lenovo-go-s.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-lenovo-go-s.c +1 -1
@@ -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
Re: [PATCH 1/3] HID: hid-lenovo-go-s: Fix signedness bug
In reply to Ethan TidmoreQuoted 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:391get_endpoint_address()warn:
signedness bug returning '(-19)'Fixes 4325fdab5dbbf ("HID: hid-lenovo-go-s: Add Lenovo Legion Go S Series HID Driver")Signed-off-by Ethan Tidmore <[email protected]>--- drivers/hid/hid-lenovo-go-s.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hid/hid-lenovo-go-s.c +1
-2@@ -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.
Re: [PATCH 2/3] HID: hid-lenovo-go-s: Remove impossible condition
In reply to Ethan TidmoreQuoted 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:508gamepad_property_store()warn:
impossible condition '(val > 255) => (0-255 > 255)'Signed-off-by Ethan Tidmore <[email protected]>--- drivers/hid/hid-lenovo-go-s.c | 3 --- 1 file changed, 3 deletions(-)drivers/hid/hid-lenovo-go-s.c +0
-4@@ -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
Re: [PATCH 3/3] HID: hid-lenovo-go-s: Fix positive promotion bug
In reply to Ethan TidmoreQuoted 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 issize_t.Change count to
ssize_t.Detected by Smatch:
drivers/hid/hid-lenovo-go-s.c:583gamepad_property_show()warn:
unsigned 'count' is never less than zero.
drivers/hid/hid-lenovo-go-s.c:583gamepad_property_show()warn:
error code type promoted to positive: 'count'Fixes 14651777fd675 ("HID: hid-lenovo-go-s: Add Feature Status Attributes")Signed-off-by Ethan Tidmore <[email protected]>--- drivers/hid/hid-lenovo-go-s.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hid/hid-lenovo-go-s.c +1
-2@@ -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