Skip to content

Commit

Permalink
drivers/libshut.c: libshut_open(): use static structs and memcpy() to…
Browse files Browse the repository at this point in the history
… actually fix alignment warnings

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jul 5, 2024
1 parent c8f4fe9 commit 7b26627
Showing 1 changed file with 4 additions and 37 deletions.
41 changes: 4 additions & 37 deletions drivers/libshut.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,10 @@ static int libshut_open(
usb_ctrl_charbuf rdbuf, usb_ctrl_charbufsize rdlen))
{
int ret, res;
/* Below we cast this buffer as sometimes containing entried of type
* "struct device_descriptor_s" or "struct my_hid_descriptor".
* Currently both of these are sized "2", and I don't see a way
* to require a "max()" of such sizes to align for generally.
*/
usb_ctrl_char buf[20] __attribute__((aligned(4)));
char string[MAX_STRING_SIZE];
struct my_hid_descriptor *desc;
struct device_descriptor_s *dev_descriptor;
struct my_hid_descriptor desc_buf, *desc = &desc_buf;
struct device_descriptor_s dev_descriptor_buf, *dev_descriptor = &dev_descriptor_buf;

/* report descriptor */
usb_ctrl_char rdbuf[MAX_REPORT_SIZE];
Expand Down Expand Up @@ -470,21 +465,7 @@ static int libshut_open(
}

/* Get DEVICE descriptor */
#if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CAST_ALIGN)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wcast-align"
#endif
#ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wcast-align"
#endif
dev_descriptor = (struct device_descriptor_s *)buf;
#ifdef __clang__
# pragma clang diagnostic pop
#endif
#if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CAST_ALIGN)
# pragma GCC diagnostic pop
#endif
memcpy(dev_descriptor, buf, sizeof(struct device_descriptor_s));
res = shut_get_descriptor(*arg_upsfd, USB_DT_DEVICE, 0, buf, USB_DT_DEVICE_SIZE);
/* res = shut_control_msg(devp, USB_ENDPOINT_IN+1, USB_REQ_GET_DESCRIPTOR,
(USB_DT_DEVICE << 8) + 0, 0, buf, 0x9, SHUT_TIMEOUT); */
Expand Down Expand Up @@ -587,21 +568,7 @@ static int libshut_open(
}

/* Get HID descriptor */
#if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CAST_ALIGN)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wcast-align"
#endif
#ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wcast-align"
#endif
desc = (struct my_hid_descriptor *)buf;
#ifdef __clang__
# pragma clang diagnostic pop
#endif
#if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CAST_ALIGN)
# pragma GCC diagnostic pop
#endif
memcpy(desc, buf, sizeof(struct my_hid_descriptor));
res = shut_get_descriptor(*arg_upsfd, USB_DT_HID, hid_desc_index, buf, 0x9);
/* res = shut_control_msg(devp, USB_ENDPOINT_IN+1, USB_REQ_GET_DESCRIPTOR,
(USB_DT_HID << 8) + 0, 0, buf, 0x9, SHUT_TIMEOUT); */
Expand Down

0 comments on commit 7b26627

Please sign in to comment.