From fee9431f972c8cb6ef70350f12f76d6f352312d2 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 7 Sep 2012 12:15:39 +0200 Subject: [PATCH] lib/sysfs: more robust sysfs_opendir() [coverity scan] Signed-off-by: Karel Zak --- lib/sysfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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. -- 2.47.3