Re: [PATCH 9/13] fs/xfs: Remove redundant test

Eric Sandeen
2008-12-21T16:01:20Z

Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
>
> In fs/cifs/cifssmb.c, pLockData is tested for being NULL at the beginning
> of the function, and not reassigned subsequently.
>
> In fs/xfs/xfs_trans_buf.c, bp is tested for being NULL just a few lines
> above.
>
> A simplified version of the semantic patch that makes this change is as
> follows: (http://www.emn.fr/x-info/coccinelle/)
>
> // <smpl>
> @r exists@
> local idexpression x;
> expression E;
> position p1,p2;
> @@
>
> if (x@p1 == NULL || ...) { ... when forall
> return ...; }
> ... when != \(x=E\|x--\|x++\|--x\|++x\|x-=E\|x+=E\|x|=E\|x&=E\|&x\)
> (
> x@p2 == NULL
> |
> x@p2 != NULL
> )
>
> // another path to the test that is not through p1?
> @s exists@
> local idexpression r.x;
> position r.p1,r.p2;
> @@
>
> ... when != x@p1
> (
> x@p2 == NULL
> |
> x@p2 != NULL
> )
>
> @fix depends on !s@
> position r.p1,r.p2;
> expression x,E;
> statement S1,S2;
> @@
>
> (
> - if ((x@p2 != NULL) || ...)
> S1
> |
> - if ((x@p2 == NULL) && ...) S1
> |
> - BUG_ON(x@p2 == NULL);
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <julia@diku.dk>

Looks fine to me, though a similar test under the #ifdef DEBUG can
probably also be removed.

-Eric

> ---
> fs/xfs/xfs_trans_buf.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/fs/xfs/xfs_trans_buf.c b/fs/xfs/xfs_trans_buf.c
> index 8ee2f8c..22afe29 100644
> --- a/fs/xfs/xfs_trans_buf.c
> +++ b/fs/xfs/xfs_trans_buf.c
> @@ -307,7 +307,7 @@ xfs_trans_read_buf(
> return (flags & XFS_BUF_TRYLOCK) ?
> EAGAIN : XFS_ERROR(ENOMEM);
>
> - if ((bp != NULL) && (XFS_BUF_GETERROR(bp) != 0)) {
> + if (XFS_BUF_GETERROR(bp) != 0) {
> xfs_ioerror_alert("xfs_trans_read_buf", mp,
> bp, blkno);
> error = XFS_BUF_GETERROR(bp);
>
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
>