aboutsummaryrefslogtreecommitdiffstats
path: root/fs/isofs
diff options
context:
space:
mode:
authorKyle Spiers <ksspiers@google.com>2018-04-10 20:02:29 -0400
committerJan Kara <jack@suse.cz>2018-04-11 03:55:40 -0400
commit5ac7c2fd6e7102532104907c0df94abca826ec5c (patch)
tree541480a00b9870bb5b97328c8abca5897e7aa7c7 /fs/isofs
parent1aa3b3e0cbdb32439f04842e88fc7557a0777660 (diff)
isofs compress: Remove VLA usage
As part of the effort to remove VLAs from the kernel[1], this changes the allocation of the bhs and pages arrays from being on the stack to being kcalloc()ed. This also allows for the removal of the explicit zeroing of bhs. https://lkml.org/lkml/2018/3/7/621 Signed-off-by: Kyle Spiers <ksspiers@google.com> Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/isofs')
-rw-r--r--fs/isofs/compress.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/fs/isofs/compress.c b/fs/isofs/compress.c
index 9bb2fe35799d..10205ececc27 100644
--- a/fs/isofs/compress.c
+++ b/fs/isofs/compress.c
@@ -20,6 +20,7 @@
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/bio.h> 21#include <linux/bio.h>
22 22
23#include <linux/slab.h>
23#include <linux/vmalloc.h> 24#include <linux/vmalloc.h>
24#include <linux/zlib.h> 25#include <linux/zlib.h>
25 26
@@ -59,7 +60,7 @@ static loff_t zisofs_uncompress_block(struct inode *inode, loff_t block_start,
59 >> bufshift; 60 >> bufshift;
60 int haveblocks; 61 int haveblocks;
61 blkcnt_t blocknum; 62 blkcnt_t blocknum;
62 struct buffer_head *bhs[needblocks + 1]; 63 struct buffer_head **bhs;
63 int curbh, curpage; 64 int curbh, curpage;
64 65
65 if (block_size > deflateBound(1UL << zisofs_block_shift)) { 66 if (block_size > deflateBound(1UL << zisofs_block_shift)) {
@@ -80,7 +81,11 @@ static loff_t zisofs_uncompress_block(struct inode *inode, loff_t block_start,
80 81
81 /* Because zlib is not thread-safe, do all the I/O at the top. */ 82 /* Because zlib is not thread-safe, do all the I/O at the top. */
82 blocknum = block_start >> bufshift; 83 blocknum = block_start >> bufshift;
83 memset(bhs, 0, (needblocks + 1) * sizeof(struct buffer_head *)); 84 bhs = kcalloc(needblocks + 1, sizeof(*bhs), GFP_KERNEL);
85 if (!bhs) {
86 *errp = -ENOMEM;
87 return 0;
88 }
84 haveblocks = isofs_get_blocks(inode, blocknum, bhs, needblocks); 89 haveblocks = isofs_get_blocks(inode, blocknum, bhs, needblocks);
85 ll_rw_block(REQ_OP_READ, 0, haveblocks, bhs); 90 ll_rw_block(REQ_OP_READ, 0, haveblocks, bhs);
86 91
@@ -190,6 +195,7 @@ z_eio:
190b_eio: 195b_eio:
191 for (i = 0; i < haveblocks; i++) 196 for (i = 0; i < haveblocks; i++)
192 brelse(bhs[i]); 197 brelse(bhs[i]);
198 kfree(bhs);
193 return stream.total_out; 199 return stream.total_out;
194} 200}
195 201
@@ -305,7 +311,7 @@ static int zisofs_readpage(struct file *file, struct page *page)
305 unsigned int zisofs_pages_per_cblock = 311 unsigned int zisofs_pages_per_cblock =
306 PAGE_SHIFT <= zisofs_block_shift ? 312 PAGE_SHIFT <= zisofs_block_shift ?
307 (1 << (zisofs_block_shift - PAGE_SHIFT)) : 0; 313 (1 << (zisofs_block_shift - PAGE_SHIFT)) : 0;
308 struct page *pages[max_t(unsigned, zisofs_pages_per_cblock, 1)]; 314 struct page **pages;
309 pgoff_t index = page->index, end_index; 315 pgoff_t index = page->index, end_index;
310 316
311 end_index = (inode->i_size + PAGE_SIZE - 1) >> PAGE_SHIFT; 317 end_index = (inode->i_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
@@ -330,6 +336,12 @@ static int zisofs_readpage(struct file *file, struct page *page)
330 full_page = 0; 336 full_page = 0;
331 pcount = 1; 337 pcount = 1;
332 } 338 }
339 pages = kcalloc(max_t(unsigned int, zisofs_pages_per_cblock, 1),
340 sizeof(*pages), GFP_KERNEL);
341 if (!pages) {
342 unlock_page(page);
343 return -ENOMEM;
344 }
333 pages[full_page] = page; 345 pages[full_page] = page;
334 346
335 for (i = 0; i < pcount; i++, index++) { 347 for (i = 0; i < pcount; i++, index++) {
@@ -357,6 +369,7 @@ static int zisofs_readpage(struct file *file, struct page *page)
357 } 369 }
358 370
359 /* At this point, err contains 0 or -EIO depending on the "critical" page */ 371 /* At this point, err contains 0 or -EIO depending on the "critical" page */
372 kfree(pages);
360 return err; 373 return err;
361} 374}
362 375