module/decompress: Avoid open-coded kvrealloc()
PATCH 1/1 module/decompress: Avoid open-coded kvrealloc()
Replace open-coded allocate/copy with kvrealloc().
---
Cc: Petr Pavlu <[email protected]>
Cc: Luis Chamberlain <[email protected]>
Cc: Sami Tolvanen <[email protected]>
Cc: Daniel Gomez <[email protected]>
Cc: <[email protected]>
--- kernel/module/decompress.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/module/decompress.c +5 -5
@@ -17,16 +17,16 @@static int module_extend_max_pages (struct load_info *info,unsigned int extent) {struct page **new_pages; +unsigned int new_max = info->max_pages + extent; - new_pages =kvmalloc_array (info->max_pages + extent, -sizeof (info->pages),GFP_KERNEL ); + new_pages =kvrealloc (info->pages, +size_mul (new_max,sizeof (*info->pages)), +GFP_KERNEL );if (!new_pages)return -ENOMEM ; -memcpy (new_pages, info->pages, info->max_pages *sizeof (info->pages)); -kvfree (info->pages); info->pages = new_pages; - info->max_pages += extent; + info->max_pages = new_max;return 0 ; }
Signature · 1 line
2.34.1
Quoted 18 lines · Kees Cook
Replace open-coded allocate/copy with
kvrealloc().Signed-off-by Kees Cook <[email protected]>---
Cc: Petr Pavlu <[email protected]>
Cc: Luis Chamberlain <[email protected]>
Cc: Sami Tolvanen <[email protected]>
Cc: Daniel Gomez <[email protected]>
Cc: <[email protected]>--- kernel/module/decompress.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)kernel/module/decompress.c +0
-0
kernel/module/decompress.c line 24
Quoted 10 lines
kernel/module/decompress.c +4
-2@@ -17,16 +17,16 @@static int module_extend_max_pages (struct load_info *info,unsigned int extent) {struct page **new_pages; +unsigned int new_max = info->max_pages + extent; - new_pages =kvmalloc_array (info->max_pages + extent, -sizeof (info->pages),GFP_KERNEL ); + new_pages =kvrealloc (info->pages, +size_mul (new_max,sizeof (*info->pages)), +GFP_KERNEL );
Nit: Using the array_size() alias of size_mul() might be clearer in this context.
It looks ok to me in any case.
Signature · 2 lines
Thanks, Petr
Quoted 3 lines · Kees Cook
Replace open-coded allocate/copy with
kvrealloc().
Applied to modules-next, thanks!
[1/1] module/decompress: Avoid open-coded kvrealloc()
commit: 68e85558587e6bbb5c3ea3c8b4c71ab852e4b53e
Best regards,
Sami