Skip to contentSkip to conversation

xfs: scrub: avoid uninitialized return code

PATCH In review Arnd Bergmann 3 participants 6 messages Nov 2, 2017 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 xfs: scrub: avoid uninitialized return code

The newly added xfs_scrub_da_btree_block() function has one code path that returns the 'error' variable without initializing it first, as shown by this compiler warning:

fs/xfs/scrub/dabtree.c: In function 'xfs_scrub_da_btree_block':
fs/xfs/scrub/dabtree.c:462:9: error: 'error' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Returning -EINVAL might be an appropriate return code in this case.

Fixes 7c4a07a424c1 ("xfs: scrub directory/attribute btrees")
---
 fs/xfs/scrub/dabtree.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/xfs/scrub/dabtree.c +3 -1
index 4a93cf1753d3..971566388c9a 100644
@@ -349,8 +349,10 @@ xfs_scrub_da_btree_block(
 
 	/* Check the pointer. */
 	blk->blkno = blkno;
-	if (!xfs_scrub_da_btree_ptr_ok(ds, level, blkno))
+	if (!xfs_scrub_da_btree_ptr_ok(ds, level, blkno)) {
+		error = -EINVAL;
 		goto out_nobuf;
+	}
 
 	/* Read the buffer. */
 	error = xfs_da_read_buf(dargs->trans, dargs->dp, blk->blkno, -2,
Signature · 1 line
2.9.0
#1 lore raw

PATCH 2/2 xfs: fix unused variable warnings

fs/xfs/libxfs/xfs_bmap.c: In function 'xfs_bmap_del_extent_delay':
fs/xfs/libxfs/xfs_bmap.c:4648:20: error: unused variable 'ifp' [-Werror=unused-variable]

  struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
                    ^~~

fs/xfs/libxfs/xfs_bmap.c: In function 'xfs_bmap_del_extent_cow':
fs/xfs/libxfs/xfs_bmap.c:4776:20: error: unused variable 'ifp' [-Werror=unused-variable]

Fixes ca5d8e5b7b90 ("xfs: move pre/post-bmap tracing into xfs_iext_update_extent")
---
 fs/xfs/libxfs/xfs_bmap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +2 -4
index f45f05c45e15..fa85b08b8fe2 100644
@@ -4645,7 +4645,6 @@ xfs_bmap_del_extent_delay(
 	struct xfs_bmbt_irec	*del)
 {
 	struct xfs_mount	*mp = ip->i_mount;
-	struct xfs_ifork	*ifp = XFS_IFORK_PTR(ip, whichfork);
 	struct xfs_bmbt_irec	new;
 	int64_t			da_old, da_new, da_diff = 0;
 	xfs_fileoff_t		del_endoff, got_endoff;
@@ -4663,7 +4662,7 @@ xfs_bmap_del_extent_delay(
 	da_new = 0;
 
 	ASSERT(*idx >= 0);
-	ASSERT(*idx <= xfs_iext_count(ifp));
+	ASSERT(*idx <= xfs_iext_count(XFS_IFORK_PTR(ip, whichfork)));
 	ASSERT(del->br_blockcount > 0);
 	ASSERT(got->br_startoff <= del->br_startoff);
 	ASSERT(got_endoff >= del_endoff);
@@ -4773,7 +4772,6 @@ xfs_bmap_del_extent_cow(
 	struct xfs_bmbt_irec	*del)
 {
 	struct xfs_mount	*mp = ip->i_mount;
-	struct xfs_ifork	*ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK);
 	struct xfs_bmbt_irec	new;
 	xfs_fileoff_t		del_endoff, got_endoff;
 	int			state = BMAP_COWFORK;
@@ -4784,7 +4782,7 @@ xfs_bmap_del_extent_cow(
 	got_endoff = got->br_startoff + got->br_blockcount;
 
 	ASSERT(*idx >= 0);
-	ASSERT(*idx <= xfs_iext_count(ifp));
+	ASSERT(*idx <= xfs_iext_count(XFS_IFORK_PTR(ip, XFS_COW_FORK)));
 	ASSERT(del->br_blockcount > 0);
 	ASSERT(got->br_startoff <= del->br_startoff);
 	ASSERT(got_endoff >= del_endoff);
Signature · 1 line
2.9.0
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] xfs: fix unused variable warnings

Quoted 10 lines · Arnd Bergmann

fs/xfs/libxfs/xfs_bmap.c: In function 'xfs_bmap_del_extent_delay':
fs/xfs/libxfs/xfs_bmap.c:4648:20: error: unused variable 'ifp' [-Werror=unused-variable]

  struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
                    ^~~

fs/xfs/libxfs/xfs_bmap.c: In function 'xfs_bmap_del_extent_cow':
fs/xfs/libxfs/xfs_bmap.c:4776:20: error: unused variable 'ifp' [-Werror=unused-variable]

Fixes ca5d8e5b7b90 ("xfs: move pre/post-bmap tracing into xfs_iext_update_extent")

---

Thanks for sending this:

Quoted 48 lines
 fs/xfs/libxfs/xfs_bmap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +2 -4
index f45f05c45e15..fa85b08b8fe2 100644
@@ -4645,7 +4645,6 @@ xfs_bmap_del_extent_delay(
 	struct xfs_bmbt_irec	*del)
 {
 	struct xfs_mount	*mp = ip->i_mount;
-	struct xfs_ifork	*ifp = XFS_IFORK_PTR(ip, whichfork);
 	struct xfs_bmbt_irec	new;
 	int64_t			da_old, da_new, da_diff = 0;
 	xfs_fileoff_t		del_endoff, got_endoff;
@@ -4663,7 +4662,7 @@ xfs_bmap_del_extent_delay(
 	da_new = 0;
 
 	ASSERT(*idx >= 0);
-	ASSERT(*idx <= xfs_iext_count(ifp));
+	ASSERT(*idx <= xfs_iext_count(XFS_IFORK_PTR(ip, whichfork)));
 	ASSERT(del->br_blockcount > 0);
 	ASSERT(got->br_startoff <= del->br_startoff);
 	ASSERT(got_endoff >= del_endoff);
@@ -4773,7 +4772,6 @@ xfs_bmap_del_extent_cow(
 	struct xfs_bmbt_irec	*del)
 {
 	struct xfs_mount	*mp = ip->i_mount;
-	struct xfs_ifork	*ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK);
 	struct xfs_bmbt_irec	new;
 	xfs_fileoff_t		del_endoff, got_endoff;
 	int			state = BMAP_COWFORK;
@@ -4784,7 +4782,7 @@ xfs_bmap_del_extent_cow(
 	got_endoff = got->br_startoff + got->br_blockcount;
 
 	ASSERT(*idx >= 0);
-	ASSERT(*idx <= xfs_iext_count(ifp));
+	ASSERT(*idx <= xfs_iext_count(XFS_IFORK_PTR(ip, XFS_COW_FORK)));
 	ASSERT(del->br_blockcount > 0);
 	ASSERT(got->br_startoff <= del->br_startoff);
 	ASSERT(got_endoff >= del_endoff);
Signature · 6 lines
2.9.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
#3 lore raw

Re: [PATCH 2/2] xfs: fix unused variable warnings

Quoted 8 lines · Brian Foster
Quoted 7 lines · Arnd Bergmann

fs/xfs/libxfs/xfs_bmap.c: In function 'xfs_bmap_del_extent_delay':
fs/xfs/libxfs/xfs_bmap.c:4648:20: error: unused variable 'ifp' [-Werror=unused-variable]

  struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
                    ^~~

fs/xfs/libxfs/xfs_bmap.c: In function 'xfs_bmap_del_extent_cow':
fs/xfs/libxfs/xfs_bmap.c:4776:20: error: unused variable 'ifp' [-Werror=unused-variable]

Christoph's subsequent patch series to reimplement the incore extent map starts using ifp for more than just the ASSERT, so I'll take this patch if that rework doesn't land in time for 4.15.

--D

Quoted 60 lines
Quoted 3 lines
Fixes ca5d8e5b7b90 ("xfs: move pre/post-bmap tracing into xfs_iext_update_extent")

---

Thanks for sending this:

Quoted 48 lines
 fs/xfs/libxfs/xfs_bmap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +2 -4
index f45f05c45e15..fa85b08b8fe2 100644
@@ -4645,7 +4645,6 @@ xfs_bmap_del_extent_delay(
 	struct xfs_bmbt_irec	*del)
 {
 	struct xfs_mount	*mp = ip->i_mount;
-	struct xfs_ifork	*ifp = XFS_IFORK_PTR(ip, whichfork);
 	struct xfs_bmbt_irec	new;
 	int64_t			da_old, da_new, da_diff = 0;
 	xfs_fileoff_t		del_endoff, got_endoff;
@@ -4663,7 +4662,7 @@ xfs_bmap_del_extent_delay(
 	da_new = 0;
 
 	ASSERT(*idx >= 0);
-	ASSERT(*idx <= xfs_iext_count(ifp));
+	ASSERT(*idx <= xfs_iext_count(XFS_IFORK_PTR(ip, whichfork)));
 	ASSERT(del->br_blockcount > 0);
 	ASSERT(got->br_startoff <= del->br_startoff);
 	ASSERT(got_endoff >= del_endoff);
@@ -4773,7 +4772,6 @@ xfs_bmap_del_extent_cow(
 	struct xfs_bmbt_irec	*del)
 {
 	struct xfs_mount	*mp = ip->i_mount;
-	struct xfs_ifork	*ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK);
 	struct xfs_bmbt_irec	new;
 	xfs_fileoff_t		del_endoff, got_endoff;
 	int			state = BMAP_COWFORK;
@@ -4784,7 +4782,7 @@ xfs_bmap_del_extent_cow(
 	got_endoff = got->br_startoff + got->br_blockcount;
 
 	ASSERT(*idx >= 0);
-	ASSERT(*idx <= xfs_iext_count(ifp));
+	ASSERT(*idx <= xfs_iext_count(XFS_IFORK_PTR(ip, XFS_COW_FORK)));
 	ASSERT(del->br_blockcount > 0);
 	ASSERT(got->br_startoff <= del->br_startoff);
 	ASSERT(got_endoff >= del_endoff);
Signature · 6 lines
2.9.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

--
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

#4 lore raw
In reply to Arnd Bergmann
Quoted 20 lines · Arnd Bergmann

The newly added xfs_scrub_da_btree_block() function has one code path that returns the 'error' variable without initializing it first, as shown by this compiler warning:

fs/xfs/scrub/dabtree.c: In function 'xfs_scrub_da_btree_block':
fs/xfs/scrub/dabtree.c:462:9: error: 'error' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Returning -EINVAL might be an appropriate return code in this case.

Fixes 7c4a07a424c1 ("xfs: scrub directory/attribute btrees")
---
 fs/xfs/scrub/dabtree.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/xfs/scrub/dabtree.c +0 -0
index 4a93cf1753d3..971566388c9a 100644

fs/xfs/scrub/dabtree.c xfs_scrub_da_btree_block( · line 355

Quoted 8 lines
fs/xfs/scrub/dabtree.c +3 -1
@@ -349,8 +349,10 @@ xfs_scrub_da_btree_block(
 
 	/* Check the pointer. */
 	blk->blkno = blkno;
-	if (!xfs_scrub_da_btree_ptr_ok(ds, level, blkno))
+	if (!xfs_scrub_da_btree_ptr_ok(ds, level, blkno)) {
+		error = -EINVAL;
 		goto out_nobuf;
+	}

Hmm.. is an error really the right thing to do here vs. setting the context corrupt and returning 0? (Darrick..?) If the latter, perhaps error should just be initialized to 0.

Brian

Quoted 10 lines
fs/xfs/scrub/dabtree.c +0 -0
 	/* Read the buffer. */
 	error = xfs_da_read_buf(dargs->trans, dargs->dp, blk->blkno, -2,
Signature · 6 lines
2.9.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
#5 lore raw
Quoted 22 lines · Brian Foster
Quoted 21 lines · Arnd Bergmann

The newly added xfs_scrub_da_btree_block() function has one code path that returns the 'error' variable without initializing it first, as shown by this compiler warning:

fs/xfs/scrub/dabtree.c: In function 'xfs_scrub_da_btree_block':
fs/xfs/scrub/dabtree.c:462:9: error: 'error' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Returning -EINVAL might be an appropriate return code in this case.

Fixes 7c4a07a424c1 ("xfs: scrub directory/attribute btrees")
---
 fs/xfs/scrub/dabtree.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/xfs/scrub/dabtree.c +0 -0
index 4a93cf1753d3..971566388c9a 100644
@@ -349,8 +349,10 @@ xfs_scrub_da_btree_block(
 
Quoted 11 lines

fs/xfs/scrub/dabtree.c xfs_scrub_da_btree_block( · line 355

Quoted 7 lines
fs/xfs/scrub/dabtree.c +3 -1
 	/* Check the pointer. */
 	blk->blkno = blkno;
-	if (!xfs_scrub_da_btree_ptr_ok(ds, level, blkno))
+	if (!xfs_scrub_da_btree_ptr_ok(ds, level, blkno)) {
+		error = -EINVAL;
 		goto out_nobuf;
+	}

Hmm.. is an error really the right thing to do here vs. setting the context corrupt and returning 0? (Darrick..?) If the latter, perhaps error should just be initialized to 0.

Yes, zero. We return from this function with a NULL blks[level]->bp (and the corrupt flag set) so the caller (xfs_scrub_da_btree) will return.

--D

Quoted 17 lines

Brian

Quoted 10 lines
fs/xfs/scrub/dabtree.c +0 -0
 	/* Read the buffer. */
 	error = xfs_da_read_buf(dargs->trans, dargs->dp, blk->blkno, -2,
Signature · 6 lines
2.9.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

--
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