diff --git a/drivers/staging/usbip/userspace/src/usbip_attach.c b/drivers/staging/usbip/userspace/src/usbip_attach.c index bdf61c0fe699..2da4e44e1633 100644 --- a/drivers/staging/usbip/userspace/src/usbip_attach.c +++ b/drivers/staging/usbip/userspace/src/usbip_attach.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "vhci_driver.h" #include "usbip_common.h" @@ -52,8 +53,18 @@ static int record_connection(char *host, char *port, char *busid, int rhport) int ret; ret = mkdir(VHCI_STATE_PATH, 0700); - if (ret < 0) - return -1; + if (ret < 0) { + /* if VHCI_STATE_PATH exists, then it better be a directory */ + if (errno == EEXIST) { + struct stat s; + ret = stat(VHCI_STATE_PATH, &s); + if (ret < 0) + return -1; + if (!(s.st_mode & S_IFDIR)) + return -1; + } else + return -1; + } snprintf(path, PATH_MAX, VHCI_STATE_PATH"/port%d", rhport);