On Mon, Apr 08, 2024 at 04:54:50PM +0200, Christoph Hellwig wrote: > XFS_FILBLKS_MIN uses min_t and thus does the comparison using the correct > xfs_filblks_t type. Use it in xfs_bmapi_write and slightly adjust the > comment document th potential pitfall to take account of this > > Signed-off-by: Christoph Hellwig <hch@xxxxxx> Pretty straightforward conversion, Reviewed-by: Darrick J. Wong <djwong@xxxxxxxxxx> --D > --- > fs/xfs/libxfs/xfs_bmap.c | 9 +++------ > 1 file changed, 3 insertions(+), 6 deletions(-) > > diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c > index 3b5816de4af2a1..f2e934c2fb423c 100644 > --- a/fs/xfs/libxfs/xfs_bmap.c > +++ b/fs/xfs/libxfs/xfs_bmap.c > @@ -4537,14 +4537,11 @@ xfs_bmapi_write( > * allocation length request (which can be 64 bits in > * length) and the bma length request, which is > * xfs_extlen_t and therefore 32 bits. Hence we have to > - * check for 32-bit overflows and handle them here. > + * be careful and do the min() using the larger type to > + * avoid overflows. > */ > - if (len > (xfs_filblks_t)XFS_MAX_BMBT_EXTLEN) > - bma.length = XFS_MAX_BMBT_EXTLEN; > - else > - bma.length = len; > + bma.length = XFS_FILBLKS_MIN(len, XFS_MAX_BMBT_EXTLEN); > > - ASSERT(len > 0); > ASSERT(bma.length > 0); > error = xfs_bmapi_allocate(&bma); > if (error) { > -- > 2.39.2 > >