From: Gerhard Sittig Date: Mon, 31 Jan 2022 21:08:41 +0000 (+0100) Subject: kingst-la2016: rephrase USB bulk transfer size padding constraint X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=418dfd7ed3bb2c62c110f7924c796e126fd41e79;p=libsigrok.git kingst-la2016: rephrase USB bulk transfer size padding constraint Always round up capture data USB bulk transfer sizes to full EP 6 packet sizes. The previous implementation suggested that it's only required for smaller transfers, but it's just a coincidence that the upper limit of 256KiB happened to also be a multiple of the 512B packet size. It's assumed that capping at the absolute size limit and always padding is more readable and as reliable as the previous if-else logic was. Rephrase the round up by means of integer multiplication instead of bit twiddling. Compilers should get what is intended, humans may prefer to read the former. --- diff --git a/src/hardware/kingst-la2016/protocol.c b/src/hardware/kingst-la2016/protocol.c index a92c822a..6ab72df0 100644 --- a/src/hardware/kingst-la2016/protocol.c +++ b/src/hardware/kingst-la2016/protocol.c @@ -1018,8 +1018,9 @@ static int la2016_start_download(const struct sr_dev_inst *sdi, to_read = devc->n_bytes_to_read; if (to_read >= LA2016_USB_BUFSZ) /* Multiple transfers. */ to_read = LA2016_USB_BUFSZ; - else /* One transfer. */ - to_read = (to_read + (LA2016_EP6_PKTSZ-1)) & ~(LA2016_EP6_PKTSZ-1); + to_read += LA2016_EP6_PKTSZ - 1; + to_read /= LA2016_EP6_PKTSZ; + to_read *= LA2016_EP6_PKTSZ; buffer = g_try_malloc(to_read); if (!buffer) { sr_dbg("USB bulk transfer size %d bytes.", (int)to_read); @@ -1144,8 +1145,9 @@ static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer) */ if (to_read >= LA2016_USB_BUFSZ) to_read = LA2016_USB_BUFSZ; - else - to_read = (to_read + (LA2016_EP6_PKTSZ-1)) & ~(LA2016_EP6_PKTSZ-1); + to_read += LA2016_EP6_PKTSZ - 1; + to_read /= LA2016_EP6_PKTSZ; + to_read *= LA2016_EP6_PKTSZ; libusb_fill_bulk_transfer(transfer, usb->devhdl, USB_EP_CAPTURE_DATA | LIBUSB_ENDPOINT_IN, transfer->buffer, to_read,