From 792449393d1792e1bdb45aedada395f345564484 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Sun, 28 Sep 2008 12:12:08 -0700 Subject: [PATCH] non-trivial warn_unused_result fixes, activate_spare Both super-ddf and super-intel ignore memory allocation failures during ->activate_spare. Fix these up by cancelling the activation. Signed-off-by: Dan Williams --- super-ddf.c | 17 ++++++++++++++++- super-intel.c | 20 +++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/super-ddf.c b/super-ddf.c index 81f8b013..527e3263 100644 --- a/super-ddf.c +++ b/super-ddf.c @@ -3287,6 +3287,8 @@ static struct mdinfo *ddf_activate_spare(struct active_array *a, /* Cool, we have a device with some space at pos */ di = malloc(sizeof(*di)); + if (!di) + continue; memset(di, 0, sizeof(*di)); di->disk.number = i; di->disk.raid_disk = i; @@ -3319,8 +3321,21 @@ static struct mdinfo *ddf_activate_spare(struct active_array *a, * phys_refnum and lba_offset values */ mu = malloc(sizeof(*mu)); + if (mu && posix_memalign(&mu->space, 512, sizeof(struct vcl)) != 0) { + free(mu); + mu = NULL; + } + if (!mu) { + while (rv) { + struct mdinfo *n = rv->next; + + free(rv); + rv = n; + } + return NULL; + } + mu->buf = malloc(ddf->conf_rec_len * 512); - posix_memalign(&mu->space, 512, sizeof(struct vcl)); mu->len = ddf->conf_rec_len; mu->next = *updates; vc = find_vdcr(ddf, a->info.container_member); diff --git a/super-intel.c b/super-intel.c index df3184aa..2ce39835 100644 --- a/super-intel.c +++ b/super-intel.c @@ -2884,6 +2884,8 @@ static struct mdinfo *imsm_activate_spare(struct active_array *a, /* found a usable disk with enough space */ di = malloc(sizeof(*di)); + if (!di) + continue; memset(di, 0, sizeof(*di)); /* dl->index will be -1 in the case we are activating a @@ -2923,7 +2925,23 @@ static struct mdinfo *imsm_activate_spare(struct active_array *a, * disk_ord_tbl for the array */ mu = malloc(sizeof(*mu)); - mu->buf = malloc(sizeof(struct imsm_update_activate_spare) * num_spares); + if (mu) { + mu->buf = malloc(sizeof(struct imsm_update_activate_spare) * num_spares); + if (mu->buf == NULL) { + free(mu); + mu = NULL; + } + } + if (!mu) { + while (rv) { + struct mdinfo *n = rv->next; + + free(rv); + rv = n; + } + return NULL; + } + mu->space = NULL; mu->len = sizeof(struct imsm_update_activate_spare) * num_spares; mu->next = *updates; -- 2.47.2