mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: xiaolinkui <xiaolinkui@kylinos.cn>
To: james.morris@microsoft.com, gustavo@embeddedor.com,
	dhowells@redhat.com, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, xiaolinkui@kylinos.cn
Subject: [PATCH 1/3] lib: assoc_array: use struct_size() in kmalloc()
Date: Fri, 17 May 2019 15:26:48 +0800	[thread overview]
Message-ID: <1558078008-15737-1-git-send-email-xiaolinkui@kylinos.cn> (raw)

Use the new struct_size() helper to keep code simple.

Signed-off-by: xiaolinkui <xiaolinkui@kylinos.cn>
---
 lib/assoc_array.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib/assoc_array.c b/lib/assoc_array.c
index edc3c14..0e69b5b 100644
--- a/lib/assoc_array.c
+++ b/lib/assoc_array.c
@@ -1494,8 +1494,7 @@ int assoc_array_gc(struct assoc_array *array,
 		shortcut = assoc_array_ptr_to_shortcut(cursor);
 		keylen = round_up(shortcut->skip_to_level, ASSOC_ARRAY_KEY_CHUNK_SIZE);
 		keylen >>= ASSOC_ARRAY_KEY_CHUNK_SHIFT;
-		new_s = kmalloc(sizeof(struct assoc_array_shortcut) +
-				keylen * sizeof(unsigned long), GFP_KERNEL);
+		new_s = kmalloc(struct_size(new_s, index_key, keylen), GFP_KERNEL);
 		if (!new_s)
 			goto enomem;
 		pr_devel("dup shortcut %p -> %p\n", shortcut, new_s);
-- 
2.7.4




             reply	other threads:[~2019-05-17  7:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-17  7:26 xiaolinkui [this message]
2019-05-18 15:47 ` Gustavo A. R. Silva

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=1558078008-15737-1-git-send-email-xiaolinkui@kylinos.cn \
    --to=xiaolinkui@kylinos.cn \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=gustavo@embeddedor.com \
    --cc=james.morris@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®