From 95eeceeb32775bffd06771c81c3dee547af0d62f Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 8 Jun 2011 15:54:13 +1000 Subject: [PATCH] getinfo_super now clears the 'info' structure before filling it in. Some code currently clears 'info' before calling getinfo_super, some code doesn't. To be consistent, change it so no caller ever clears 'info', but ever getinfo_super function must clear it. Note that ->raid_disk may be meaningful if that 'map' is passed non-NULL. In that case it is copied out before the structure is zeroed. Signed-off-by: NeilBrown --- Assemble.c | 2 -- Create.c | 2 +- Incremental.c | 3 --- mdadm.h | 1 + super-ddf.c | 2 ++ super-intel.c | 2 ++ super0.c | 1 + super1.c | 1 + 8 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Assemble.c b/Assemble.c index 8b05829d..250a6e0e 100644 --- a/Assemble.c +++ b/Assemble.c @@ -418,7 +418,6 @@ int Assemble(struct supertype *st, char *mddev, int uuid[4]; content = &info; - memset(content, 0, sizeof(*content)); tst->ss->getinfo_super(tst, content, NULL); if (!parse_uuid(ident->container, uuid) || @@ -484,7 +483,6 @@ int Assemble(struct supertype *st, char *mddev, } else { content = &info; - memset(content, 0, sizeof(*content)); tst->ss->getinfo_super(tst, content, NULL); if (!ident_matches(ident, content, tst, diff --git a/Create.c b/Create.c index 1aeff77b..7b4d0fec 100644 --- a/Create.c +++ b/Create.c @@ -658,8 +658,8 @@ int Create(struct supertype *st, char *mddev, goto abort; total_slots = info.array.nr_disks; - sysfs_init(&info, mdfd, 0); st->ss->getinfo_super(st, &info, NULL); + sysfs_init(&info, mdfd, 0); if (did_default && verbose >= 0) { if (is_subarray(info.text_version)) { diff --git a/Incremental.c b/Incremental.c index 14184da0..f576cbae 100644 --- a/Incremental.c +++ b/Incremental.c @@ -202,7 +202,6 @@ int Incremental(char *devname, int verbose, int runstop, } close (dfd); dfd = -1; - memset(&info, 0, sizeof(info)); st->ss->getinfo_super(st, &info, NULL); /* 3/ Check if there is a match in mdadm.conf */ @@ -396,7 +395,6 @@ int Incremental(char *devname, int verbose, int runstop, goto out; } close(dfd2); - memset(&info2, 0, sizeof(info2)); st2->ss->getinfo_super(st2, &info2, NULL); st2->ss->free_super(st2); if (info.array.level != info2.array.level || @@ -1435,7 +1433,6 @@ static int Incremental_container(struct supertype *st, char *devname, int suuid[4]; int sfd; - memset(&info, 0, sizeof(info)); st->ss->getinfo_super(st, &info, NULL); if ((runstop > 0 && info.container_enough >= 0) || diff --git a/mdadm.h b/mdadm.h index 9437d04e..8bde0de5 100644 --- a/mdadm.h +++ b/mdadm.h @@ -616,6 +616,7 @@ extern struct superswitch { * (raid_disk must already be set and correct) and it is filled * with 1 for slots that are thought to be active and 0 for slots which * appear to be failed/missing. + * *info is zeroed out before data is added. */ void (*getinfo_super)(struct supertype *st, struct mdinfo *info, char *map); struct mdinfo *(*getinfo_super_disks)(struct supertype *st); diff --git a/super-ddf.c b/super-ddf.c index 8f88b708..21a917e4 100644 --- a/super-ddf.c +++ b/super-ddf.c @@ -1341,6 +1341,7 @@ static void getinfo_super_ddf(struct supertype *st, struct mdinfo *info, char *m getinfo_super_ddf_bvd(st, info, map); return; } + memset(info, 0, sizeof(*info)); info->array.raid_disks = __be16_to_cpu(ddf->phys->used_pdes); info->array.level = LEVEL_CONTAINER; @@ -1406,6 +1407,7 @@ static void getinfo_super_ddf_bvd(struct supertype *st, struct mdinfo *info, cha struct dl *dl; int map_disks = info->array.raid_disks; + memset(info, 0, sizeof(*info)); /* FIXME this returns BVD info - what if we want SVD ?? */ info->array.raid_disks = __be16_to_cpu(vc->conf.prim_elmnt_count); diff --git a/super-intel.c b/super-intel.c index e401eb01..b1461c64 100644 --- a/super-intel.c +++ b/super-intel.c @@ -1764,6 +1764,7 @@ static void getinfo_super_imsm_volume(struct supertype *st, struct mdinfo *info, unsigned int component_size_alligment; int map_disks = info->array.raid_disks; + memset(info, 0, sizeof(*info)); if (prev_map) map_to_analyse = prev_map; @@ -1972,6 +1973,7 @@ static void getinfo_super_imsm(struct supertype *st, struct mdinfo *info, char * getinfo_super_imsm_volume(st, info, map); return; } + memset(info, 0, sizeof(*info)); /* Set raid_disks to zero so that Assemble will always pull in valid * spares diff --git a/super0.c b/super0.c index 2c27e1e1..440981ba 100644 --- a/super0.c +++ b/super0.c @@ -346,6 +346,7 @@ static void getinfo_super0(struct supertype *st, struct mdinfo *info, char *map) int i; int map_disks = info->array.raid_disks; + memset(info, 0, sizeof(*info)); info->array.major_version = sb->major_version; info->array.minor_version = sb->minor_version; info->array.patch_version = sb->patch_version; diff --git a/super1.c b/super1.c index 9ba1ded4..81648232 100644 --- a/super1.c +++ b/super1.c @@ -566,6 +566,7 @@ static void getinfo_super1(struct supertype *st, struct mdinfo *info, char *map) unsigned int role; unsigned int map_disks = info->array.raid_disks; + memset(info, 0, sizeof(*info)); info->array.major_version = 1; info->array.minor_version = st->minor_version; info->array.patch_version = 0; -- 2.39.2