xfs: Stop using __maybe_unused in xfs_alloc.c
authorJohn Garry <john.g.garry@oracle.com>
Thu, 2 May 2024 10:08:26 +0000 (10:08 +0000)
committerChandan Babu R <chandanbabu@kernel.org>
Mon, 27 May 2024 10:24:24 +0000 (15:54 +0530)
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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
fs/xfs/libxfs/xfs_alloc.c

index 6cb8b2ddc541b4b28d553ffee414b903725e97f8..6c55a6e88eba3ffb8ac76803b2b14ea03b45b467 100644 (file)
@@ -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) {