mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Kyle Spiers <ksspiers@google.com>
Cc: jack@suse.cz, arnd@arndb.de, dhowells@redhat.com,
	viro@zeniv.linux.org.uk, gregkh@linuxfoundation.org,
	keescook@chromium.org, joe@perches.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4] isofs compress: Remove VLA usage
Date: Wed, 11 Apr 2018 09:57:03 +0200	[thread overview]
Message-ID: <20180411075703.uimpgcxsasxsm5sh@quack2.suse.cz> (raw)
In-Reply-To: <20180411000229.188137-1-ksspiers@google.com>

On Tue 10-04-18 17:02:29, Kyle Spiers wrote:
> 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>
> ---
> Fix sparc64 build
> Fix Error recovery Mistakes

Thanks, the patch looks good now and I've merged it to my tree and will
push it to Linus (likely for rc2).

								Honza

> ---
>  fs/isofs/compress.c | 19 ++++++++++++++++---
>  1 file 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 @@
>  #include <linux/init.h>
>  #include <linux/bio.h>
>  
> +#include <linux/slab.h>
>  #include <linux/vmalloc.h>
>  #include <linux/zlib.h>
>  
> @@ -59,7 +60,7 @@ static loff_t zisofs_uncompress_block(struct inode *inode, loff_t block_start,
>  				>> bufshift;
>  	int haveblocks;
>  	blkcnt_t blocknum;
> -	struct buffer_head *bhs[needblocks + 1];
> +	struct buffer_head **bhs;
>  	int curbh, curpage;
>  
>  	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. */
>  	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);
>  	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:
>  	for (i = 0; i < haveblocks; i++)
>  		brelse(bhs[i]);
> +	kfree(bhs);
>  	return stream.total_out;
>  }
>  
> @@ -305,7 +311,7 @@ static int zisofs_readpage(struct file *file, struct page *page)
>  	unsigned int zisofs_pages_per_cblock =
>  		PAGE_SHIFT <= zisofs_block_shift ?
>  		(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;
>  
>  	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;
>  		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;
>  
>  	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 */
> +	kfree(pages);
>  	return err;
>  }
>  
> -- 
> 2.17.0.484.g0c8726318c-goog
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

      reply	other threads:[~2018-04-11  7:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-11  0:02 Kyle Spiers
2018-04-11  7:57 ` Jan Kara [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180411075703.uimpgcxsasxsm5sh@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=arnd@arndb.de \
    --cc=dhowells@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=joe@perches.com \
    --cc=keescook@chromium.org \
    --cc=ksspiers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®