diff options
author | Jes Sorensen <Jes.Sorensen@gmail.com> | 2017-03-30 22:52:37 +0200 |
---|---|---|
committer | Jes Sorensen <Jes.Sorensen@gmail.com> | 2017-03-30 22:52:37 +0200 |
commit | dae131379f9fd82e2867aed25a3ff719f957e9a3 (patch) | |
tree | f337efe8338f6c9cb58086b274cf7ae32a3cd64c /sysfs.c | |
parent | sysfs: Use the presence of /sys/block/<dev>/md as indicator of valid device (diff) | |
download | mdadm-dae131379f9fd82e2867aed25a3ff719f957e9a3.tar.xz mdadm-dae131379f9fd82e2867aed25a3ff719f957e9a3.zip |
sysfs: Make sysfs_init() return an error code
Rather than have the caller inspect the returned content, return an
error code from sysfs_init(). In addition make all callers actually
check it.
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
Diffstat (limited to 'sysfs.c')
-rw-r--r-- | sysfs.c | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -84,25 +84,30 @@ void sysfs_init_dev(struct mdinfo *mdi, unsigned long devid) sizeof(mdi->sys_name), "dev-%s", devid2kname(devid)); } -void sysfs_init(struct mdinfo *mdi, int fd, char *devnm) +int sysfs_init(struct mdinfo *mdi, int fd, char *devnm) { struct stat stb; char fname[MAX_SYSFS_PATH_LEN]; + int retval = -ENODEV; mdi->sys_name[0] = 0; if (fd >= 0) devnm = fd2devnm(fd); if (devnm == NULL) - return; + goto out; snprintf(fname, MAX_SYSFS_PATH_LEN, "/sys/block/%s/md", devnm); if (stat(fname, &stb)) - return; + goto out; if (!S_ISDIR(stb.st_mode)) - return; + goto out; strcpy(mdi->sys_name, devnm); + + retval = 0; +out: + return retval; } struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options) @@ -117,8 +122,7 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options) struct dirent *de; sra = xcalloc(1, sizeof(*sra)); - sysfs_init(sra, fd, devnm); - if (sra->sys_name[0] == 0) { + if (sysfs_init(sra, fd, devnm)) { free(sra); return NULL; } |