diff mbox series

[2/2] xfs: fix backwards endian conversion in scrub

Message ID 155111650186.15126.5896442701967175896.stgit@magnolia (mailing list archive)
State Accepted, archived
Headers show
Series [1/2] xfs: fix uninitialized error variables | expand

Commit Message

Darrick J. Wong Feb. 25, 2019, 5:41 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Fix a backwards endian conversion of a constant.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/scrub/agheader.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Allison Henderson Feb. 25, 2019, 6:09 p.m. UTC | #1
On 2/25/19 10:41 AM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Fix a backwards endian conversion of a constant.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>   fs/xfs/scrub/agheader.c |    2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> 
> diff --git a/fs/xfs/scrub/agheader.c b/fs/xfs/scrub/agheader.c
> index 9d4e8293d37e..ddf06bfaa29d 100644
> --- a/fs/xfs/scrub/agheader.c
> +++ b/fs/xfs/scrub/agheader.c
> @@ -399,7 +399,7 @@ xchk_agf_xref_cntbt(
>   	if (!xchk_should_check_xref(sc, &error, &sc->sa.cnt_cur))
>   		return;
>   	if (!have) {
> -		if (agf->agf_freeblks != be32_to_cpu(0))
> +		if (agf->agf_freeblks != cpu_to_be32(0))
>   			xchk_block_xref_set_corrupt(sc, sc->sa.agf_bp);
>   		return;
>   	}
> 

Good catch.  I suppose there's not as much need to do the conversion if 
the value is 0?  But I think the call helps to make clear that the value 
is supposed to be in big endian.

Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Darrick J. Wong Feb. 25, 2019, 6:15 p.m. UTC | #2
On Mon, Feb 25, 2019 at 11:09:14AM -0700, Allison Henderson wrote:
> On 2/25/19 10:41 AM, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Fix a backwards endian conversion of a constant.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> >   fs/xfs/scrub/agheader.c |    2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > 
> > diff --git a/fs/xfs/scrub/agheader.c b/fs/xfs/scrub/agheader.c
> > index 9d4e8293d37e..ddf06bfaa29d 100644
> > --- a/fs/xfs/scrub/agheader.c
> > +++ b/fs/xfs/scrub/agheader.c
> > @@ -399,7 +399,7 @@ xchk_agf_xref_cntbt(
> >   	if (!xchk_should_check_xref(sc, &error, &sc->sa.cnt_cur))
> >   		return;
> >   	if (!have) {
> > -		if (agf->agf_freeblks != be32_to_cpu(0))
> > +		if (agf->agf_freeblks != cpu_to_be32(0))
> >   			xchk_block_xref_set_corrupt(sc, sc->sa.agf_bp);
> >   		return;
> >   	}
> > 
> 
> Good catch.  I suppose there's not as much need to do the conversion if the
> value is 0?

Yep.  Fortunately, there's enough macro soup in cpu_to_be* (and all the
other endian conversion functions) to detect that the argument is a
constant value and transform it at compile time to avoid runtime
overhead.

> But I think the call helps to make clear that the value is supposed to
> be in big endian.

It's more or less to satisfy static checkers. :)

> Reviewed-by: Allison Henderson <allison.henderson@oracle.com>



--D
diff mbox series

Patch

diff --git a/fs/xfs/scrub/agheader.c b/fs/xfs/scrub/agheader.c
index 9d4e8293d37e..ddf06bfaa29d 100644
--- a/fs/xfs/scrub/agheader.c
+++ b/fs/xfs/scrub/agheader.c
@@ -399,7 +399,7 @@  xchk_agf_xref_cntbt(
 	if (!xchk_should_check_xref(sc, &error, &sc->sa.cnt_cur))
 		return;
 	if (!have) {
-		if (agf->agf_freeblks != be32_to_cpu(0))
+		if (agf->agf_freeblks != cpu_to_be32(0))
 			xchk_block_xref_set_corrupt(sc, sc->sa.agf_bp);
 		return;
 	}