linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: shilong wang <wangshilong1991@gmail.com>
Cc: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 1/2] Ext2: free memory allocated and forget buffer head when io error happens
Date: Fri, 11 Jan 2013 17:22:02 +0100	[thread overview]
Message-ID: <20130111162202.GB16923@quack.suse.cz> (raw)
In-Reply-To: <CAP9B-QnartwX4ge95OfBWonMqYG1iebsjdjM=A0DodrsZJmLhw@mail.gmail.com>

On Fri 11-01-13 03:56:45, shilong wang wrote:
> From: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
> 
> Add a necessary check when a io error happens.
>  If io error happens,free the memory has been allocated and forget buffer head.
> 
> Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
> ---
>  fs/ext2/inode.c |   12 ++++++++++++
>  1 files changed, 12 insertions(+), 0 deletions(-)
> 
> diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
> index 6363ac6..661c816 100644
> --- a/fs/ext2/inode.c
> +++ b/fs/ext2/inode.c
> @@ -495,6 +495,10 @@ static int ext2_alloc_branch(struct inode *inode,
>  		 * parent to disk.
>  		 */
>  		bh = sb_getblk(inode->i_sb, new_blocks[n-1]);
> +		if (!bh) {
> +			err = -EIO;
> +			goto failed;
> +		}
  I think it should rather be ENOMEM because that's the only real reason
why sb_getblk() can fail...

>  		branch[n].bh = bh;
>  		lock_buffer(bh);
>  		memset(bh->b_data, 0, blocksize);
> @@ -523,6 +527,14 @@ static int ext2_alloc_branch(struct inode *inode,
>  	}
>  	*blks = num;
>  	return err;
> +
> +failed:
> +	for (i = 1; i < n; i++)
> +		bforget(branch[i].bh);
  I don't think we should bforget() the buffer here. They will be cleaned
up later in ext2_get_blocks().

> +	for (i = 0; i < indirect_blks; i++)
> +		ext2_free_blocks(inode, new_blocks[i], 1);
> +	ext2_free_blocks(inode, new_blocks[i], num);
> +	return err;
>  }

									Honza
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR

  reply	other threads:[~2013-01-11 16:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-11 11:56 [PATCH 1/2] Ext2: free memory allocated and forget buffer head when io error happens shilong wang
2013-01-11 16:22 ` Jan Kara [this message]
2013-01-11 16:25   ` Jan Kara

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=20130111162202.GB16923@quack.suse.cz \
    --to=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=wangshilong1991@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).