From 0fc5630f3cab1f7bb5b449429adfcd2b4d21edbf Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Fri, 18 Feb 2022 13:37:12 +0000 Subject: [PATCH] fel_lib: fix wrong const annotation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The aw_usb_read() function is meant to *fill* the buffer given to it, so marking the pointer as "const" in the parameters list is wrong. Some compilers (for instance GCC 11) spot this and issue a warning: ---------------------------------- fel_lib.c: In function ‘aw_read_fel_status’: fel_lib.c:190:9: warning: ‘buf’ may be used uninitialized [-Wmaybe-uninitialize] 190 | aw_usb_read(dev, buf, sizeof(buf)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fel_lib.c:168:13: note: by argument 2 of type ‘const void *’ to ‘aw_usb_read’ declared here 168 | static void aw_usb_read(feldev_handle *dev, const void *data, size_t len) | ^~~~~~~~~~~ fel_lib.c:189:14: note: ‘buf’ declared here 189 | char buf[8]; | ^~~ ---------------------------------- Drop the 'const' specifier, and use the right USB bulk transfer wrapper to make this work. The usb_bulk_send() function just happened to work before because the actual libusb bulk transfer function is bidirectional. Signed-off-by: Andre Przywara --- fel_lib.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fel_lib.c b/fel_lib.c index 0852cc8..485df2b 100644 --- a/fel_lib.c +++ b/fel_lib.c @@ -165,11 +165,10 @@ static void aw_usb_write(feldev_handle *dev, const void *data, size_t len, aw_read_usb_response(dev); } -static void aw_usb_read(feldev_handle *dev, const void *data, size_t len) +static void aw_usb_read(feldev_handle *dev, void *data, size_t len) { aw_send_usb_request(dev, AW_USB_READ, len); - usb_bulk_send(dev->usb->handle, dev->usb->endpoint_in, - data, len, false); + usb_bulk_recv(dev->usb->handle, dev->usb->endpoint_in, data, len); aw_read_usb_response(dev); }