xfsprogs: fix covscan issues
v2 cover xfsprogs: fix covscan issues
From: Carlos Maiolino <[email protected]>
Fix a couple of minor issues found by covscan
Carlos Maiolino (2):
xfs_repair: Fix check_refcount() error path
xfs_repair: Fix rmaps_verify_btree() error path
repair/rmap.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/2 xfs_repair: Fix check_refcount() error path
From: Carlos Maiolino <[email protected]>
Add proper exit error paths to avoid checking all pointers at the current path
Fixes-coverity-id: 1512651
---
V2:
- Rename error label from err_agf to err_pag
- pass error directly to libxfs_btree_del_cursor() without using ternary operator
repair/rmap.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
repair/rmap.c +10 -12
@@ -1379,7 +1379,7 @@ check_refcounts(if (error) {do_warn (_ ("Could not read AGF %u to check refcount btree.\n" ), agno); - goto err; + goto err_pag; }/* Leave the per-ag data "uninitialized" since we rewrite it later */
@@ -1388,7 +1388,7 @@ check_refcounts( bt_cur =libxfs_refcountbt_init_cursor (mp,NULL , agbp, pag);if (!bt_cur) {do_warn (_ ("Not enough memory to check refcount data.\n" )); - goto err; + goto err_bt_cur; } rl_rec =pop_slab_cursor (rl_cur);
@@ -1401,7 +1401,7 @@ check_refcounts(do_warn (_ ("Could not read reference count record for (%u/%u).\n" ), agno, rl_rec->rc_startblock); - goto err; + goto err_loop; }if (!have) { do_warn(
@@ -1416,7 +1416,7 @@ _("Missing reference count record for (%u/%u) len %u count %u\n"),do_warn (_ ("Could not read reference count record for (%u/%u).\n" ), agno, rl_rec->rc_startblock); - goto err; + goto err_loop; }if (!i) { do_warn(
@@ -1446,14 +1446,12 @@ next_loop: rl_rec =pop_slab_cursor (rl_cur); } -err: -if (bt_cur) -libxfs_btree_del_cursor (bt_cur, error ?XFS_BTREE_ERROR : -XFS_BTREE_NOERROR ); -if (pag) -libxfs_perag_put (pag); -if (agbp) -libxfs_buf_relse (agbp); +err_loop: +libxfs_btree_del_cursor (bt_cur, error); +err_bt_cur: +libxfs_buf_relse (agbp); +err_pag: +libxfs_perag_put (pag);free_slab_cursor (&rl_cur); }
Signature · 1 line
2.30.2
Re: [PATCH 1/2] xfs_repair: Fix check_refcount() error path
Quoted 64 lines · On Mon, Nov 28, 2022 at 02:14:33PM +0100, [email protected] wrote:
From: Carlos Maiolino <[email protected]>
Add proper exit error paths to avoid checking all pointers at the current path
Fixes-coverity-id: 1512651
Signed-off-by Carlos Maiolino <[email protected]>---
V2:
- Rename error label fromerr_agftoerr_pag
- pass error directly tolibxfs_btree_del_cursor()without using ternary operatorrepair/rmap.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)repair/rmap.c +4
-8@@ -1379,7 +1379,7 @@ check_refcounts(if (error) {do_warn (_ ("Could not read AGF %u to check refcount btree.\n" ), agno); - goto err; + goto err_pag; }/* Leave the per-ag data "uninitialized" since we rewrite it later */ @@ -1388,7 +1388,7 @@ check_refcounts( bt_cur =libxfs_refcountbt_init_cursor (mp,NULL , agbp, pag);if (!bt_cur) {do_warn (_ ("Not enough memory to check refcount data.\n" )); - goto err; + goto err_bt_cur; } rl_rec =pop_slab_cursor (rl_cur);@@ -1401,7 +1401,7 @@ check_refcounts(do_warn (_ ("Could not read reference count record for (%u/%u).\n" ), agno, rl_rec->rc_startblock); - goto err; + goto err_loop; }if (!have) { do_warn(@@ -1416,7 +1416,7 @@ _("Missing reference count record for (%u/%u) len %u count %u\n"),do_warn (_ ("Could not read reference count record for (%u/%u).\n" ), agno, rl_rec->rc_startblock); - goto err; + goto err_loop; }if (!i) { do_warn(@@ -1446,14 +1446,12 @@ next_loop: rl_rec =pop_slab_cursor (rl_cur); } -err: -if (bt_cur) -libxfs_btree_del_cursor (bt_cur, error ?XFS_BTREE_ERROR : -XFS_BTREE_NOERROR );
repair/rmap.c next_loop: · line 1454
Quoted 10 lines
repair/rmap.c +6
-4-if (pag) -libxfs_perag_put (pag); -if (agbp) -libxfs_buf_relse (agbp); +err_loop: +libxfs_btree_del_cursor (bt_cur, error); +err_bt_cur: +libxfs_buf_relse (agbp); +err_pag: +libxfs_perag_put (pag);
So I see that you fixed one of the labels so that err_pag jumps to releasing the perag pointer, but it's still the case that err_bt_cur frees the AGF buffer, not the btree cursor; and that err_loop actually frees the btree cursor.
--D
Quoted 6 lines
repair/rmap.c +0
-0free_slab_cursor (&rl_cur); }Signature · 1 line
2.30.2
Re: [PATCH 1/2] xfs_repair: Fix check_refcount() error path
Quoted 72 lines · Darrick J. Wong
Quoted 71 lines · On Mon, Nov 28, 2022 at 02:14:33PM +0100, [email protected] wrote:
From: Carlos Maiolino <[email protected]>
Add proper exit error paths to avoid checking all pointers at the current path
Fixes-coverity-id: 1512651
Signed-off-by Carlos Maiolino <[email protected]>---
V2:
- Rename error label fromerr_agftoerr_pag
- pass error directly tolibxfs_btree_del_cursor()without using ternary operatorrepair/rmap.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)repair/rmap.c +7
-12@@ -1379,7 +1379,7 @@ check_refcounts(if (error) {do_warn (_ ("Could not read AGF %u to check refcount btree.\n" ), agno); - goto err; + goto err_pag; }/* Leave the per-ag data "uninitialized" since we rewrite it later */ @@ -1388,7 +1388,7 @@ check_refcounts( bt_cur =libxfs_refcountbt_init_cursor (mp,NULL , agbp, pag);if (!bt_cur) {do_warn (_ ("Not enough memory to check refcount data.\n" )); - goto err; + goto err_bt_cur; } rl_rec =pop_slab_cursor (rl_cur);@@ -1401,7 +1401,7 @@ check_refcounts(do_warn (_ ("Could not read reference count record for (%u/%u).\n" ), agno, rl_rec->rc_startblock); - goto err; + goto err_loop; }if (!have) { do_warn(@@ -1416,7 +1416,7 @@ _("Missing reference count record for (%u/%u) len %u count %u\n"),do_warn (_ ("Could not read reference count record for (%u/%u).\n" ), agno, rl_rec->rc_startblock); - goto err; + goto err_loop; }if (!i) { do_warn(@@ -1446,14 +1446,12 @@ next_loop: rl_rec =pop_slab_cursor (rl_cur); } -err: -if (bt_cur) -libxfs_btree_del_cursor (bt_cur, error ?XFS_BTREE_ERROR : -XFS_BTREE_NOERROR ); -if (pag) -libxfs_perag_put (pag); -if (agbp) -libxfs_buf_relse (agbp); +err_loop: +libxfs_btree_del_cursor (bt_cur, error); +err_bt_cur:
Quoted 8 lines
repair/rmap.c next_loop: · line 1454
Quoted 3 lines
repair/rmap.c +3
-0+libxfs_buf_relse (agbp); +err_pag: +libxfs_perag_put (pag);So I see that you fixed one of the labels so that
err_pagjumps to releasing the perag pointer, but it's still the case thaterr_bt_curfrees the AGF buffer, not the btree cursor; and thaterr_loopactually frees the btree cursor.
Totally true. I focused on your comments regarding err_pag, and forgot to review the remaining labels. I'll fix it and send a V3.
Thanks for the review.
Quoted 9 lines
--D
Quoted 6 lines
repair/rmap.c +0
-1free_slab_cursor (&rl_cur); } --2.30.2
Signature · 1 line
Carlos Maiolino
Re: [PATCH 1/2] xfs_repair: Fix check_refcount() error path
Quoted 12 lines
Quoted 11 lines
repair/rmap.c next_loop: · line 1454
Quoted 6 lines
repair/rmap.c +6
-0+err_loop: +libxfs_btree_del_cursor (bt_cur, error); +err_bt_cur: +libxfs_buf_relse (agbp); +err_pag: +libxfs_perag_put (pag);So I see that you fixed one of the labels so that
err_pagjumps to releasing the perag pointer, but it's still the case thaterr_bt_curfrees the AGF buffer, not the btree cursor; and thaterr_loopactually frees the btree cursor.
Quoted 2 lines
Totally true. I focused on your comments regarding
err_pag, and forgot to review the remaining labels. I'll fix it and send a V3.
Just to avoid unnecessary new versions :)
Are the fallowing names ok?
err_curerr_agferr_pag
Could be err_agbp too, but I'd rather be explicit this buffer belongs to the agf.
Quoted 3 lines
Thanks for the review.
Signature · 1 line
Carlos Maiolino
Re: [PATCH 1/2] xfs_repair: Fix check_refcount() error path
Quoted 15 lines · Carlos Maiolino
Quoted 12 lines
Quoted 11 lines
repair/rmap.c next_loop: · line 1454
Quoted 6 lines
repair/rmap.c +6
-0+err_loop: +libxfs_btree_del_cursor (bt_cur, error); +err_bt_cur: +libxfs_buf_relse (agbp); +err_pag: +libxfs_perag_put (pag);So I see that you fixed one of the labels so that
err_pagjumps to releasing the perag pointer, but it's still the case thaterr_bt_curfrees the AGF buffer, not the btree cursor; and thaterr_loopactually frees the btree cursor.Quoted 2 lines
Totally true. I focused on your comments regarding
err_pag, and forgot to review the remaining labels. I'll fix it and send a V3.
Quoted 6 lines
Just to avoid unnecessary new versions :)
Are the fallowing names ok?
err_curerr_agferr_pag
Yes, those are fine. The label names reflect whatever gets cleaned up immediately after the label.
Quoted 2 lines
Could be
err_agbptoo, but I'd rather be explicit this buffer belongs to the agf.
Agreed.
--D
Quoted 7 lines
Quoted 4 lines
Thanks for the review.
Signature · 1 line
Carlos Maiolino
PATCH v2 2/2 xfs_repair: Fix rmaps_verify_btree() error path
In reply to [email protected]From: Carlos Maiolino <[email protected]>
Add proper exit error paths to avoid checking all pointers at the current path
Fixes-coverity-id: 1512654
---
V2:
- Rename error label from err_agf to err_pag
repair/rmap.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
repair/rmap.c +10 -11
@@ -1004,7 +1004,7 @@ rmaps_verify_btree(if (error) {do_warn (_ ("Could not read AGF %u to check rmap btree.\n" ), agno); - goto err; + goto err_pag; }/* Leave the per-ag data "uninitialized" since we rewrite it later */
@@ -1013,7 +1013,7 @@ rmaps_verify_btree( bt_cur =libxfs_rmapbt_init_cursor (mp,NULL , agbp, pag);if (!bt_cur) {do_warn (_ ("Not enough memory to check reverse mappings.\n" )); - goto err; + goto err_bt_cur; } rm_rec =pop_slab_cursor (rm_cur);
@@ -1023,7 +1023,7 @@ rmaps_verify_btree(do_warn (_ ("Could not read reverse-mapping record for (%u/%u).\n" ), agno, rm_rec->rm_startblock); - goto err; + goto err_loop; }/*
@@ -1039,7 +1039,7 @@ _("Could not read reverse-mapping record for (%u/%u).\n"),do_warn (_ ("Could not read reverse-mapping record for (%u/%u).\n" ), agno, rm_rec->rm_startblock); - goto err; + goto err_loop; } }if (!have) {
@@ -1090,13 +1090,12 @@ next_loop: rm_rec =pop_slab_cursor (rm_cur); } -err: -if (bt_cur) -libxfs_btree_del_cursor (bt_cur,XFS_BTREE_NOERROR ); -if (pag) -libxfs_perag_put (pag); -if (agbp) -libxfs_buf_relse (agbp); +err_loop: +libxfs_btree_del_cursor (bt_cur,XFS_BTREE_NOERROR ); +err_bt_cur: +libxfs_buf_relse (agbp); +err_pag: +libxfs_perag_put (pag);free_slab_cursor (&rm_cur); }
Signature · 1 line
2.30.2