HID: logitech-dj: fix unintentional integer overflow on left shift
Subsystems (3)
PATCH 1/1 HID: logitech-dj: fix unintentional integer overflow on left shift
From: Colin Ian King <[email protected]>
Shifting the integer value 1 is evaluated using 32-bit rithmetic and then used in an expression that expects a 64-bit value, so there is potentially an integer overflow. Fix this by using th BIT_ULL macro to perform the shift and avoid the overflow.
Addresses-Coverity: ("Uninitentional integer overflow")
--- drivers/hid/hid-logitech-dj.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-logitech-dj.c +1 -1
@@ -1035,7 +1035,7 @@ static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev,memset (reportbuffer,0 ,sizeof (reportbuffer));for (i =0 ; i <NUMBER_OF_HID_REPORTS ; i++) { -if (djdev->reports_supported & (1 << i)) { +if (djdev->reports_supported &BIT_ULL (i)) { reportbuffer[0 ] = i; if (hid_input_report(djdev->hdev, HID_INPUT_REPORT,
Signature · 1 line
2.29.2
Quoted 19 lines · Colin King
From: Colin Ian King <[email protected]>
Shifting the integer value 1 is evaluated using 32-bit rithmetic and then used in an expression that expects a 64-bit value, so there is potentially an integer overflow. Fix this by using th
BIT_ULLmacro to perform the shift and avoid the overflow.Addresses-Coverity: ("Uninitentional integer overflow")
Fixes 534a7b8e10ec ("HID: Add full support for Logitech Unifying receivers")Signed-off-by Colin Ian King <[email protected]>--- drivers/hid/hid-logitech-dj.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hid/hid-logitech-dj.c +0
-0
drivers/hid/hid-logitech-dj.c static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev, · line 1037
Quoted 3 lines
drivers/hid/hid-logitech-dj.c +0
-0@@ -1035,7 +1035,7 @@ static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev,memset (reportbuffer,0 ,sizeof (reportbuffer));for (i =0 ; i <NUMBER_OF_HID_REPORTS ; i++) {
^^^^^^^^^^^^^^^^^^^^^
This is 32, so it can't be undefined.
drivers/hid/hid-logitech-dj.c static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev, · line 1041
Quoted 5 lines
drivers/hid/hid-logitech-dj.c +1
-1-if (djdev->reports_supported & (1 << i)) { +if (djdev->reports_supported &BIT_ULL (i)) { reportbuffer[0 ] = i; if (hid_input_report(djdev->hdev, HID_INPUT_REPORT,
regards,
dan carpenter
Quoted 22 lines · Dan Carpenter
Quoted 21 lines · Colin King
From: Colin Ian King <[email protected]>
Shifting the integer value 1 is evaluated using 32-bit rithmetic and then used in an expression that expects a 64-bit value, so there is potentially an integer overflow. Fix this by using th
BIT_ULLmacro to perform the shift and avoid the overflow.Addresses-Coverity: ("Uninitentional integer overflow")
Fixes 534a7b8e10ec ("HID: Add full support for Logitech Unifying receivers")Signed-off-by Colin Ian King <[email protected]>--- drivers/hid/hid-logitech-dj.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hid/hid-logitech-dj.c +0
-0@@ -1035,7 +1035,7 @@ static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev,memset (reportbuffer,0 ,sizeof (reportbuffer));
Quoted 3 lines
drivers/hid/hid-logitech-dj.c static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev, · line 1037
Quoted 1 line
drivers/hid/hid-logitech-dj.c +0
-0for (i =0 ; i <NUMBER_OF_HID_REPORTS ; i++) {^^^^^^^^^^^^^^^^^^^^^This is 32, so it can't be undefined.
Urgh, looks like coverity is being overly pedantic here. :-(
Quoted 10 lines
drivers/hid/hid-logitech-dj.c static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev, · line 1041
Quoted 6 lines
drivers/hid/hid-logitech-dj.c +1
-1-if (djdev->reports_supported & (1 << i)) { +if (djdev->reports_supported &BIT_ULL (i)) { reportbuffer[0 ] = i; if (hid_input_report(djdev->hdev, HID_INPUT_REPORT,regards,
dan carpenter