mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
bcache: use flexible arrays
Cleanup, allocate whole struct with a single malloc call.
This commit is contained in:
parent
b3c7a2b3f0
commit
b44db5d1a7
@ -66,23 +66,17 @@ struct control_block {
|
|||||||
struct cb_set {
|
struct cb_set {
|
||||||
struct dm_list free;
|
struct dm_list free;
|
||||||
struct dm_list allocated;
|
struct dm_list allocated;
|
||||||
struct control_block *vec;
|
struct control_block vec[];
|
||||||
} control_block_set;
|
} control_block_set;
|
||||||
|
|
||||||
static struct cb_set *_cb_set_create(unsigned nr)
|
static struct cb_set *_cb_set_create(unsigned nr)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
struct cb_set *cbs = malloc(sizeof(*cbs));
|
struct cb_set *cbs = malloc(sizeof(*cbs) + nr * sizeof(*cbs->vec));
|
||||||
|
|
||||||
if (!cbs)
|
if (!cbs->vec)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
cbs->vec = malloc(nr * sizeof(*cbs->vec));
|
|
||||||
if (!cbs->vec) {
|
|
||||||
free(cbs);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
dm_list_init(&cbs->free);
|
dm_list_init(&cbs->free);
|
||||||
dm_list_init(&cbs->allocated);
|
dm_list_init(&cbs->allocated);
|
||||||
|
|
||||||
@ -102,7 +96,6 @@ static void _cb_set_destroy(struct cb_set *cbs)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(cbs->vec);
|
|
||||||
free(cbs);
|
free(cbs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user