]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: use sysfs_init() more carefully
authorKarel Zak <kzak@redhat.com>
Mon, 30 May 2011 20:59:35 +0000 (22:59 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 30 May 2011 20:59:35 +0000 (22:59 +0200)
Reported-by: Francesco Cosoleto <cosoleto@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/src/devname.c
shlibs/blkid/src/devno.c
shlibs/blkid/src/topology/sysfs.c

index 2ed85cdbded595b76ed560554db7c70df273c701..e1fc2c84995caf1bb6afab3b27fd4d43c3b48b57 100644 (file)
@@ -571,9 +571,10 @@ static int probe_all_removable(blkid_cache cache)
                if (!devno)
                        continue;
 
-               sysfs_init(&sysfs, devno, NULL);
-               sysfs_read_int(&sysfs, "removable", &removable);
-               sysfs_deinit(&sysfs);
+               if (sysfs_init(&sysfs, devno, NULL) == 0) {
+                       sysfs_read_int(&sysfs, "removable", &removable);
+                       sysfs_deinit(&sysfs);
+               }
 
                if (removable)
                        probe_one(cache, d->d_name, devno, 0, 0, 1);
index dffafef8ca466b675824d4483fdbebc09dd67e66..9a356a84f5df795511ace785834e02fa016e4daa 100644 (file)
@@ -349,10 +349,8 @@ int blkid_devno_to_wholedisk(dev_t dev, char *diskname,
        struct sysfs_cxt cxt;
        int is_part = 0;
 
-       if (!dev)
-               goto err;
-       if (sysfs_init(&cxt, dev, NULL))
-               goto err;
+       if (!dev || sysfs_init(&cxt, dev, NULL) != 0)
+               return -1;
 
        is_part = sysfs_has_attribute(&cxt, "partition");
        if (!is_part) {
index fccd58f4d584600ca3fab35a4f123c4b294adeb0..588fc7a1330ef17c85c00e923d3839d690c6e3a7 100644 (file)
@@ -42,16 +42,14 @@ static struct topology_val {
 static int probe_sysfs_tp(blkid_probe pr, const struct blkid_idmag *mag)
 {
        dev_t dev, disk = 0;
-       int i, count = 0;
+       int i, count = 0, rc;
        struct sysfs_cxt sysfs, parent;
 
-       int rc = 1;             /* nothing (default) */
-
        dev = blkid_probe_get_devno(pr);
-       if (!dev)
-               goto done;                      /* probably not a block device */
-       if (sysfs_init(&sysfs, dev, NULL))
-               goto done;                      /* no entry in /sys ? */
+       if (!dev || sysfs_init(&sysfs, dev, NULL) != 0)
+               return 1;
+
+       rc = 1;         /* nothing (default) */
 
        for (i = 0; i < ARRAY_SIZE(topology_vals); i++) {
                struct topology_val *val = &topology_vals[i];
@@ -67,10 +65,12 @@ static int probe_sysfs_tp(blkid_probe pr, const struct blkid_idmag *mag)
                                 */
                                disk = blkid_probe_get_wholedisk_devno(pr);
                                if (disk && disk != dev) {
-                                       sysfs_init(&parent, disk, NULL);
-                                       sysfs.parent = &parent;
+                                       if (sysfs_init(&parent, disk, NULL) != 0)
+                                               goto done;
 
-                                       ok = sysfs_has_attribute(&sysfs, val->attr);
+                                       sysfs.parent = &parent;
+                                       ok = sysfs_has_attribute(&sysfs,
+                                                                val->attr);
                                }
                        }
                        if (!ok)