Re: [PATCH 1/1] fs/affs/file.c: unlock/release page on error

From: Fabian Frederick
Date: Sat Mar 21 2015 - 15:52:06 EST




> On 21 March 2015 at 18:31 Taesoo Kim <tsgatesv@xxxxxxxxx> wrote:
>
>
> When affs_bread_ino() fails, correctly unlock the page and
> release the page cache with proper error value. All write_end()
> should unlock/release the page that was locked by write_beg().
>
> Signed-off-by: Taesoo Kim <tsgatesv@xxxxxxxxx>
> ---
>Â fs/affs/file.c | 19 ++++++++++++-------
>Â 1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/fs/affs/file.c b/fs/affs/file.c
> index d2468bf..a91795e 100644
> --- a/fs/affs/file.c
> +++ b/fs/affs/file.c
> @@ -699,8 +699,10 @@ static int affs_write_end_ofs(struct file *file, struct
> address_space *mapping,
>Â Â Â Âboff = tmp % bsize;
>Â Â Â Âif (boff) {
>Â Â Â Â Â Â Â Âbh = affs_bread_ino(inode, bidx, 0);
> -Â Â Â Â Â Â Âif (IS_ERR(bh))
> -Â Â Â Â Â Â Â Â Â Â Âreturn PTR_ERR(bh);
> +Â Â Â Â Â Â Âif (IS_ERR(bh)) {
> +Â Â Â Â Â Â Â Â Â Â Âwritten = PTR_ERR(bh);
> +Â Â Â Â Â Â Â Â Â Â Âgoto err_first_bh;
> +Â Â Â Â Â Â Â}
>Â Â Â Â Â Â Â Âtmp = min(bsize - boff, to - from);
>Â Â Â Â Â Â Â ÂBUG_ON(boff + tmp > bsize || tmp > bsize);
>Â Â Â Â Â Â Â Âmemcpy(AFFS_DATA(bh) + boff, data + from, tmp);
> @@ -712,14 +714,16 @@ static int affs_write_end_ofs(struct file *file, struct
> address_space *mapping,
>Â Â Â Â Â Â Â Âbidx++;
>Â Â Â Â} else if (bidx) {
>Â Â Â Â Â Â Â Âbh = affs_bread_ino(inode, bidx - 1, 0);
> -Â Â Â Â Â Â Âif (IS_ERR(bh))
> -Â Â Â Â Â Â Â Â Â Â Âreturn PTR_ERR(bh);
> +Â Â Â Â Â Â Âif (IS_ERR(bh)) {
> +Â Â Â Â Â Â Â Â Â Â Âwritten = PTR_ERR(bh);
> +Â Â Â Â Â Â Â Â Â Â Âgoto err_first_bh;
> +Â Â Â Â Â Â Â}
>Â Â Â Â}
>Â Â Â Âwhile (from + bsize <= to) {
>Â Â Â Â Â Â Â Âprev_bh = bh;
>Â Â Â Â Â Â Â Âbh = affs_getemptyblk_ino(inode, bidx);
>Â Â Â Â Â Â Â Âif (IS_ERR(bh))
> -Â Â Â Â Â Â Â Â Â Â Âgoto out;
> +Â Â Â Â Â Â Â Â Â Â Âgoto err_bh;
>Â Â Â Â Â Â Â Âmemcpy(AFFS_DATA(bh), data + from, bsize);
>Â Â Â Â Â Â Â Âif (buffer_new(bh)) {
>Â Â Â Â Â Â Â Â Â Â Â ÂAFFS_DATA_HEAD(bh)->ptype = cpu_to_be32(T_DATA);
> @@ -751,7 +755,7 @@ static int affs_write_end_ofs(struct file *file, struct
> address_space *mapping,
>Â Â Â Â Â Â Â Âprev_bh = bh;
>Â Â Â Â Â Â Â Âbh = affs_bread_ino(inode, bidx, 1);
>Â Â Â Â Â Â Â Âif (IS_ERR(bh))
> -Â Â Â Â Â Â Â Â Â Â Âgoto out;
> +Â Â Â Â Â Â Â Â Â Â Âgoto err_bh;
>Â Â Â Â Â Â Â Âtmp = min(bsize, to - from);
>Â Â Â Â Â Â Â ÂBUG_ON(tmp > bsize);
>Â Â Â Â Â Â Â Âmemcpy(AFFS_DATA(bh), data + from, tmp);
> @@ -790,12 +794,13 @@ done:
>Â Â Â Âif (tmp > inode->i_size)
>Â Â Â Â Â Â Â Âinode->i_size = AFFS_I(inode)->mmu_private = tmp;
>Â
> +err_first_bh:
>Â Â Â Âunlock_page(page);
>Â Â Â Âpage_cache_release(page);
>Â
>Â Â Â Âreturn written;
>Â
> -out:
> +err_bh:
>Â Â Â Âbh = prev_bh;
>Â Â Â Âif (!written)
>Â Â Â Â Â Â Â Âwritten = PTR_ERR(bh);
> --
> 2.3.3
>

Hi Taesoo,

    Your patch is ok for me but we generally send a new message
for an update with the version in title and explain updates
done to it after ---. Here's an example of an AFFS V2 patch:
Â
http://marc.info/?l=linux-kernel&m=142316316001752&w=2

Regards,
Fabian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/