commit | c3864c822b190dfbef48b0459222a08467f94cfb | [log] [tgz] |
---|---|---|
author | Chris Dickens <christopher.a.dickens@gmail.com> | Thu Jan 23 16:18:24 2020 -0800 |
committer | Chris Dickens <christopher.a.dickens@gmail.com> | Fri Jan 24 11:22:52 2020 -0800 |
tree | 8b3a498944772040058f52d5292d7820eeeb150b | |
parent | d5bb64b3dc438a0a03c66d08a7fd12de5543f538 [diff] |
linux_usbfs: Clean up inconsistencies and optimize memory usage The formatting and coding style varied across the whole file. Adopt the following consistent style: - Align function arguments to the opening parenthesis - Do not check for NULL before calling free() - Reduce indentation where possible in loops by continuing in the success case - Remove space between function name and opening parenthesis - Remove pointless pointer casts from void * - Replace comparisons with NULL or 0 by a negation operator - When comparing against rvalues, place the rvalue on the right side of the expression - Where possible, have the debug message string on the same line as the usbi_* call. This makes it easier to grep for specific strings. Also update the definitions in linux_usbfs.h to exactly match that of the kernel and remove definitions that are not needed. A number of functions declared stack buffers of size PATH_MAX. This is generally 4K, which is very much overkill for a lot of the strings and is not friendly for embedded environments. Replace many of these buffers with reasonably-sized ones, in many cases using exactly the size needed. When reading the descriptors during device enumeration, we were starting with a 1K buffer and doubling as needed. The vast majority of devices will not have a large set of descriptors, so change the allocation logic to grow the buffer in steps of 256 bytes. Introduce a new parsing function for reading sysfs attributes. Using the fdopen() function to use fscanf() results in excessive memory allocation, one for the FILE object and another for the buffer into which the C library will read the data. The sysfs attributes of interest are generally just a few characters, so use a small stack buffer and some rigorous parsing to read these attributes. This also consolidates error checking (e.g. negative values or larger than expected values). Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb is a library for USB device access from Linux, macOS, Windows, OpenBSD/NetBSD and Haiku userspace. It is written in C (Haiku backend in C++) and licensed under the GNU Lesser General Public License version 2.1 or, at your option, any later version (see COPYING).
libusb is abstracted internally in such a way that it can hopefully be ported to other operating systems. Please see the PORTING file for more information.
libusb homepage: http://libusb.info/
Developers will wish to consult the API documentation: http://api.libusb.info
Use the mailing list for questions, comments, etc: http://mailing-list.libusb.info
(Please use the mailing list rather than mailing developers directly)