[PATCH 5/5] hid: Shift usage values to LSB

Aric Stewart aric at codeweavers.com
Mon May 6 11:38:46 CDT 2019


Signed-off-by: Aric Stewart <aric at codeweavers.com>

On 5/6/19 8:46 AM, Andrew Eikum wrote:
> Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>
> ---
> 
> This applies on top of Piotr's series.
> 
> 
>   dlls/hid/hidp.c | 33 ++++++++++++++-------------------
>   1 file changed, 14 insertions(+), 19 deletions(-)
> 
> diff --git a/dlls/hid/hidp.c b/dlls/hid/hidp.c
> index 2c4e98ad541..6a686d4334c 100644
> --- a/dlls/hid/hidp.c
> +++ b/dlls/hid/hidp.c
> @@ -49,32 +49,27 @@ static NTSTATUS get_report_data(BYTE *report, INT reportLength, INT startBit, IN
>           ULONG byte_index = startBit / 8;
>           ULONG bit_index = startBit - (byte_index * 8);
>           INT mask = (1 << bit_index);
> -        *value = (report[byte_index] & mask);
> +        *value = !!(report[byte_index] & mask);
>       }
>       else
>       {
> +        ULONG remaining_bits = valueSize;
>           ULONG byte_index = startBit / 8;
> +        ULONG bit_index = startBit % 8;
>           ULONG data = 0;
> -        ULONG remainingBits = valueSize;
>           ULONG shift = 0;
> -        ULONG begin_offset = startBit % 8;
> -        while (remainingBits)
> +        while (remaining_bits)
>           {
> -            if (remainingBits >= 8)
> -            {
> -                BYTE mask = 0xff << begin_offset;
> -                data |= (report[byte_index] & mask) << shift;
> -                byte_index ++;
> -                remainingBits -= (8-begin_offset);
> -                shift += (8-begin_offset);
> -                begin_offset = 0;
> -            }
> -            else if (remainingBits > 0)
> -            {
> -                BYTE mask = (0xff >> (8-remainingBits)) << begin_offset;
> -                data |= (report[byte_index] & mask) << shift;
> -                remainingBits = 0;
> -            }
> +            ULONG copy_bits = 8 - bit_index;
> +            if (remaining_bits < copy_bits)
> +                copy_bits = remaining_bits;
> +
> +            data |= ((report[byte_index] >> bit_index) & ((2 << copy_bits) - 1)) << shift;
> +
> +            shift += copy_bits;
> +            bit_index = 0;
> +            byte_index++;
> +            remaining_bits -= copy_bits;
>           }
>           *value = data;
>       }
> 



More information about the wine-devel mailing list