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>
This commit is contained in:
parent
1aa3b3e0cb
commit
5ac7c2fd6e
|
@ -20,6 +20,7 @@
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/bio.h>
|
#include <linux/bio.h>
|
||||||
|
|
||||||
|
#include <linux/slab.h>
|
||||||
#include <linux/vmalloc.h>
|
#include <linux/vmalloc.h>
|
||||||
#include <linux/zlib.h>
|
#include <linux/zlib.h>
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ static loff_t zisofs_uncompress_block(struct inode *inode, loff_t block_start,
|
||||||
>> bufshift;
|
>> bufshift;
|
||||||
int haveblocks;
|
int haveblocks;
|
||||||
blkcnt_t blocknum;
|
blkcnt_t blocknum;
|
||||||
struct buffer_head *bhs[needblocks + 1];
|
struct buffer_head **bhs;
|
||||||
int curbh, curpage;
|
int curbh, curpage;
|
||||||
|
|
||||||
if (block_size > deflateBound(1UL << zisofs_block_shift)) {
|
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,
|
||||||
|
|
||||||
/* Because zlib is not thread-safe, do all the I/O at the top. */
|
/* Because zlib is not thread-safe, do all the I/O at the top. */
|
||||||
blocknum = block_start >> bufshift;
|
blocknum = block_start >> bufshift;
|
||||||
memset(bhs, 0, (needblocks + 1) * sizeof(struct buffer_head *));
|
bhs = kcalloc(needblocks + 1, sizeof(*bhs), GFP_KERNEL);
|
||||||
|
if (!bhs) {
|
||||||
|
*errp = -ENOMEM;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
haveblocks = isofs_get_blocks(inode, blocknum, bhs, needblocks);
|
haveblocks = isofs_get_blocks(inode, blocknum, bhs, needblocks);
|
||||||
ll_rw_block(REQ_OP_READ, 0, haveblocks, bhs);
|
ll_rw_block(REQ_OP_READ, 0, haveblocks, bhs);
|
||||||
|
|
||||||
|
@ -190,6 +195,7 @@ static loff_t zisofs_uncompress_block(struct inode *inode, loff_t block_start,
|
||||||
b_eio:
|
b_eio:
|
||||||
for (i = 0; i < haveblocks; i++)
|
for (i = 0; i < haveblocks; i++)
|
||||||
brelse(bhs[i]);
|
brelse(bhs[i]);
|
||||||
|
kfree(bhs);
|
||||||
return stream.total_out;
|
return stream.total_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,7 +311,7 @@ static int zisofs_readpage(struct file *file, struct page *page)
|
||||||
unsigned int zisofs_pages_per_cblock =
|
unsigned int zisofs_pages_per_cblock =
|
||||||
PAGE_SHIFT <= zisofs_block_shift ?
|
PAGE_SHIFT <= zisofs_block_shift ?
|
||||||
(1 << (zisofs_block_shift - PAGE_SHIFT)) : 0;
|
(1 << (zisofs_block_shift - PAGE_SHIFT)) : 0;
|
||||||
struct page *pages[max_t(unsigned, zisofs_pages_per_cblock, 1)];
|
struct page **pages;
|
||||||
pgoff_t index = page->index, end_index;
|
pgoff_t index = page->index, end_index;
|
||||||
|
|
||||||
end_index = (inode->i_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
end_index = (inode->i_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
||||||
|
@ -330,6 +336,12 @@ static int zisofs_readpage(struct file *file, struct page *page)
|
||||||
full_page = 0;
|
full_page = 0;
|
||||||
pcount = 1;
|
pcount = 1;
|
||||||
}
|
}
|
||||||
|
pages = kcalloc(max_t(unsigned int, zisofs_pages_per_cblock, 1),
|
||||||
|
sizeof(*pages), GFP_KERNEL);
|
||||||
|
if (!pages) {
|
||||||
|
unlock_page(page);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
pages[full_page] = page;
|
pages[full_page] = page;
|
||||||
|
|
||||||
for (i = 0; i < pcount; i++, index++) {
|
for (i = 0; i < pcount; i++, index++) {
|
||||||
|
@ -357,6 +369,7 @@ static int zisofs_readpage(struct file *file, struct page *page)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* At this point, err contains 0 or -EIO depending on the "critical" page */
|
/* At this point, err contains 0 or -EIO depending on the "critical" page */
|
||||||
|
kfree(pages);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user