Skip to contentSkip to conversation

xfs: initialize error in xfs_getfsmap_rtdev_rtbitmap()

PATCH In review Ian Rogers 3 participants 3 messages Nov 19 – Nov 20 XFS filesystem

lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

PATCH 1/1 xfs: initialize error in xfs_getfsmap_rtdev_rtbitmap()

When xfs_getfsmap_rtdev_rtbitmap() was converted to iterate over realtime groups with xfs_rtgroup_next_range(), 'error' was left uninitialized. If a continuation or range-bounded FS_IOC_GETFSMAP query has start_rgno > end_rgno (for example when keys[0].fmr_physical + keys[0].fmr_length lies in a higher realtime group than keys[1].fmr_physical while both remain below eofs), the while loop executes zero iterations and returns the uninitialized stack variable 'error' directly to userspace as the ioctl() return value.

Initialize 'error' to 0, matching xfs_getfsmap_rtdev_rmapbt().

Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with -Wconditional-uninitialized enabled; fix and changelog drafted with an AI coding assistant. Build-tested with LLVM=1 W=1 and -Wconditional-uninitialized; not runtime-tested on a live XFS realtime filesystem.

Fixes e3088ae2dcae ("xfs: move RT bitmap and summary information to the rtgroup")
---
 fs/xfs/xfs_fsmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_fsmap.c +1 -1
index 041bb2105ec6..3ccf3ce23332 100644
@@ -760,7 +760,7 @@ xfs_getfsmap_rtdev_rtbitmap(
 	xfs_rgnumber_t			start_rgno, end_rgno;
 	struct xfs_rtgroup		*rtg = NULL;
 	uint64_t			eofs;
-	int				error;
+	int				error = 0;
 
 	eofs = XFS_FSB_TO_BB(mp, mp->m_sb.sb_rblocks);
 	if (keys[0].fmr_physical >= eofs)
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Ian Rogers

When xfs_getfsmap_rtdev_rtbitmap() was converted to iterate over realtime groups with xfs_rtgroup_next_range(), 'error' was left uninitialized. If a continuation or range-bounded FS_IOC_GETFSMAP query has start_rgno > end_rgno (for example when keys[0].fmr_physical + keys[0].fmr_length lies in a higher realtime group than keys[1].fmr_physical while both remain below eofs), the while loop executes zero iterations and returns the uninitialized stack variable 'error' directly to userspace as the ioctl() return value.

Initialize 'error' to 0, matching xfs_getfsmap_rtdev_rmapbt().

Quoted 8 lines

Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with -Wconditional-uninitialized enabled; fix and changelog drafted with an AI coding assistant. Build-tested with LLVM=1 W=1 and -Wconditional-uninitialized; not runtime-tested on a live XFS realtime filesystem.

Fixes e3088ae2dcae ("xfs: move RT bitmap and summary information to the rtgroup")

This looks right to me. Returning "nothing, successfull, with error 0" is correct. xfs_rtgroup_next_range() also cannot return an error that must be captured. There might be weird subtleties if we ever get shrink going, but for now this looks correct, thanks.

Quoted 17 lines
---
 fs/xfs/xfs_fsmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_fsmap.c +1 -1
index 041bb2105ec6..3ccf3ce23332 100644
@@ -760,7 +760,7 @@ xfs_getfsmap_rtdev_rtbitmap(
 	xfs_rgnumber_t			start_rgno, end_rgno;
 	struct xfs_rtgroup		*rtg = NULL;
 	uint64_t			eofs;
-	int				error;
+	int				error = 0;
 
 	eofs = XFS_FSB_TO_BB(mp, mp->m_sb.sb_rblocks);
 	if (keys[0].fmr_physical >= eofs)