public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Dave Chinner <david@fromorbit.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 3/5] xfs: silence sparse warning when checking version number
Date: Tue, 2 Apr 2024 20:57:27 -0700	[thread overview]
Message-ID: <20240403035727.GO6390@frogsfrogsfrogs> (raw)
In-Reply-To: <20240402213541.1199959-4-david@fromorbit.com>

On Wed, Apr 03, 2024 at 08:28:30AM +1100, Dave Chinner wrote:
> From: Dave Chinner <dchinner@redhat.com>
> 
> Scrub checks the superblock version number against the known good
> feature bits that can be set in the version mask. It calculates
> the version mask to compare like so:
> 
> 	vernum_mask = cpu_to_be16(~XFS_SB_VERSION_OKBITS |
>                                   XFS_SB_VERSION_NUMBITS |
>                                   XFS_SB_VERSION_ALIGNBIT |
>                                   XFS_SB_VERSION_DALIGNBIT |
>                                   XFS_SB_VERSION_SHAREDBIT |
>                                   XFS_SB_VERSION_LOGV2BIT |
>                                   XFS_SB_VERSION_SECTORBIT |
>                                   XFS_SB_VERSION_EXTFLGBIT |
>                                   XFS_SB_VERSION_DIRV2BIT);
> 
> This generates a sparse warning:
> 
> fs/xfs/scrub/agheader.c:168:23: warning: cast truncates bits from constant value (ffff3f8f becomes 3f8f)
> 
> This is because '~XFS_SB_VERSION_OKBITS' is considered a 32 bit
> constant, even though it's value is always under 16 bits.
> 
> This is a kinda silly thing to do, because:
> 
> /*
>  * Supported feature bit list is just all bits in the versionnum field because
>  * we've used them all up and understand them all. Except, of course, for the
>  * shared superblock bit, which nobody knows what it does and so is unsupported.
>  */
> #define XFS_SB_VERSION_OKBITS           \
>         ((XFS_SB_VERSION_NUMBITS | XFS_SB_VERSION_ALLFBITS) & \
>                 ~XFS_SB_VERSION_SHAREDBIT)
> 
> #define XFS_SB_VERSION_NUMBITS          0x000f
> #define XFS_SB_VERSION_ALLFBITS         0xfff0
> #define XFS_SB_VERSION_SHAREDBIT        0x0200
> 
> 
> XFS_SB_VERSION_OKBITS has a value of 0xfdff, and so
> ~XFS_SB_VERSION_OKBITS == XFS_SB_VERSION_SHAREDBIT.  The calculated
> mask already sets XFS_SB_VERSION_SHAREDBIT, so starting with
> ~XFS_SB_VERSION_OKBITS is completely redundant....
> 
> Signed-off-by: Dave Chinner <dchinner@redhat.com>

What a tongue twister!
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  fs/xfs/scrub/agheader.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/xfs/scrub/agheader.c b/fs/xfs/scrub/agheader.c
> index e954f07679dd..d6a1a9fc63c9 100644
> --- a/fs/xfs/scrub/agheader.c
> +++ b/fs/xfs/scrub/agheader.c
> @@ -165,8 +165,7 @@ xchk_superblock(
>  		xchk_block_set_corrupt(sc, bp);
>  
>  	/* Check sb_versionnum bits that are set at mkfs time. */
> -	vernum_mask = cpu_to_be16(~XFS_SB_VERSION_OKBITS |
> -				  XFS_SB_VERSION_NUMBITS |
> +	vernum_mask = cpu_to_be16(XFS_SB_VERSION_NUMBITS |
>  				  XFS_SB_VERSION_ALIGNBIT |
>  				  XFS_SB_VERSION_DALIGNBIT |
>  				  XFS_SB_VERSION_SHAREDBIT |
> -- 
> 2.43.0
> 
> 

  reply	other threads:[~2024-04-03  3:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-02 21:28 [PATCH 0/5] xfs: sparse warning fixes Dave Chinner
2024-04-02 21:28 ` [PATCH 1/5] xfs: fix CIL sparse lock context warnings Dave Chinner
2024-04-03  3:53   ` Christoph Hellwig
2024-04-02 21:28 ` [PATCH 2/5] xfs: fix sparse warning in xfs_extent_busy_clear Dave Chinner
2024-04-03  4:04   ` Darrick J. Wong
2024-04-03  4:32   ` Christoph Hellwig
2024-04-02 21:28 ` [PATCH 3/5] xfs: silence sparse warning when checking version number Dave Chinner
2024-04-03  3:57   ` Darrick J. Wong [this message]
2024-04-03  4:35   ` Christoph Hellwig
2024-04-02 21:28 ` [PATCH 4/5] xfs: remove unused is_rt_data_fork() function Dave Chinner
2024-04-03  3:54   ` Darrick J. Wong
2024-04-03  4:35   ` Christoph Hellwig
2024-04-02 21:28 ` [PATCH 5/5] xfs: fix sparse warnings about unused interval tree functions Dave Chinner
2024-04-03  3:53   ` Darrick J. Wong
2024-04-03  4:39   ` Christoph Hellwig

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=20240403035727.GO6390@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=david@fromorbit.com \
    --cc=linux-xfs@vger.kernel.org \
    /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