From: Marek Szyprowski Date: Thu, 19 Jan 2023 07:30:10 +0000 (+0100) Subject: usb-gadget: Handle more than one extcon reporting USB cable X-Git-Tag: accepted/tizen/unified/20230209.111259~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c9dee14badcb31d4a238798d48a17e9b260e6a3c;p=platform%2Fcore%2Fsystem%2Fdeviced.git usb-gadget: Handle more than one extcon reporting USB cable Signed-off-by: Marek Szyprowski Change-Id: I0c26ac4ecb13f1cd6d0c464a105e1e333b411806 --- diff --git a/src/usb-gadget/usb-gadget.c b/src/usb-gadget/usb-gadget.c index 1a0769c..bc551ea 100644 --- a/src/usb-gadget/usb-gadget.c +++ b/src/usb-gadget/usb-gadget.c @@ -205,15 +205,26 @@ static int usb_state_changed(const char *index, int new_status) { int ret = -1; static int old_status = -1; /* -1: Uninitialized, 0: disconnected, 1: connected */ + static char old_index[NAME_MAX]; /* For debugging. Do not move the location. */ - _I("USB state is changed by extcon from (%d) to (%d).", old_status, new_status); + _I("USB state is changed by extcon \"%s\" from (%d) to (%d).", index ? index : "(NULL)", old_status, new_status); + + if (old_index[0] != '\0' && index && strncmp(old_index, index, sizeof(old_index)) != 0) { + _I("USB state change ignored on extcon \"%s\"\n", index); + return 0; + } if (old_status == new_status) return 0; switch (new_status) { case USB_CONNECTED: + old_index[0] = '\0'; + if (index) { + strncpy(old_index, index, sizeof(old_index) - 1); + old_index[sizeof(old_index) - 1] = '\0'; + } ret = usb_connected(); break; @@ -221,6 +232,7 @@ static int usb_state_changed(const char *index, int new_status) if (old_status == -1) { /* only initialize the internal data state and skip usb hal operation. */ _I("USB is initialized without USB connection"); + old_index[0] = '\0'; /* From usb_disconnected() */ usb_state_set_connection(USB_DISCONNECTED); @@ -231,8 +243,10 @@ static int usb_state_changed(const char *index, int new_status) change_usb_state_notification_handler(USB_GADGET_FUNC_NONE); ret = 0; - } else + } else { + old_index[0] = '\0'; ret = usb_disconnected(); + } break; default: