summaryrefslogtreecommitdiff
path: root/raid6check.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 /raid6check.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 'raid6check.c')
-rw-r--r--raid6check.c40
1 files changed, 10 insertions, 30 deletions
diff --git a/raid6check.c b/raid6check.c
index 1d91c96a..be7a449e 100644
--- a/raid6check.c
+++ b/raid6check.c
@@ -106,12 +106,12 @@ int check_stripes(struct mdinfo *info, int *source, unsigned long long *offsets,
unsigned long long start, unsigned long long length, char *name[])
{
/* read the data and p and q blocks, and check we got them right */
- char *stripe_buf = malloc(raid_disks * chunk_size);
- char **stripes = malloc(raid_disks * sizeof(char*));
- char **blocks = malloc(raid_disks * sizeof(char*));
- uint8_t *p = malloc(chunk_size);
- uint8_t *q = malloc(chunk_size);
- int *results = malloc(chunk_size * sizeof(int));
+ char *stripe_buf = xmalloc(raid_disks * chunk_size);
+ char **stripes = xmalloc(raid_disks * sizeof(char*));
+ char **blocks = xmalloc(raid_disks * sizeof(char*));
+ uint8_t *p = xmalloc(chunk_size);
+ uint8_t *q = xmalloc(chunk_size);
+ int *results = xmalloc(chunk_size * sizeof(int));
int i;
int diskP, diskQ;
@@ -122,16 +122,6 @@ int check_stripes(struct mdinfo *info, int *source, unsigned long long *offsets,
extern int tables_ready;
- if((stripe_buf == NULL) ||
- (stripes == NULL) ||
- (blocks == NULL) ||
- (p == NULL) ||
- (q == NULL) ||
- (results == NULL)) {
- err = 1;
- goto exitCheck;
- }
-
if (!tables_ready)
make_tables();
@@ -340,21 +330,11 @@ int main(int argc, char *argv[])
length = (info->component_size * 512) / chunk_size - start;
}
- disk_name = malloc(raid_disks * sizeof(*disk_name));
- fds = malloc(raid_disks * sizeof(*fds));
- offsets = malloc(raid_disks * sizeof(*offsets));
- buf = malloc(raid_disks * chunk_size);
-
- if((disk_name == NULL) ||
- (fds == NULL) ||
- (offsets == NULL) ||
- (buf == NULL)) {
- fprintf(stderr, "%s: allocation fail\n", prg);
- exit_err = 5;
- goto exitHere;
- }
+ disk_name = xmalloc(raid_disks * sizeof(*disk_name));
+ fds = xmalloc(raid_disks * sizeof(*fds));
+ offsets = xcalloc(raid_disks, sizeof(*offsets));
+ buf = xmalloc(raid_disks * chunk_size);
- memset(offsets, 0, raid_disks * sizeof(*offsets));
for(i=0; i<raid_disks; i++) {
fds[i] = -1;
}