All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zdenek Kabelac <zkabelac@sourceware.org>
To: lvm-devel@redhat.com
Subject: master - bcache: use flexible arrays
Date: Fri,  2 Oct 2020 20:27:53 +0000 (GMT)	[thread overview]
Message-ID: <20201002202753.5BBC6398E493@sourceware.org> (raw)

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);
 }
 



                 reply	other threads:[~2020-10-02 20:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201002202753.5BBC6398E493@sourceware.org \
    --to=zkabelac@sourceware.org \
    --cc=lvm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.