mirror of
https://github.com/torvalds/linux.git
synced 2026-05-12 16:18:45 +02:00
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>
This commit is contained in:
parent
c685e6e8d8
commit
e19eaffc52
|
|
@ -182,18 +182,12 @@ static int mtd_virt_concat_create_item(struct device_node *parts,
|
||||||
for (i = 1; i < count; i++)
|
for (i = 1; i < count; i++)
|
||||||
item->nodes[i] = of_parse_phandle(parts, CONCAT_PROP, (i - 1));
|
item->nodes[i] = of_parse_phandle(parts, CONCAT_PROP, (i - 1));
|
||||||
|
|
||||||
concat = kzalloc(sizeof(*concat), GFP_KERNEL);
|
concat = kzalloc_flex(*concat, subdev, count, GFP_KERNEL);
|
||||||
if (!concat) {
|
if (!concat) {
|
||||||
kfree(item);
|
kfree(item);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
concat->subdev = kcalloc(count, sizeof(*concat->subdev), GFP_KERNEL);
|
|
||||||
if (!concat->subdev) {
|
|
||||||
kfree(item);
|
|
||||||
kfree(concat);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
item->concat = concat;
|
item->concat = concat;
|
||||||
|
|
||||||
list_add_tail(&item->head, &concat_node_list);
|
list_add_tail(&item->head, &concat_node_list);
|
||||||
|
|
|
||||||
|
|
@ -627,7 +627,6 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
|
||||||
const char *name)
|
const char *name)
|
||||||
{ /* name for the new device */
|
{ /* name for the new device */
|
||||||
int i;
|
int i;
|
||||||
size_t size;
|
|
||||||
struct mtd_concat *concat;
|
struct mtd_concat *concat;
|
||||||
struct mtd_info *subdev_master = NULL;
|
struct mtd_info *subdev_master = NULL;
|
||||||
uint32_t max_erasesize, curr_erasesize;
|
uint32_t max_erasesize, curr_erasesize;
|
||||||
|
|
@ -640,15 +639,13 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
|
||||||
printk(KERN_NOTICE "into device \"%s\"\n", name);
|
printk(KERN_NOTICE "into device \"%s\"\n", name);
|
||||||
|
|
||||||
/* allocate the device structure */
|
/* allocate the device structure */
|
||||||
size = SIZEOF_STRUCT_MTD_CONCAT(num_devs);
|
concat = kzalloc_flex(*concat, subdev, num_devs, GFP_KERNEL);
|
||||||
concat = kzalloc(size, GFP_KERNEL);
|
|
||||||
if (!concat) {
|
if (!concat) {
|
||||||
printk
|
printk
|
||||||
("memory allocation error while creating concatenated device \"%s\"\n",
|
("memory allocation error while creating concatenated device \"%s\"\n",
|
||||||
name);
|
name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
concat->subdev = (struct mtd_info **) (concat + 1);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up the new "super" device's MTD object structure, check for
|
* Set up the new "super" device's MTD object structure, check for
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
struct mtd_concat {
|
struct mtd_concat {
|
||||||
struct mtd_info mtd;
|
struct mtd_info mtd;
|
||||||
int num_subdev;
|
int num_subdev;
|
||||||
struct mtd_info **subdev;
|
struct mtd_info *subdev[];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mtd_info *mtd_concat_create(
|
struct mtd_info *mtd_concat_create(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user