From: Karel Zak Date: Fri, 7 Sep 2012 10:15:39 +0000 (+0200) Subject: lib/sysfs: more robust sysfs_opendir() [coverity scan] X-Git-Tag: v2.23-rc1~714 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fee9431f972c8cb6ef70350f12f76d6f352312d2;p=thirdparty%2Futil-linux.git lib/sysfs: more robust sysfs_opendir() [coverity scan] Signed-off-by: Karel Zak --- diff --git a/lib/sysfs.c b/lib/sysfs.c index 7b2c5f7b14..d1eccb585c 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -233,11 +233,12 @@ ssize_t sysfs_readlink(struct sysfs_cxt *cxt, const char *attr, DIR *sysfs_opendir(struct sysfs_cxt *cxt, const char *attr) { DIR *dir; - int fd; + int fd = -1; if (attr) fd = sysfs_open(cxt, attr); - else + + else if (cxt->dir_fd >= 0) /* request to open root of device in sysfs (/sys/block/) * -- we cannot use cxt->sysfs_fd directly, because closedir() * will close this our persistent file descriptor.