* master - bcache: use flexible arrays
@ 2020-10-02 20:27 Zdenek Kabelac
0 siblings, 0 replies; only message in thread
From: Zdenek Kabelac @ 2020-10-02 20:27 UTC (permalink / raw)
To: lvm-devel
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b44db5d1a7ecc2e8e3cef0852c4397b64ddf0a09
Commit: b44db5d1a7ecc2e8e3cef0852c4397b64ddf0a09
Parent: b3c7a2b3f0bc761a14cfe1c8fc768e265a183204
Author: Zdenek Kabelac <zkabelac@redhat.com>
AuthorDate: Wed Sep 30 23:28:44 2020 +0200
Committer: Zdenek Kabelac <zkabelac@redhat.com>
CommitterDate: Fri Oct 2 21:00:26 2020 +0200
bcache: use flexible arrays
Cleanup, allocate whole struct with a single malloc call.
---
lib/device/bcache.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/lib/device/bcache.c b/lib/device/bcache.c
index d1749d9ab..2451eda2b 100644
--- a/lib/device/bcache.c
+++ b/lib/device/bcache.c
@@ -66,23 +66,17 @@ struct control_block {
struct cb_set {
struct dm_list free;
struct dm_list allocated;
- struct control_block *vec;
+ struct control_block vec[];
} control_block_set;
static struct cb_set *_cb_set_create(unsigned nr)
{
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;
- cbs->vec = malloc(nr * sizeof(*cbs->vec));
- if (!cbs->vec) {
- free(cbs);
- return NULL;
- }
-
dm_list_init(&cbs->free);
dm_list_init(&cbs->allocated);
@@ -102,7 +96,6 @@ static void _cb_set_destroy(struct cb_set *cbs)
return;
}
- free(cbs->vec);
free(cbs);
}
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2020-10-02 20:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-02 20:27 master - bcache: use flexible arrays Zdenek Kabelac
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.