Skip to content

Commit 17fc808

Browse files
Andrea Righitorvalds
authored andcommitted
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 <[email protected]> Tested-by: Andrea Righi <[email protected]> Signed-off-by: Andrea Righi <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent ca219be commit 17fc808

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

kernel/module/decompress.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static ssize_t module_gzip_decompress(struct load_info *info,
100100
s.next_in = buf + gzip_hdr_len;
101101
s.avail_in = size - gzip_hdr_len;
102102

103-
s.workspace = vmalloc(zlib_inflate_workspacesize());
103+
s.workspace = kvmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
104104
if (!s.workspace)
105105
return -ENOMEM;
106106

@@ -138,7 +138,7 @@ static ssize_t module_gzip_decompress(struct load_info *info,
138138
out_inflate_end:
139139
zlib_inflateEnd(&s);
140140
out:
141-
vfree(s.workspace);
141+
kvfree(s.workspace);
142142
return retval;
143143
}
144144
#elif defined(CONFIG_MODULE_COMPRESS_XZ)
@@ -241,7 +241,7 @@ static ssize_t module_zstd_decompress(struct load_info *info,
241241
}
242242

243243
wksp_size = zstd_dstream_workspace_bound(header.windowSize);
244-
wksp = vmalloc(wksp_size);
244+
wksp = kvmalloc(wksp_size, GFP_KERNEL);
245245
if (!wksp) {
246246
retval = -ENOMEM;
247247
goto out;
@@ -284,7 +284,7 @@ static ssize_t module_zstd_decompress(struct load_info *info,
284284
retval = new_size;
285285

286286
out:
287-
vfree(wksp);
287+
kvfree(wksp);
288288
return retval;
289289
}
290290
#else

0 commit comments

Comments
 (0)