On Wed, 24 Apr 2024, Mark Cave-Ayland wrote:
On 22/04/2024 22:07, BALATON Zoltan wrote:
On Mon, 22 Apr 2024, Mark Cave-Ayland wrote:
When compiling with gcc 12 drivers/usb.c generates the following error:
/root/drivers/usb.c: In function 'get_descriptor': /root/drivers/usb.c:200:23: error: array subscript 'device_descriptor_t[0]' is partly outside array bounds of 'u8[8]' {aka 'unsigned char[8]'} [-Werror=array-bounds] 200 | if (dd->bMaxPacketSize0 != 0) | ^~ /root/drivers/usb.c:181:12: note: object 'buf' of size 8 181 | u8 buf[8]; | ^~~ cc1: all warnings being treated as errors make[1]: *** [rules.mak:229: target/drivers/usb.o] Error 1 make[1]: Leaving directory '/root/obj-ppc'
The compiler is complaining that a device_descriptor_t pointer cast to the 8 byte buffer means that a pointer dereference to some members of the device_descriptor_t could go beyond the end of the 8 byte buffer. Whilst this sounds as if it should be allowed, some searching suggests that the behaviour of such a cast is undefined.
Rework get_descriptor() so that an entire device_descriptor_t is used to store the first 8 bytes of the incoming descriptor, and update the buf references to use the equivalent device_descriptor_t fields instead.
Originally this came from libpayload of coreboot. To avoid diverging from that, aybe you can consider checking the changes there and updating this file from the current version of libpayload to also get the fixes and enhancements made there. This function seems to have been replaced in coreboot and not there any more.
I've had a quick look over at coreboot and it seems the latest version of this file is quite different from what is used here in OpenBIOS. Given that I've had requests to use the Debian compilers for upstream and reproducible builds, this would be better done as a follow-up exercise.
Can you remember which version of libpayload you used when importing into OpenBIOS and what the changes were that you made?
I've used the version that was current (probably in coreboot's git) at the time I've ported this driver. I still have a coreboot git clone with HEAD at commit d5403773901d from May 1 00:02:43 2014 so maybe it was around that time. I've deliberately kept changes minimal so it would be possible to later update the file so maybe you can get a patch with the needed changes by comparing to that coreboot commit. It looks like I had to do mostly endianness fixes, don't knoe if coreboot has fixed that already.
Regards, BALATON Zoltan