summaryrefslogtreecommitdiff
path: root/Assemble.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2012-07-09 17:14:16 +1000
committerNeilBrown <neilb@suse.de>2012-07-09 17:14:16 +1000
commit503975b9d5f0696b5d2ee20ea903b859e3f60662 (patch)
tree171c9f9b9db109325fad7f81ba07671d84a085a5 /Assemble.c
parentc8e1a230b73c44aff5beeeb74d32e36219bed12d (diff)
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 'Assemble.c')
-rw-r--r--Assemble.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/Assemble.c b/Assemble.c
index f06fb5c1..c0ed917d 100644
--- a/Assemble.c
+++ b/Assemble.c
@@ -727,8 +727,8 @@ int Assemble(struct supertype *st, char *mddev,
bitmap_done = 0;
#endif
/* Ok, no bad inconsistancy, we can try updating etc */
- devices = malloc(num_devs * sizeof(*devices));
- devmap = calloc(num_devs * content->array.raid_disks, 1);
+ devices = xcalloc(num_devs, sizeof(*devices));
+ devmap = xcalloc(num_devs, content->array.raid_disks);
for (tmpdev = devlist; tmpdev; tmpdev=tmpdev->next) if (tmpdev->used == 1) {
char *devname = tmpdev->devname;
struct stat stb;
@@ -866,7 +866,7 @@ int Assemble(struct supertype *st, char *mddev,
if (i < 10000) {
if (i >= bestcnt) {
int newbestcnt = i+10;
- int *newbest = malloc(sizeof(int)*newbestcnt);
+ int *newbest = xmalloc(sizeof(int)*newbestcnt);
int c;
for (c=0; c < newbestcnt; c++)
if (c < bestcnt)
@@ -931,8 +931,7 @@ int Assemble(struct supertype *st, char *mddev,
/* now we have some devices that might be suitable.
* I wonder how many
*/
- avail = malloc(content->array.raid_disks);
- memset(avail, 0, content->array.raid_disks);
+ avail = xcalloc(content->array.raid_disks, 1);
okcnt = 0;
sparecnt=0;
rebuilding_cnt=0;
@@ -1199,7 +1198,7 @@ int Assemble(struct supertype *st, char *mddev,
#ifndef MDASSEMBLE
if (content->reshape_active) {
int err = 0;
- int *fdlist = malloc(sizeof(int)* bestcnt);
+ int *fdlist = xmalloc(sizeof(int)* bestcnt);
if (verbose > 0)
pr_err(":%s has an active reshape - checking "
"if critical section needs to be restored\n",