Skip to contentSkip to conversation

mtd: zero out mtd_partion struct before using it

PATCH In review Brian Norris 2 participants 3 messages Nov 12, 2015 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: zero out mtd_partion struct before using it

It's easier to guarantee we've cleared out all unused fields with memset() than by manually initializing each field.

---
I hit this while testing out the added 'of_node' field:

http://patchwork.ozlabs.org/patch/538838/

 drivers/mtd/mtdpart.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mtd/mtdpart.c +1 -2
index c2b6e967a160..3ace53342fd2 100644
@@ -597,11 +597,10 @@ int mtd_add_partition(struct mtd_info *master, const char *name,
 	if (length <= 0)
 		return -EINVAL;
 
+	memset(&part, 0, sizeof(part));
 	part.name = name;
 	part.size = length;
 	part.offset = offset;
-	part.mask_flags = 0;
-	part.ecclayout = NULL;
 
 	new = allocate_partition(master, &part, -1, offset);
 	if (IS_ERR(new))
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · On Wed, 11 Nov 2015 16:47:52 -0800 Brian Norris <[email protected]>…

It's easier to guarantee we've cleared out all unused fields with memset() than by manually initializing each field.

Quoted 25 lines

---
I hit this while testing out the added 'of_node' field:

http://patchwork.ozlabs.org/patch/538838/

 drivers/mtd/mtdpart.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mtd/mtdpart.c +1 -2
index c2b6e967a160..3ace53342fd2 100644
@@ -597,11 +597,10 @@ int mtd_add_partition(struct mtd_info *master, const char *name,
 	if (length <= 0)
 		return -EINVAL;
 
+	memset(&part, 0, sizeof(part));
 	part.name = name;
 	part.size = length;
 	part.offset = offset;
-	part.mask_flags = 0;
-	part.ecclayout = NULL;
 
 	new = allocate_partition(master, &part, -1, offset);
 	if (IS_ERR(new))
Signature · 3 lines
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com