libxl: libxl_pvusb.c: Remove redundant lstat
authorChunyan Liu <cyliu@suse.com>
Thu, 7 Apr 2016 09:40:27 +0000 (17:40 +0800)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 7 Apr 2016 16:48:59 +0000 (17:48 +0100)
There is no harm in calling realpath, and we can handle ENOENT then.

CID: 1358112

Signed-off-by: Chunyan Liu <cyliu@suse.com>
CC: Simon Cao <caobosimon@gmail.com>
CC: George Dunlap <george.dunlap@citrix.com>
Acked-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
tools/libxl/libxl_pvusb.c

index d983a5c333d70b0360cb564cf0b3ec2210110987..f0de36c572c7ea78c0ca5f2985bea0763b1db929 100644 (file)
@@ -1043,25 +1043,14 @@ static char *usbdev_busid_from_ctrlport(libxl__gc *gc, uint32_t domid,
 static int usbintf_get_drvpath(libxl__gc *gc, const char *intf, char **drvpath)
 {
     char *spath, *dp = NULL;
-    struct stat st;
-    int r;
 
     spath = GCSPRINTF(SYSFS_USB_DEV "/%s/driver", intf);
 
-    r = lstat(spath, &st);
-    if (r == 0) {
-        /* Find the canonical path to the driver. */
-        dp = libxl__zalloc(gc, PATH_MAX);
-        dp = realpath(spath, dp);
-        if (!dp) {
-            LOGE(ERROR, "get realpath failed: '%s'", spath);
-            return ERROR_FAIL;
-        }
-    } else if (errno == ENOENT) {
-        /* driver path doesn't exist */
-        dp = NULL;
-    } else {
-        LOGE(ERROR, "lstat failed: '%s'", spath);
+    /* Find the canonical path to the driver. */
+    dp = libxl__zalloc(gc, PATH_MAX);
+    dp = realpath(spath, dp);
+    if (!dp && errno != ENOENT) {
+        LOGE(ERROR, "get realpath failed: '%s'", spath);
         return ERROR_FAIL;
     }