usb: prevent double opening

This could happen in gintctl's USB tracer and obviously cause all sorts
of problems.
This commit is contained in:
Lephe 2023-02-18 16:48:28 +01:00
parent 53c67af52d
commit c0671649df
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
2 changed files with 5 additions and 0 deletions

View file

@ -39,6 +39,8 @@ enum {
USB_OPEN_MISSING_DATA,
/* Invalid parameters: bad endpoint numbers, bad buffer sizes... */
USB_OPEN_INVALID_PARAMS,
/* USB interfaces are already opened */
USB_OPEN_ALREADY_OPEN,
/* This pipe is busy (returned by usb_write_async()) */
USB_WRITE_BUSY,

View file

@ -121,6 +121,9 @@ static void hpoweroff(void)
int usb_open(usb_interface_t const **interfaces, gint_call_t callback)
{
if(usb_open_status)
return USB_OPEN_ALREADY_OPEN;
/* TODO: Check whether the calculator can host devices (probably no) */
bool host = false;