From c0671649df07e205ea568fb4bd7c49a878bfbbb7 Mon Sep 17 00:00:00 2001 From: Lephe Date: Sat, 18 Feb 2023 16:48:28 +0100 Subject: [PATCH] usb: prevent double opening This could happen in gintctl's USB tracer and obviously cause all sorts of problems. --- include/gint/usb.h | 2 ++ src/usb/usb.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/include/gint/usb.h b/include/gint/usb.h index 66e4a63..0ccc08f 100644 --- a/include/gint/usb.h +++ b/include/gint/usb.h @@ -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, diff --git a/src/usb/usb.c b/src/usb/usb.c index 8e25a10..c0e7228 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -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;