Skip to content

Commit c685e6e

Browse files
nehebmiquelraynal
authored andcommitted
mtd: virt_concat: use single allocation for node
Simpler to reason about and avoids having to free nodes separately. Also add __counted_by attribute for extra runtime analysis. Signed-off-by: Rosen Penev <rosenp@gmail.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent 87d8f12 commit c685e6e

1 file changed

Lines changed: 2 additions & 9 deletions

File tree

drivers/mtd/mtd_virt_concat.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ static LIST_HEAD(concat_node_list);
3131
struct mtd_virt_concat_node {
3232
struct list_head head;
3333
unsigned int count;
34-
struct device_node **nodes;
3534
struct mtd_concat *concat;
35+
struct device_node *nodes[] __counted_by(count);
3636
};
3737

3838
/**
@@ -133,7 +133,6 @@ int mtd_virt_concat_destroy(struct mtd_info *mtd)
133133
for (idx = 0; idx < item->count; idx++)
134134
of_node_put(item->nodes[idx]);
135135

136-
kfree(item->nodes);
137136
kfree(item);
138137
}
139138
return 0;
@@ -167,16 +166,11 @@ static int mtd_virt_concat_create_item(struct device_node *parts,
167166
return 0;
168167
}
169168

170-
item = kzalloc(sizeof(*item), GFP_KERNEL);
169+
item = kzalloc_flex(*item, nodes, count, GFP_KERNEL);
171170
if (!item)
172171
return -ENOMEM;
173172

174173
item->count = count;
175-
item->nodes = kcalloc(count, sizeof(*item->nodes), GFP_KERNEL);
176-
if (!item->nodes) {
177-
kfree(item);
178-
return -ENOMEM;
179-
}
180174

181175
/*
182176
* The partition in which "part-concat-next" property
@@ -216,7 +210,6 @@ void mtd_virt_concat_destroy_items(void)
216210
for (i = 0; i < item->count; i++)
217211
of_node_put(item->nodes[i]);
218212

219-
kfree(item->nodes);
220213
kfree(item);
221214
}
222215
}

0 commit comments

Comments
 (0)