--- zzzz-none-000/linux-3.10.107/drivers/input/tablet/gtco.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/input/tablet/gtco.c 2021-02-04 17:41:59.000000000 +0000 @@ -53,14 +53,13 @@ #include #include #include -#include #include #include #include #include #include #include - +#include #include @@ -232,13 +231,17 @@ /* Walk this report and pull out the info we need */ while (i < length) { - prefix = report[i]; - - /* Skip over prefix */ - i++; + prefix = report[i++]; /* Determine data size and save the data in the proper variable */ - size = PREF_SIZE(prefix); + size = (1U << PREF_SIZE(prefix)) >> 1; + if (i + size > length) { + dev_err(ddev, + "Not enough data (need %d, have %d)\n", + i + size, length); + break; + } + switch (size) { case 1: data = report[i]; @@ -246,8 +249,7 @@ case 2: data16 = get_unaligned_le16(&report[i]); break; - case 3: - size = 4; + case 4: data32 = get_unaligned_le32(&report[i]); break; } @@ -615,7 +617,6 @@ struct input_dev *inputdev; int rc; u32 val = 0; - s8 valsigned = 0; char le_buffer[2]; inputdev = device->inputdevice; @@ -666,20 +667,11 @@ /* Fall thru */ case 4: /* Tilt */ + input_report_abs(inputdev, ABS_TILT_X, + sign_extend32(device->buffer[6], 6)); - /* Sign extend these 7 bit numbers. */ - if (device->buffer[6] & 0x40) - device->buffer[6] |= 0x80; - - if (device->buffer[7] & 0x40) - device->buffer[7] |= 0x80; - - - valsigned = (device->buffer[6]); - input_report_abs(inputdev, ABS_TILT_X, (s32)valsigned); - - valsigned = (device->buffer[7]); - input_report_abs(inputdev, ABS_TILT_Y, (s32)valsigned); + input_report_abs(inputdev, ABS_TILT_Y, + sign_extend32(device->buffer[7], 6)); /* Fall thru */ case 2: @@ -849,7 +841,7 @@ gtco->inputdevice = input_dev; /* Save interface information */ - gtco->usbdev = usb_get_dev(interface_to_usbdev(usbinterface)); + gtco->usbdev = interface_to_usbdev(usbinterface); gtco->intf = usbinterface; /* Allocate some data for incoming reports */