mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-28 16:56:26 +00:00
module/decompress: use kvmalloc() consistently
We consistently switched from kmalloc() to vmalloc() in module decompression to prevent potential memory allocation failures with large modules, however vmalloc() is not as memory-efficient and fast as kmalloc(). Since we don't know in general the size of the workspace required by the decompression algorithm, it is more reasonable to use kvmalloc() consistently, also considering that we don't have special memory requirements here. Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Tested-by: Andrea Righi <andrea.righi@canonical.com> Signed-off-by: Andrea Righi <andrea.righi@canonical.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
ca219be012
commit
17fc8084aa
@ -100,7 +100,7 @@ static ssize_t module_gzip_decompress(struct load_info *info,
|
||||
s.next_in = buf + gzip_hdr_len;
|
||||
s.avail_in = size - gzip_hdr_len;
|
||||
|
||||
s.workspace = vmalloc(zlib_inflate_workspacesize());
|
||||
s.workspace = kvmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
|
||||
if (!s.workspace)
|
||||
return -ENOMEM;
|
||||
|
||||
@ -138,7 +138,7 @@ static ssize_t module_gzip_decompress(struct load_info *info,
|
||||
out_inflate_end:
|
||||
zlib_inflateEnd(&s);
|
||||
out:
|
||||
vfree(s.workspace);
|
||||
kvfree(s.workspace);
|
||||
return retval;
|
||||
}
|
||||
#elif defined(CONFIG_MODULE_COMPRESS_XZ)
|
||||
@ -241,7 +241,7 @@ static ssize_t module_zstd_decompress(struct load_info *info,
|
||||
}
|
||||
|
||||
wksp_size = zstd_dstream_workspace_bound(header.windowSize);
|
||||
wksp = vmalloc(wksp_size);
|
||||
wksp = kvmalloc(wksp_size, GFP_KERNEL);
|
||||
if (!wksp) {
|
||||
retval = -ENOMEM;
|
||||
goto out;
|
||||
@ -284,7 +284,7 @@ static ssize_t module_zstd_decompress(struct load_info *info,
|
||||
retval = new_size;
|
||||
|
||||
out:
|
||||
vfree(wksp);
|
||||
kvfree(wksp);
|
||||
return retval;
|
||||
}
|
||||
#else
|
||||
|
Loading…
Reference in New Issue
Block a user