]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
non-trivial warn_unused_result fixes, activate_spare
authorDan Williams <dan.j.williams@intel.com>
Sun, 28 Sep 2008 19:12:08 +0000 (12:12 -0700)
committerDan Williams <dan.j.williams@intel.com>
Wed, 15 Oct 2008 21:15:52 +0000 (14:15 -0700)
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 <dan.j.williams@intel.com>
super-ddf.c
super-intel.c

index 81f8b013ff4040a8e950073be5325de31d11bdeb..527e32635da56fe61f60fb2e3cab08f11fe3c8a8 100644 (file)
@@ -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);
index df3184aae000fba5620b40f582505208e8e949ee..2ce398359ebd459879c0ea6decf1ce95cf1209e4 100644 (file)
@@ -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;