Lines Matching +full:page +full:- +full:size
1 // SPDX-License-Identifier: GPL-2.0-or-later
19 struct page **new_pages; in module_extend_max_pages()
21 new_pages = kvmalloc_array(info->max_pages + extent, in module_extend_max_pages()
22 sizeof(info->pages), GFP_KERNEL); in module_extend_max_pages()
24 return -ENOMEM; in module_extend_max_pages()
26 memcpy(new_pages, info->pages, info->max_pages * sizeof(info->pages)); in module_extend_max_pages()
27 kvfree(info->pages); in module_extend_max_pages()
28 info->pages = new_pages; in module_extend_max_pages()
29 info->max_pages += extent; in module_extend_max_pages()
34 static struct page *module_get_next_page(struct load_info *info) in module_get_next_page()
36 struct page *page; in module_get_next_page() local
39 if (info->max_pages == info->used_pages) { in module_get_next_page()
40 error = module_extend_max_pages(info, info->used_pages); in module_get_next_page()
45 page = alloc_page(GFP_KERNEL | __GFP_HIGHMEM); in module_get_next_page()
46 if (!page) in module_get_next_page()
47 return ERR_PTR(-ENOMEM); in module_get_next_page()
49 info->pages[info->used_pages++] = page; in module_get_next_page()
50 return page; in module_get_next_page()
63 static size_t module_gzip_header_len(const u8 *buf, size_t size) in module_gzip_header_len() argument
68 if (size < len || memcmp(buf, signature, sizeof(signature))) in module_gzip_header_len()
77 if (len == size) in module_gzip_header_len()
86 const void *buf, size_t size) in module_gzip_decompress() argument
94 gzip_hdr_len = module_gzip_header_len(buf, size); in module_gzip_decompress()
97 return -EINVAL; in module_gzip_decompress()
101 s.avail_in = size - gzip_hdr_len; in module_gzip_decompress()
105 return -ENOMEM; in module_gzip_decompress()
107 rc = zlib_inflateInit2(&s, -MAX_WBITS); in module_gzip_decompress()
110 retval = -EINVAL; in module_gzip_decompress()
115 struct page *page = module_get_next_page(info); in module_gzip_decompress() local
117 if (IS_ERR(page)) { in module_gzip_decompress()
118 retval = PTR_ERR(page); in module_gzip_decompress()
122 s.next_out = kmap_local_page(page); in module_gzip_decompress()
127 new_size += PAGE_SIZE - s.avail_out; in module_gzip_decompress()
132 retval = -EINVAL; in module_gzip_decompress()
150 const void *buf, size_t size) in module_xz_decompress() argument
159 if (size < sizeof(signature) || in module_xz_decompress()
162 return -EINVAL; in module_xz_decompress()
165 xz_dec = xz_dec_init(XZ_DYNALLOC, (u32)-1); in module_xz_decompress()
167 return -ENOMEM; in module_xz_decompress()
169 xz_buf.in_size = size; in module_xz_decompress()
174 struct page *page = module_get_next_page(info); in module_xz_decompress() local
176 if (IS_ERR(page)) { in module_xz_decompress()
177 retval = PTR_ERR(page); in module_xz_decompress()
181 xz_buf.out = kmap_local_page(page); in module_xz_decompress()
192 retval = -EINVAL; in module_xz_decompress()
208 const void *buf, size_t size) in module_zstd_decompress() argument
221 if (size < sizeof(signature) || in module_zstd_decompress()
224 return -EINVAL; in module_zstd_decompress()
229 zstd_buf.size = size; in module_zstd_decompress()
231 ret = zstd_get_frame_header(&header, zstd_buf.src, zstd_buf.size); in module_zstd_decompress()
233 pr_err("ZSTD-compressed data has an incomplete frame header\n"); in module_zstd_decompress()
234 retval = -EINVAL; in module_zstd_decompress()
238 pr_err("ZSTD-compressed data has too large a window size\n"); in module_zstd_decompress()
239 retval = -EINVAL; in module_zstd_decompress()
246 retval = -ENOMEM; in module_zstd_decompress()
253 retval = -ENOMEM; in module_zstd_decompress()
258 struct page *page = module_get_next_page(info); in module_zstd_decompress() local
260 if (IS_ERR(page)) { in module_zstd_decompress()
261 retval = PTR_ERR(page); in module_zstd_decompress()
265 zstd_dec.dst = kmap_local_page(page); in module_zstd_decompress()
267 zstd_dec.size = PAGE_SIZE; in module_zstd_decompress()
279 pr_err("ZSTD-decompression failed with status %d\n", retval); in module_zstd_decompress()
280 retval = -EINVAL; in module_zstd_decompress()
294 int module_decompress(struct load_info *info, const void *buf, size_t size) in module_decompress() argument
301 info->compressed_len = size; in module_decompress()
308 n_pages = DIV_ROUND_UP(size, PAGE_SIZE) * 2; in module_decompress()
311 data_size = MODULE_DECOMPRESS_FN(info, buf, size); in module_decompress()
317 info->hdr = vmap(info->pages, info->used_pages, VM_MAP, PAGE_KERNEL); in module_decompress()
318 if (!info->hdr) { in module_decompress()
319 error = -ENOMEM; in module_decompress()
323 info->len = data_size; in module_decompress()
335 if (info->hdr) in module_decompress_cleanup()
336 vunmap(info->hdr); in module_decompress_cleanup()
338 for (i = 0; i < info->used_pages; i++) in module_decompress_cleanup()
339 __free_page(info->pages[i]); in module_decompress_cleanup()
341 kvfree(info->pages); in module_decompress_cleanup()
343 info->pages = NULL; in module_decompress_cleanup()
344 info->max_pages = info->used_pages = 0; in module_decompress_cleanup()
360 error = sysfs_create_file(&module_kset->kobj, in module_decompress_sysfs_init()