Skip to contentSkip to conversation

xfs: avoid -Wint-in-bool-context warning in xfs_bmap_util.c

PATCH In review Eric Biggers 2 participants 3 messages Jun 3, 2017 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: avoid -Wint-in-bool-context warning in xfs_bmap_util.c

From: Eric Biggers <[email protected]>

XFS triggers gcc 7's -Wint-in-bool-context warning (on by default with -Wall), which warns about arithmetic in a boolean context that has no effect on the result:

    In file included from fs/xfs/xfs_inode.h:22:0,
                     from fs/xfs/xfs_bmap_util.c:29:
    fs/xfs/xfs_bmap_util.c: In function ‘xfs_swap_extents_check_format’:
    fs/xfs/libxfs/xfs_inode_fork.h:90:30: warning: ‘<<’ in boolean context, did you mean ‘<’ ? [-Wint-in-bool-context]
     #define XFS_IFORK_BOFF(ip)  ((int)((ip)->i_d.di_forkoff << 3))
                                 ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    fs/xfs/xfs_bmap_util.c:1620:7: note: in expansion of macro ‘XFS_IFORK_BOFF’
       if (XFS_IFORK_BOFF(ip) &&
           ^~~~~~~~~~~~~~
    fs/xfs/libxfs/xfs_inode_fork.h:90:30: warning: ‘<<’ in boolean context, did you mean ‘<’ ? [-Wint-in-bool-context]
     #define XFS_IFORK_BOFF(ip)  ((int)((ip)->i_d.di_forkoff << 3))
                                 ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    fs/xfs/xfs_bmap_util.c:1630:7: note: in expansion of macro ‘XFS_IFORK_BOFF’
       if (XFS_IFORK_BOFF(tip) &&
           ^~~~~~~~~~~~~~

This is more or less a false positive, because the useless arithmetic is just the left shift in XFS_IFORK_BOFF(). Use XFS_IFORK_Q() instead to make the warnings go away, while having the same behavior and being more consistent with other places in XFS which also use XFS_IFORK_Q().

---
 fs/xfs/xfs_bmap_util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/xfs/xfs_bmap_util.c +2 -2
index 7ac80a1facf2..05a6fdf5976d 100644
@@ -1613,7 +1613,7 @@ xfs_swap_extents_check_format(
 	 * extent format...
 	 */
 	if (tip->i_d.di_format == XFS_DINODE_FMT_BTREE) {
-		if (XFS_IFORK_BOFF(ip) &&
+		if (XFS_IFORK_Q(ip) &&
 		    XFS_BMAP_BMDR_SPACE(tip->i_df.if_broot) > XFS_IFORK_BOFF(ip))
 			return -EINVAL;
 		if (XFS_IFORK_NEXTENTS(tip, XFS_DATA_FORK) <=
@@ -1623,7 +1623,7 @@ xfs_swap_extents_check_format(
 
 	/* Reciprocal target->temp btree format checks */
 	if (ip->i_d.di_format == XFS_DINODE_FMT_BTREE) {
-		if (XFS_IFORK_BOFF(tip) &&
+		if (XFS_IFORK_Q(tip) &&
 		    XFS_BMAP_BMDR_SPACE(ip->i_df.if_broot) > XFS_IFORK_BOFF(tip))
 			return -EINVAL;
 		if (XFS_IFORK_NEXTENTS(ip, XFS_DATA_FORK) <=
Signature · 1 line
2.13.0
#1 lore raw
Quoted 22 lines · Eric Biggers

From: Eric Biggers <[email protected]>

XFS triggers gcc 7's -Wint-in-bool-context warning (on by default with -Wall), which warns about arithmetic in a boolean context that has no effect on the result:

    In file included from fs/xfs/xfs_inode.h:22:0,
                     from fs/xfs/xfs_bmap_util.c:29:
    fs/xfs/xfs_bmap_util.c: In function ‘xfs_swap_extents_check_format’:
    fs/xfs/libxfs/xfs_inode_fork.h:90:30: warning: ‘<<’ in boolean context, did you mean ‘<’ ? [-Wint-in-bool-context]
     #define XFS_IFORK_BOFF(ip)  ((int)((ip)->i_d.di_forkoff << 3))
                                 ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    fs/xfs/xfs_bmap_util.c:1620:7: note: in expansion of macro ‘XFS_IFORK_BOFF’
       if (XFS_IFORK_BOFF(ip) &&
           ^~~~~~~~~~~~~~
    fs/xfs/libxfs/xfs_inode_fork.h:90:30: warning: ‘<<’ in boolean context, did you mean ‘<’ ? [-Wint-in-bool-context]
     #define XFS_IFORK_BOFF(ip)  ((int)((ip)->i_d.di_forkoff << 3))
                                 ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    fs/xfs/xfs_bmap_util.c:1630:7: note: in expansion of macro ‘XFS_IFORK_BOFF’
       if (XFS_IFORK_BOFF(tip) &&
           ^~~~~~~~~~~~~~
Quoted 6 lines

This is more or less a false positive, because the useless arithmetic is just the left shift in XFS_IFORK_BOFF(). Use XFS_IFORK_Q() instead to make the warnings go away, while having the same behavior and being more consistent with other places in XFS which also use XFS_IFORK_Q().

Arnd Bergmann already sent the exact same patch[1] for 4.13, but, er, thanks for spotting this! :)

--D

[1] https://marc.info/?l=linux-xfs&m=149498134833721&w=2

Quoted 33 lines
---
 fs/xfs/xfs_bmap_util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/xfs/xfs_bmap_util.c +2 -2
index 7ac80a1facf2..05a6fdf5976d 100644
@@ -1613,7 +1613,7 @@ xfs_swap_extents_check_format(
 	 * extent format...
 	 */
 	if (tip->i_d.di_format == XFS_DINODE_FMT_BTREE) {
-		if (XFS_IFORK_BOFF(ip) &&
+		if (XFS_IFORK_Q(ip) &&
 		    XFS_BMAP_BMDR_SPACE(tip->i_df.if_broot) > XFS_IFORK_BOFF(ip))
 			return -EINVAL;
 		if (XFS_IFORK_NEXTENTS(tip, XFS_DATA_FORK) <=
@@ -1623,7 +1623,7 @@ xfs_swap_extents_check_format(
 
 	/* Reciprocal target->temp btree format checks */
 	if (ip->i_d.di_format == XFS_DINODE_FMT_BTREE) {
-		if (XFS_IFORK_BOFF(tip) &&
+		if (XFS_IFORK_Q(tip) &&
 		    XFS_BMAP_BMDR_SPACE(ip->i_df.if_broot) > XFS_IFORK_BOFF(tip))
 			return -EINVAL;
 		if (XFS_IFORK_NEXTENTS(ip, XFS_DATA_FORK) <=
Signature · 6 lines
2.13.0

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 8 lines · Darrick J. Wong

Arnd Bergmann already sent the exact same patch[1] for 4.13, but, er, thanks for spotting this! :)

--D

[1] https://marc.info/?l=linux-xfs&m=149498134833721&w=2

Oh, okay. I didn't see anything in
git://git.kernel.org/pub/scm/fs/xfs/xfs-linux.git#for-next; I guess it hasn't been pushed out yet.

Eric