* [PATCH 1/3] lib: assoc_array: use struct_size() in kmalloc()
@ 2019-05-17 7:26 xiaolinkui
2019-05-18 15:47 ` Gustavo A. R. Silva
0 siblings, 1 reply; 2+ messages in thread
From: xiaolinkui @ 2019-05-17 7:26 UTC (permalink / raw)
To: james.morris, gustavo, dhowells, akpm; +Cc: linux-kernel, xiaolinkui
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
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH 1/3] lib: assoc_array: use struct_size() in kmalloc()
2019-05-17 7:26 [PATCH 1/3] lib: assoc_array: use struct_size() in kmalloc() xiaolinkui
@ 2019-05-18 15:47 ` Gustavo A. R. Silva
0 siblings, 0 replies; 2+ messages in thread
From: Gustavo A. R. Silva @ 2019-05-18 15:47 UTC (permalink / raw)
To: xiaolinkui, james.morris, dhowells, akpm; +Cc: linux-kernel
On 5/17/19 2:26 AM, xiaolinkui wrote:
> Use the new struct_size() helper to keep code simple.
>
This is not the reason why this helper was created.
And if you are going to copy/paste changelog texts, at
least try to understand and compile[1][2] the code
before submitting it.
--
Gustavo
[1] https://lore.kernel.org/lkml/d83390a9-33be-3d76-3e23-b97f0a05b72f@kernel.dk/
[2] https://lore.kernel.org/lkml/b4d33107-75d5-fa18-536e-6d21c96e4972@kernel.dk/
> 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);
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-05-18 15:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-17 7:26 [PATCH 1/3] lib: assoc_array: use struct_size() in kmalloc() xiaolinkui
2019-05-18 15:47 ` Gustavo A. R. Silva
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®