From: Karel Zak Date: Mon, 30 May 2011 20:59:35 +0000 (+0200) Subject: libblkid: use sysfs_init() more carefully X-Git-Tag: v2.20-rc1~221 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5206c819452656e68b0aafd514d0cbc90c4c2fd;p=thirdparty%2Futil-linux.git libblkid: use sysfs_init() more carefully Reported-by: Francesco Cosoleto Signed-off-by: Karel Zak --- diff --git a/shlibs/blkid/src/devname.c b/shlibs/blkid/src/devname.c index 2ed85cdbde..e1fc2c8499 100644 --- a/shlibs/blkid/src/devname.c +++ b/shlibs/blkid/src/devname.c @@ -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); diff --git a/shlibs/blkid/src/devno.c b/shlibs/blkid/src/devno.c index dffafef8ca..9a356a84f5 100644 --- a/shlibs/blkid/src/devno.c +++ b/shlibs/blkid/src/devno.c @@ -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) { diff --git a/shlibs/blkid/src/topology/sysfs.c b/shlibs/blkid/src/topology/sysfs.c index fccd58f4d5..588fc7a133 100644 --- a/shlibs/blkid/src/topology/sysfs.c +++ b/shlibs/blkid/src/topology/sysfs.c @@ -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)