diff options
author | NeilBrown <neilb@suse.de> | 2012-07-09 09:14:16 +0200 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2012-07-09 09:14:16 +0200 |
commit | 503975b9d5f0696b5d2ee20ea903b859e3f60662 (patch) | |
tree | 171c9f9b9db109325fad7f81ba07671d84a085a5 /sysfs.c | |
parent | Remove re_add flag in favour of new disposition. (diff) | |
download | mdadm-503975b9d5f0696b5d2ee20ea903b859e3f60662.tar.xz mdadm-503975b9d5f0696b5d2ee20ea903b859e3f60662.zip |
Remove scattered checks for malloc success.
malloc should never fail, and if it does it is unlikely
that anything else useful can be done. Best approach is to
abort and let some super-daemon restart.
So define xmalloc, xcalloc, xrealloc, xstrdup which don't
fail but just print a message and exit. Then use those
removing all the tests for failure.
Also replace all "malloc;memset" sequences with 'xcalloc'.
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'sysfs.c')
-rw-r--r-- | sysfs.c | 9 |
1 files changed, 2 insertions, 7 deletions
@@ -105,10 +105,7 @@ struct mdinfo *sysfs_read(int fd, int devnum, unsigned long options) DIR *dir = NULL; struct dirent *de; - sra = malloc(sizeof(*sra)); - if (sra == NULL) - return sra; - memset(sra, 0, sizeof(*sra)); + sra = xcalloc(1, sizeof(*sra)); sysfs_init(sra, fd, devnum); if (sra->sys_name[0] == 0) { free(sra); @@ -250,9 +247,7 @@ struct mdinfo *sysfs_read(int fd, int devnum, unsigned long options) dbase = base + strlen(base); *dbase++ = '/'; - dev = malloc(sizeof(*dev)); - if (!dev) - goto abort; + dev = xmalloc(sizeof(*dev)); /* Always get slot, major, minor */ strcpy(dbase, "slot"); |