]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: fix sysfs context usage
authorKarel Zak <kzak@redhat.com>
Tue, 6 Mar 2012 10:24:54 +0000 (11:24 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 6 Mar 2012 10:24:54 +0000 (11:24 +0100)
Reported-by: Elan Ruusamäe <glen@delfi.ee>
Signed-off-by: Karel Zak <kzak@redhat.com>
include/sysfs.h
lib/sysfs.c
libblkid/src/devname.c
libblkid/src/devno.c
libblkid/src/topology/sysfs.c

index c1e63527b5bd58c1b5aac56d791723d893cb7fdc..affd2bb7655f153b62f3c432fed50b6094aa9c41 100644 (file)
@@ -23,6 +23,7 @@ struct sysfs_cxt {
        struct sysfs_cxt *parent;
 };
 
+#define UL_SYSFSCXT_EMPTY { 0, -1, NULL, NULL }
 
 extern char *sysfs_devno_attribute_path(dev_t devno, char *buf,
                                  size_t bufsiz, const char *attr);
index 89600bfddd780e70b7ae5fa290c831015f7b220c..2340d3046df1a5a68105775956f059d90cc0d21b 100644 (file)
@@ -137,7 +137,7 @@ char *sysfs_devno_to_devpath(dev_t devno, char *buf, size_t bufsiz)
 int sysfs_init(struct sysfs_cxt *cxt, dev_t devno, struct sysfs_cxt *parent)
 {
        char path[PATH_MAX];
-       int fd, rc = 0;
+       int fd, rc;
 
        memset(cxt, 0, sizeof(*cxt));
        cxt->dir_fd = -1;
@@ -157,7 +157,7 @@ int sysfs_init(struct sysfs_cxt *cxt, dev_t devno, struct sysfs_cxt *parent)
        cxt->parent = parent;
        return 0;
 err:
-       rc = -errno;
+       rc = errno > 0 ? -errno : -1;
        sysfs_deinit(cxt);
        return rc;
 }
@@ -445,7 +445,7 @@ char *sysfs_get_devname(struct sysfs_cxt *cxt, char *buf, size_t bufsiz)
 
 int main(int argc, char *argv[])
 {
-       struct sysfs_cxt cxt;
+       struct sysfs_cxt cxt = UL_SYSFSCXT_EMPTY;
        char *devname;
        dev_t devno;
        char path[PATH_MAX];
index 12cd93ad33001acbb1df1979696355417dac920d..4a08452d8c94c93a71efa7b397e67de2031a79fd 100644 (file)
@@ -550,7 +550,7 @@ static int probe_all_removable(blkid_cache cache)
                return -BLKID_ERR_PROC;
 
        while((d = readdir(dir))) {
-               struct sysfs_cxt sysfs;
+               struct sysfs_cxt sysfs = UL_SYSFSCXT_EMPTY;
                int removable = 0;
                dev_t devno;
 
index b2a8be537c4da2379faf4e2abb39b0baae022379..59edfd85cefdc82bd3b79437c775f284559c6d48 100644 (file)
@@ -346,7 +346,7 @@ static int get_dm_wholedisk(struct sysfs_cxt *cxt, char *diskname,
 int blkid_devno_to_wholedisk(dev_t dev, char *diskname,
                        size_t len, dev_t *diskdevno)
 {
-       struct sysfs_cxt cxt;
+       struct sysfs_cxt cxt = UL_SYSFSCXT_EMPTY;
        int is_part = 0;
 
        if (!dev || sysfs_init(&cxt, dev, NULL) != 0)
index e62b84c27a9635c56ce6c26e3e9909d595e4758e..a04b20a374f9895d403321bb070ee7a6199c4c2e 100644 (file)
@@ -44,7 +44,8 @@ static int probe_sysfs_tp(blkid_probe pr,
 {
        dev_t dev, disk = 0;
        int rc;
-       struct sysfs_cxt sysfs, parent;
+       struct sysfs_cxt sysfs = UL_SYSFSCXT_EMPTY,
+                        parent = UL_SYSFSCXT_EMPTY;
        size_t i, count = 0;
 
        dev = blkid_probe_get_devno(pr);
@@ -76,7 +77,7 @@ static int probe_sysfs_tp(blkid_probe pr,
                                }
                        }
                        if (!ok)
-                               continue;       /* attrinute does not exist */
+                               continue;       /* attribute does not exist */
                }
 
                if (val->set_ulong) {
@@ -102,8 +103,8 @@ static int probe_sysfs_tp(blkid_probe pr,
 
 done:
        sysfs_deinit(&sysfs);
-       if (disk)
-               sysfs_deinit(&parent);
+       sysfs_deinit(&parent);
+
        if (count)
                return 0;               /* success */
        return rc;                      /* error or nothing */