Skip to content

Commit b33874f

Browse files
johnpgarryChandan Babu R
authored andcommitted
xfs: Stop using __maybe_unused in xfs_alloc.c
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>
1 parent d7ba701 commit b33874f

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

fs/xfs/libxfs/xfs_alloc.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,13 +1008,12 @@ xfs_alloc_cur_finish(
10081008
struct xfs_alloc_arg *args,
10091009
struct xfs_alloc_cur *acur)
10101010
{
1011-
struct xfs_agf __maybe_unused *agf = args->agbp->b_addr;
10121011
int error;
10131012

10141013
ASSERT(acur->cnt && acur->bnolt);
10151014
ASSERT(acur->bno >= acur->rec_bno);
10161015
ASSERT(acur->bno + acur->len <= acur->rec_bno + acur->rec_len);
1017-
ASSERT(acur->rec_bno + acur->rec_len <= be32_to_cpu(agf->agf_length));
1016+
ASSERT(xfs_verify_agbext(args->pag, acur->rec_bno, acur->rec_len));
10181017

10191018
error = xfs_alloc_fixup_trees(acur->cnt, acur->bnolt, acur->rec_bno,
10201019
acur->rec_len, acur->bno, acur->len, 0);
@@ -1217,7 +1216,6 @@ STATIC int /* error */
12171216
xfs_alloc_ag_vextent_exact(
12181217
xfs_alloc_arg_t *args) /* allocation argument structure */
12191218
{
1220-
struct xfs_agf __maybe_unused *agf = args->agbp->b_addr;
12211219
struct xfs_btree_cur *bno_cur;/* by block-number btree cursor */
12221220
struct xfs_btree_cur *cnt_cur;/* by count btree cursor */
12231221
int error;
@@ -1297,7 +1295,7 @@ xfs_alloc_ag_vextent_exact(
12971295
*/
12981296
cnt_cur = xfs_cntbt_init_cursor(args->mp, args->tp, args->agbp,
12991297
args->pag);
1300-
ASSERT(args->agbno + args->len <= be32_to_cpu(agf->agf_length));
1298+
ASSERT(xfs_verify_agbext(args->pag, args->agbno, args->len));
13011299
error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen, args->agbno,
13021300
args->len, XFSA_FIXUP_BNO_OK);
13031301
if (error) {

0 commit comments

Comments
 (0)