From 8221229498a119ec0af1d48e42d2eb83580956b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Tue, 21 Sep 2021 08:36:42 +0200 Subject: [PATCH] winebus.sys: Always add padding after button blocks. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: RĂ©mi Bernon Signed-off-by: Alexandre Julliard --- dlls/winebus.sys/bus_sdl.c | 7 ------- dlls/winebus.sys/bus_udev.c | 7 ------- dlls/winebus.sys/hid.c | 21 +++++++++++---------- dlls/winebus.sys/unix_private.h | 1 - 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index c83276aa873..bebe2eeb0f2 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -422,13 +422,6 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext) if (!hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, CONTROLLER_NUM_BUTTONS)) return STATUS_NO_MEMORY; - if (BUTTON_BIT_COUNT % 8 != 0) - { - /* unused bits between hatswitch and following constant */ - if (!hid_descriptor_add_padding(&ext->desc, 8 - (BUTTON_BIT_COUNT % 8))) - return STATUS_NO_MEMORY; - } - if (!descriptor_add_haptic(ext)) return STATUS_NO_MEMORY; diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 00c64829172..b9e5c968d0c 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -521,13 +521,6 @@ static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct u if (!hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) return STATUS_NO_MEMORY; - if (button_count % 8) - { - BYTE padding = 8 - (button_count % 8); - if (!hid_descriptor_add_padding(&ext->desc, padding)) - return STATUS_NO_MEMORY; - } - report_size += (button_count + 7) / 8; } diff --git a/dlls/winebus.sys/hid.c b/dlls/winebus.sys/hid.c index ba9fa4ba12d..d2dff7e5a24 100644 --- a/dlls/winebus.sys/hid.c +++ b/dlls/winebus.sys/hid.c @@ -99,6 +99,7 @@ void hid_descriptor_free(struct hid_descriptor *desc) BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page, USAGE usage_min, USAGE usage_max) { + const USHORT count = usage_max - usage_min + 1; const BYTE template[] = { USAGE_PAGE(2, usage_page), @@ -108,24 +109,24 @@ BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page, LOGICAL_MAXIMUM(1, 1), PHYSICAL_MINIMUM(1, 0), PHYSICAL_MAXIMUM(1, 1), - REPORT_COUNT(2, usage_max - usage_min + 1), + REPORT_COUNT(2, count), REPORT_SIZE(1, 1), INPUT(1, Data|Var|Abs), }; - - return hid_descriptor_append(desc, template, sizeof(template)); -} - -BOOL hid_descriptor_add_padding(struct hid_descriptor *desc, BYTE bitcount) -{ - const BYTE template[] = + const BYTE template_pad[] = { - REPORT_COUNT(1, bitcount), + REPORT_COUNT(1, 8 - (count % 8)), REPORT_SIZE(1, 1), INPUT(1, Cnst|Var|Abs), }; - return hid_descriptor_append(desc, template, sizeof(template)); + if (!hid_descriptor_append(desc, template, sizeof(template))) + return FALSE; + + if ((count % 8) && !hid_descriptor_append(desc, template_pad, sizeof(template_pad))) + return FALSE; + + return TRUE; } BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count) diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h index 069b6a0964a..cfb56d2d83e 100644 --- a/dlls/winebus.sys/unix_private.h +++ b/dlls/winebus.sys/unix_private.h @@ -82,7 +82,6 @@ extern void hid_descriptor_free(struct hid_descriptor *desc) DECLSPEC_HIDDEN; extern BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page, USAGE usage_min, USAGE usage_max) DECLSPEC_HIDDEN; -extern BOOL hid_descriptor_add_padding(struct hid_descriptor *desc, BYTE bitcount) DECLSPEC_HIDDEN; extern BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count) DECLSPEC_HIDDEN; extern BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usage_page, const USAGE *usages, BOOL rel, LONG min, LONG max) DECLSPEC_HIDDEN;