summaryrefslogtreecommitdiff
path: root/mdstat.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 /mdstat.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 'mdstat.c')
-rw-r--r--mdstat.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/mdstat.c b/mdstat.c
index 0dece0aa..5f690e5d 100644
--- a/mdstat.c
+++ b/mdstat.c
@@ -103,7 +103,7 @@ static int add_member_devname(struct dev_member **m, char *name)
/* not a device */
return 0;
- new = malloc(sizeof(*new));
+ new = xmalloc(sizeof(*new));
new->name = strndup(name, t - name);
new->next = *m;
*m = new;
@@ -177,12 +177,7 @@ struct mdstat_ent *mdstat_read(int hold, int start)
continue;
}
- ent = malloc(sizeof(*ent));
- if (!ent) {
- pr_err("malloc failed reading /proc/mdstat.\n");
- free_line(line);
- break;
- }
+ ent = xmalloc(sizeof(*ent));
ent->dev = ent->level = ent->pattern= NULL;
ent->next = NULL;
ent->percent = RESYNC_NONE;
@@ -193,7 +188,7 @@ struct mdstat_ent *mdstat_read(int hold, int start)
ent->devcnt = 0;
ent->members = NULL;
- ent->dev = strdup(line);
+ ent->dev = xstrdup(line);
ent->devnum = devnum;
for (w=dl_next(line); w!= line ; w=dl_next(w)) {
@@ -207,7 +202,7 @@ struct mdstat_ent *mdstat_read(int hold, int start)
} else if (ent->active > 0 &&
ent->level == NULL &&
w[0] != '(' /*readonly*/) {
- ent->level = strdup(w);
+ ent->level = xstrdup(w);
in_devs = 1;
} else if (in_devs && strcmp(w, "blocks")==0)
in_devs = 0;
@@ -231,13 +226,13 @@ struct mdstat_ent *mdstat_read(int hold, int start)
} else if (strcmp(w, "super") == 0 &&
dl_next(w) != line) {
w = dl_next(w);
- ent->metadata_version = strdup(w);
+ ent->metadata_version = xstrdup(w);
} else if (w[0] == '[' && isdigit(w[1])) {
ent->raid_disks = atoi(w+1);
} else if (!ent->pattern &&
w[0] == '[' &&
(w[1] == 'U' || w[1] == '_')) {
- ent->pattern = strdup(w+1);
+ ent->pattern = xstrdup(w+1);
if (ent->pattern[l-2]==']')
ent->pattern[l-2] = '\0';
} else if (ent->percent == RESYNC_NONE &&