]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Abort sysfs_read early if no device found.
authorNeilBrown <neilb@suse.de>
Tue, 4 Nov 2008 09:56:11 +0000 (20:56 +1100)
committerNeilBrown <neilb@suse.de>
Tue, 4 Nov 2008 09:56:11 +0000 (20:56 +1100)
sysfs_read currently tried to look in sysfs even in no valid sys_name
was found.  Don't to that.

Signed-off-by: NeilBrown <neilb@suse.de>
sysfs.c

diff --git a/sysfs.c b/sysfs.c
index 7f94d5567d95ce2ae036a8595f3104d5b3eb867c..b9fd3da95d37a80bb303583cf4bf0eb78ebf34e2 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -81,6 +81,7 @@ int sysfs_open(int devnum, char *devname, char *attr)
 
 void sysfs_init(struct mdinfo *mdi, int fd, int devnum)
 {
+       mdi->sys_name[0] = 0;
        if (fd >= 0) {
                mdu_version_t vers;
                if (ioctl(fd, RAID_VERSION, &vers) != 0)
@@ -118,6 +119,10 @@ struct mdinfo *sysfs_read(int fd, int devnum, unsigned long options)
                return sra;
        memset(sra, 0, sizeof(*sra));
        sysfs_init(sra, fd, devnum);
+       if (sra->sys_name[0] == 0) {
+               free(sra);
+               return NULL;
+       }
 
        sprintf(fname, "/sys/block/%s/md/", sra->sys_name);
        base = fname + strlen(fname);