]> git.apps.os.sepia.ceph.com Git - xfsprogs-dev.git/commitdiff
xfs: Stop using __maybe_unused in xfs_alloc.c
authorJohn Garry <john.g.garry@oracle.com>
Mon, 29 Jul 2024 23:22:57 +0000 (16:22 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:01:05 +0000 (17:01 -0700)
Source kernel commit: b33874fb7f28326380562f208d948bab785fbd6f

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>
libxfs/xfs_alloc.c

index b86f788f45ed0872f3a1447759cffb793858d168..45feff0343365dfaa1ac381126de9fe34f85b095 100644 (file)
@@ -1004,13 +1004,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);
@@ -1213,7 +1212,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;
@@ -1293,7 +1291,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) {