summaryrefslogtreecommitdiffstats
path: root/lib/sysfs.c
diff options
context:
space:
mode:
authorKarel Zak2012-09-07 12:15:39 +0200
committerKarel Zak2012-09-07 12:15:39 +0200
commitfee9431f972c8cb6ef70350f12f76d6f352312d2 (patch)
tree82a2ab04b3972cfdd62ba33875d16043007cdeb4 /lib/sysfs.c
parentmark expected fallthrough for static analysers (diff)
downloadkernel-qcow2-util-linux-fee9431f972c8cb6ef70350f12f76d6f352312d2.tar.gz
kernel-qcow2-util-linux-fee9431f972c8cb6ef70350f12f76d6f352312d2.tar.xz
kernel-qcow2-util-linux-fee9431f972c8cb6ef70350f12f76d6f352312d2.zip
lib/sysfs: more robust sysfs_opendir() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/sysfs.c')
-rw-r--r--lib/sysfs.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/sysfs.c b/lib/sysfs.c
index 7b2c5f7b1..d1eccb585 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/<dev>)
* -- we cannot use cxt->sysfs_fd directly, because closedir()
* will close this our persistent file descriptor.