Closed diablodale closed 1 year ago
Hi @diablodale
Regarding Concern section:
I'd leave local variable and remove the global static and write to global static. libusb should handle that, so not really sure what the intention of setting it to wMaxPacketSize
was.
Regarding FYI section:
Thanks for addressing these - for the future, IMO best to go with device_search_improvements_libusb
way, as they remove the hard to deal with WinUSB code
OK, will update PR.
I get the desire for a single usb API. libusb will introduce LGPL 2.1 licensing which is very particular and legal in how libusb can be linked into code that uses it. As I understand, LGPL requires libusb can never be compiled into other code. Otherwise, the LGPL license is forced onto that using code. Instead, libusb must always be dynamically/shared linked. Someone (who?) has to compile libusb into a DLL and host the license and code. And then that independent DLL must be only dynamically linked to xlink and depthai-core; and the libusb.DLL distributed alongside the using code.
This then adds libusb.DLL (and other OS equals) to all your prebuild distributions and cmake needs related compile/install changes. Because if you compile libusb into using code, then the depthai license changes from MIT -> LGPL.
Yeah, LGPL isn't the most open licence but will work okay as long as we note a couple of things.
There are 2 ways to go:
The third option of having static libusb and static core, comes with a caveat that consuming application must then either be: provided in an object form to be able to relink another libusb or be opensource. This case should be documented so people aren't introducing licencing incompatible code into their project.
Note, we'll default to build libusb as a dll, so the change shouldn't affect anyone (with exception of Windows users regarding installing the libusb dll along their app)
Core doesn't have to become LGPL licenced as there is the exemption of being able to relink with another version of libusb, which an opensource library consuming it fits into (in dll case).
Disclaimer, I'm am not a lawyer - this is my understanding from reading through various sources.
I'm in alignment with what you wrote (as both non-lawyers). I've opened issue #37 to discuss independent of this issue.
XLink has various unsafe usage found by the MSVC code analyzer. Some are code defects and can lead to abnormal program flow and/or crash.
My intention is to fix code defects, and to decrease noise so that important warnings/errors can be seen. I have a PR ready that addresses all issues except one in the CONCERN section below
Setup
master
eef5a51c608fef8e326c740f120b90a543e55b27Repro
/analyze:plugin EspXEngine.dll /wd26440 /wd26496 /wd26462 /wd26460 /wd26481 /wd26493 /wd26446 /wd26482 /wd26485 /wd26812 /wd26476 /wd26490 /wd26472 /wd26495 /wd26432 /wd26457 /wd6031
Result
I read the below compiler+analyzer output and investigated the code. Almost all the issues the analyzer found are legitimate bugs (not style issues).
Concern -- need feedback
src\pc\protocols\usb_boot.c
there are two vars same namebulk_chunklen
. One is global static. The other is function localbulk_chunklen
as it might have had its value restricted by line 706 -- where libusb declares the max packet size for this usb endpoint. This is suspicious.I suspect a code defect concerning these
bulk_chunklen
vars. I don't have the USB experience or the hardware-level visibility to test this. 🤔 What is your view on this topic? I want to update the PR to address this (or open a separate bug for your USB team member to investigate).FYI
In
win_usb.c
the two call sites forSetupDiGetDeviceInterfaceDetail()
have inconsistent code, no error handling, memory leak due to missingLocalFree()
, and use of problematic Windows apis like_alloca()
. The call siteget_mx_id_device_path()
is definitely used. I didn't readily find a client-side codepath that would call the otherretreive_dev_path()
._alloca()
raises a Windows SEH exception on error and the existing code will crash the main program. SEH exceptions are Windows-only and require Windows specific wrapping via__try __except __finally
or the program crashes. https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/alloca?view=msvc-170 https://docs.microsoft.com/en-us/cpp/cpp/structured-exception-handling-c-cpp?view=msvc-170I resolved difference in the two call sites, handled leaks and errors, and changed to use
malloc()
. There is no need for the other inconsistent memory alloc functions.If you want to use
_alloca()
at one of the call sites, the adjusted code should be similar to... 😐