Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mtd: concat: replace alloc + calloc with 1 alloc

A flex array can be used to reduce the allocation to 1.

And actually mtdconcat was using the pointer + 1 trick to point to the
overallocated area. Better alternatives exist.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

authored by

Rosen Penev and committed by
Miquel Raynal
e19eaffc c685e6e8

+3 -12
+1 -7
drivers/mtd/mtd_virt_concat.c
··· 182 182 for (i = 1; i < count; i++) 183 183 item->nodes[i] = of_parse_phandle(parts, CONCAT_PROP, (i - 1)); 184 184 185 - concat = kzalloc(sizeof(*concat), GFP_KERNEL); 185 + concat = kzalloc_flex(*concat, subdev, count, GFP_KERNEL); 186 186 if (!concat) { 187 187 kfree(item); 188 188 return -ENOMEM; 189 189 } 190 190 191 - concat->subdev = kcalloc(count, sizeof(*concat->subdev), GFP_KERNEL); 192 - if (!concat->subdev) { 193 - kfree(item); 194 - kfree(concat); 195 - return -ENOMEM; 196 - } 197 191 item->concat = concat; 198 192 199 193 list_add_tail(&item->head, &concat_node_list);
+1 -4
drivers/mtd/mtdconcat.c
··· 627 627 const char *name) 628 628 { /* name for the new device */ 629 629 int i; 630 - size_t size; 631 630 struct mtd_concat *concat; 632 631 struct mtd_info *subdev_master = NULL; 633 632 uint32_t max_erasesize, curr_erasesize; ··· 639 640 printk(KERN_NOTICE "into device \"%s\"\n", name); 640 641 641 642 /* allocate the device structure */ 642 - size = SIZEOF_STRUCT_MTD_CONCAT(num_devs); 643 - concat = kzalloc(size, GFP_KERNEL); 643 + concat = kzalloc_flex(*concat, subdev, num_devs, GFP_KERNEL); 644 644 if (!concat) { 645 645 printk 646 646 ("memory allocation error while creating concatenated device \"%s\"\n", 647 647 name); 648 648 return NULL; 649 649 } 650 - concat->subdev = (struct mtd_info **) (concat + 1); 651 650 652 651 /* 653 652 * Set up the new "super" device's MTD object structure, check for
+1 -1
include/linux/mtd/concat.h
··· 18 18 struct mtd_concat { 19 19 struct mtd_info mtd; 20 20 int num_subdev; 21 - struct mtd_info **subdev; 21 + struct mtd_info *subdev[]; 22 22 }; 23 23 24 24 struct mtd_info *mtd_concat_create(