summaryrefslogtreecommitdiff
path: root/Grow.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 /Grow.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 'Grow.c')
-rw-r--r--Grow.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/Grow.c b/Grow.c
index 50effc7f..8aa0a139 100644
--- a/Grow.c
+++ b/Grow.c
@@ -49,11 +49,8 @@ int restore_backup(struct supertype *st,
int disk_count = next_spare + working_disks;
dprintf("Called restore_backup()\n");
- fdlist = malloc(sizeof(int) * disk_count);
- if (fdlist == NULL) {
- pr_err("cannot allocate memory for disk list\n");
- return 1;
- }
+ fdlist = xmalloc(sizeof(int) * disk_count);
+
for (i = 0; i < next_spare; i++)
fdlist[i] = -1;
for (dev = content->devs; dev; dev = dev->next) {
@@ -2401,12 +2398,8 @@ started:
nrdisks = max(reshape.before.data_disks,
reshape.after.data_disks) + reshape.parity
+ sra->array.spare_disks;
- fdlist = malloc((1+nrdisks) * sizeof(int));
- offsets = malloc((1+nrdisks) * sizeof(offsets[0]));
- if (!fdlist || !offsets) {
- pr_err("malloc failed: grow aborted\n");
- goto release;
- }
+ fdlist = xcalloc((1+nrdisks), sizeof(int));
+ offsets = xcalloc((1+nrdisks), sizeof(offsets[0]));
odisks = reshape.before.data_disks + reshape.parity;
d = reshape_prepare_fdlist(devname, sra, odisks,
@@ -3415,8 +3408,8 @@ static void validate(int afd, int bfd, unsigned long long offset)
free(abuf);
free(bbuf);
abuflen = len;
- abuf = malloc(abuflen);
- bbuf = malloc(abuflen);
+ abuf = xmalloc(abuflen);
+ bbuf = xmalloc(abuflen);
}
lseek64(bfd, offset+__le64_to_cpu(bsb2.devstart2)*512, 0);
@@ -3804,7 +3797,7 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt
goto second_fail; /* Cannot find leading superblock */
/* Now need the data offsets for all devices. */
- offsets = malloc(sizeof(*offsets)*info->array.raid_disks);
+ offsets = xmalloc(sizeof(*offsets)*info->array.raid_disks);
for(j=0; j<info->array.raid_disks; j++) {
if (fdlist[j] < 0)
continue;