* [PATCH v2 0/2] xfs: Clear a W=1 warning and some __maybe_unused usage
@ 2024-05-02 10:08 John Garry
2024-05-02 10:08 ` [PATCH v2 1/2] xfs: Clear W=1 warning in xfs_iwalk_run_callbacks() John Garry
2024-05-02 10:08 ` [PATCH v2 2/2] xfs: Stop using __maybe_unused in xfs_alloc.c John Garry
0 siblings, 2 replies; 5+ messages in thread
From: John Garry @ 2024-05-02 10:08 UTC (permalink / raw)
To: chandan.babu, dchinner, djwong, hch; +Cc: linux-xfs, John Garry
For configs XFS_DEBUG and XFS_WARN disabled, for a W=1 build
xfs_iwalk_run_callbacks() generates a warning for unused variable. Clean
that up.
Also remove __maybe_unused usage in xfs_alloc.c, which is for protecting
against the same type of warning.
John Garry (2):
xfs: Clear W=1 warning in xfs_iwalk_run_callbacks()
xfs: Stop using __maybe_unused in xfs_alloc.c
fs/xfs/libxfs/xfs_alloc.c | 6 ++----
fs/xfs/xfs_iwalk.c | 5 ++---
2 files changed, 4 insertions(+), 7 deletions(-)
--
2.31.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] xfs: Clear W=1 warning in xfs_iwalk_run_callbacks()
2024-05-02 10:08 [PATCH v2 0/2] xfs: Clear a W=1 warning and some __maybe_unused usage John Garry
@ 2024-05-02 10:08 ` John Garry
2024-05-02 12:48 ` Christoph Hellwig
2024-05-02 10:08 ` [PATCH v2 2/2] xfs: Stop using __maybe_unused in xfs_alloc.c John Garry
1 sibling, 1 reply; 5+ messages in thread
From: John Garry @ 2024-05-02 10:08 UTC (permalink / raw)
To: chandan.babu, dchinner, djwong, hch; +Cc: linux-xfs, John Garry
For CONFIG_XFS_DEBUG unset, xfs_iwalk_run_callbacks() generates the
following warning for when building with W=1:
fs/xfs/xfs_iwalk.c: In function ‘xfs_iwalk_run_callbacks’:
fs/xfs/xfs_iwalk.c:354:42: error: variable ‘irec’ set but not used [-Werror=unused-but-set-variable]
354 | struct xfs_inobt_rec_incore *irec;
| ^~~~
cc1: all warnings being treated as errors
Drop @irec, as it is only an intermediate variable.
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
fs/xfs/xfs_iwalk.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/fs/xfs/xfs_iwalk.c b/fs/xfs/xfs_iwalk.c
index 730c8d48da28..86f14ec7c31f 100644
--- a/fs/xfs/xfs_iwalk.c
+++ b/fs/xfs/xfs_iwalk.c
@@ -351,7 +351,6 @@ xfs_iwalk_run_callbacks(
int *has_more)
{
struct xfs_mount *mp = iwag->mp;
- struct xfs_inobt_rec_incore *irec;
xfs_agino_t next_agino;
int error;
@@ -361,8 +360,8 @@ xfs_iwalk_run_callbacks(
/* Delete cursor but remember the last record we cached... */
xfs_iwalk_del_inobt(iwag->tp, curpp, agi_bpp, 0);
- irec = &iwag->recs[iwag->nr_recs - 1];
- ASSERT(next_agino >= irec->ir_startino + XFS_INODES_PER_CHUNK);
+ ASSERT(next_agino >= iwag->recs[iwag->nr_recs - 1].ir_startino +
+ XFS_INODES_PER_CHUNK);
if (iwag->drop_trans) {
xfs_trans_cancel(iwag->tp);
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] xfs: Stop using __maybe_unused in xfs_alloc.c
2024-05-02 10:08 [PATCH v2 0/2] xfs: Clear a W=1 warning and some __maybe_unused usage John Garry
2024-05-02 10:08 ` [PATCH v2 1/2] xfs: Clear W=1 warning in xfs_iwalk_run_callbacks() John Garry
@ 2024-05-02 10:08 ` John Garry
2024-05-02 12:48 ` Christoph Hellwig
1 sibling, 1 reply; 5+ messages in thread
From: John Garry @ 2024-05-02 10:08 UTC (permalink / raw)
To: chandan.babu, dchinner, djwong, hch; +Cc: linux-xfs, John Garry
In both xfs_alloc_cur_finish() and xfs_alloc_ag_vextent_exact(), local
variable @afg is tagged as __maybe_unused. Otherwise an unused variable
warning would be generated for when building with W=1 and CONFIG_XFS_DEBUG
unset. In both cases, the variable is unused as it is only referenced in
an ASSERT() call, which is compiled out (in this config).
It is generally a poor programming style to use __maybe_unused for
variables.
The ASSERT() call is to verify that agbno of the end of the extent is
within bounds for both functions. @afg is used as an intermediate variable
to find the AG length.
However xfs_verify_agbext() already exists to verify a valid extent range.
The arguments for calling xfs_verify_agbext() are already available, so use
that instead.
An advantage of using xfs_verify_agbext() is that it verifies that both the
start and the end of the extent are within the bounds of the AG and
catches overflows.
Suggested-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
fs/xfs/libxfs/xfs_alloc.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
index 6cb8b2ddc541..6c55a6e88eba 100644
--- a/fs/xfs/libxfs/xfs_alloc.c
+++ b/fs/xfs/libxfs/xfs_alloc.c
@@ -1008,13 +1008,12 @@ xfs_alloc_cur_finish(
struct xfs_alloc_arg *args,
struct xfs_alloc_cur *acur)
{
- struct xfs_agf __maybe_unused *agf = args->agbp->b_addr;
int error;
ASSERT(acur->cnt && acur->bnolt);
ASSERT(acur->bno >= acur->rec_bno);
ASSERT(acur->bno + acur->len <= acur->rec_bno + acur->rec_len);
- ASSERT(acur->rec_bno + acur->rec_len <= be32_to_cpu(agf->agf_length));
+ ASSERT(xfs_verify_agbext(args->pag, acur->rec_bno, acur->rec_len));
error = xfs_alloc_fixup_trees(acur->cnt, acur->bnolt, acur->rec_bno,
acur->rec_len, acur->bno, acur->len, 0);
@@ -1217,7 +1216,6 @@ STATIC int /* error */
xfs_alloc_ag_vextent_exact(
xfs_alloc_arg_t *args) /* allocation argument structure */
{
- struct xfs_agf __maybe_unused *agf = args->agbp->b_addr;
struct xfs_btree_cur *bno_cur;/* by block-number btree cursor */
struct xfs_btree_cur *cnt_cur;/* by count btree cursor */
int error;
@@ -1297,7 +1295,7 @@ xfs_alloc_ag_vextent_exact(
*/
cnt_cur = xfs_cntbt_init_cursor(args->mp, args->tp, args->agbp,
args->pag);
- ASSERT(args->agbno + args->len <= be32_to_cpu(agf->agf_length));
+ ASSERT(xfs_verify_agbext(args->pag, args->agbno, args->len));
error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen, args->agbno,
args->len, XFSA_FIXUP_BNO_OK);
if (error) {
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] xfs: Clear W=1 warning in xfs_iwalk_run_callbacks()
2024-05-02 10:08 ` [PATCH v2 1/2] xfs: Clear W=1 warning in xfs_iwalk_run_callbacks() John Garry
@ 2024-05-02 12:48 ` Christoph Hellwig
0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2024-05-02 12:48 UTC (permalink / raw)
To: John Garry; +Cc: chandan.babu, dchinner, djwong, hch, linux-xfs
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] xfs: Stop using __maybe_unused in xfs_alloc.c
2024-05-02 10:08 ` [PATCH v2 2/2] xfs: Stop using __maybe_unused in xfs_alloc.c John Garry
@ 2024-05-02 12:48 ` Christoph Hellwig
0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2024-05-02 12:48 UTC (permalink / raw)
To: John Garry; +Cc: chandan.babu, dchinner, djwong, hch, linux-xfs
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-05-02 12:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-02 10:08 [PATCH v2 0/2] xfs: Clear a W=1 warning and some __maybe_unused usage John Garry
2024-05-02 10:08 ` [PATCH v2 1/2] xfs: Clear W=1 warning in xfs_iwalk_run_callbacks() John Garry
2024-05-02 12:48 ` Christoph Hellwig
2024-05-02 10:08 ` [PATCH v2 2/2] xfs: Stop using __maybe_unused in xfs_alloc.c John Garry
2024-05-02 12:48 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox