]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super-ddf.c
Always initialise a struct super_type to zero
[thirdparty/mdadm.git] / super-ddf.c
index e98e4110e2dc78143244b34af865a36ebade1cd2..0c2a0138c5b9b480ce84c9beda400cb2e7a8628a 100644 (file)
@@ -820,6 +820,7 @@ static struct supertype *match_metadata_desc_ddf(char *arg)
                return NULL;
 
        st = malloc(sizeof(*st));
+       memset(st, 0, sizeof(*st));
        st->ss = &super_ddf;
        st->max_devs = 512;
        st->minor_version = 0;
@@ -837,6 +838,7 @@ static struct supertype *match_metadata_desc_ddf_bvd(char *arg)
                return NULL;
 
        st = malloc(sizeof(*st));
+       memset(st, 0, sizeof(*st));
        st->ss = &super_ddf_bvd;
        st->max_devs = 512;
        st->minor_version = 0;
@@ -853,6 +855,7 @@ static struct supertype *match_metadata_desc_ddf_svd(char *arg)
                return NULL;
 
        st = malloc(sizeof(*st));
+       memset(st, 0, sizeof(*st));
        st->ss = &super_ddf_svd;
        st->max_devs = 512;
        st->minor_version = 0;
@@ -1561,8 +1564,8 @@ static int init_super_ddf(struct supertype *st,
         * Remaining 16 are serial number.... maybe a hostname would do?
         */
        memcpy(ddf->controller.guid, T10, sizeof(T10));
-       gethostname(hostname, 17);
-       hostname[17] = 0;
+       gethostname(hostname, sizeof(hostname));
+       hostname[sizeof(hostname) - 1] = 0;
        hostlen = strlen(hostname);
        memcpy(ddf->controller.guid + 24 - hostlen, hostname, hostlen);
        for (i = strlen(T10) ; i+hostlen < 24; i++)
@@ -2147,9 +2150,9 @@ int validate_geometry_ddf(struct supertype *st,
                                                         dev, freesize);
                }
                close(cfd);
-       }
-       fprintf(stderr, Name ": Cannot use %s: Already in use\n",
-               dev);
+       } else /* device may belong to a different container */
+               return 0;
+
        return 1;
 }
 
@@ -2178,7 +2181,7 @@ int validate_geometry_ddf_container(struct supertype *st,
        }
        close(fd);
 
-       *freesize = avail_size_ddf(st, ldsize);
+       *freesize = avail_size_ddf(st, ldsize >> 9);
 
        return 1;
 }
@@ -3045,8 +3048,8 @@ static struct mdinfo *ddf_activate_spare(struct active_array *a,
         * Create a metadata_update record to update the
         * phys_refnum and lba_offset values
         */
-       mu = malloc(sizeof(*mu) + ddf->conf_rec_len * 512);
-       mu->buf = (char*)(mu+1);
+       mu = malloc(sizeof(*mu));
+       mu->buf = malloc(ddf->conf_rec_len * 512);
        mu->space = malloc(sizeof(struct vcl));
        mu->len = ddf->conf_rec_len;
        mu->next = *updates;