diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c index cb3cda1390ad..c67ff5df0340 100644 --- a/fs/jfs/jfs_dmap.c +++ b/fs/jfs/jfs_dmap.c @@ -2142,6 +2142,12 @@ static void dbAllocBits(struct bmap * bmp, struct dmap * dp, s64 blkno, int size; s8 *leaf; + agno = blkno >> bmp->db_agl2size; + if (agno < 0 || agno >= MAXAG) { + jfs_error(bmp->db_ipbmap->i_sb, "%s: agno %d out of range\n", __func__, agno); + return; + } + /* pick up a pointer to the leaves of the dmap tree */ leaf = dp->tree.stree + LEAFIND; @@ -2289,6 +2295,12 @@ static int dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno, int rc = 0; int size; + agno = blkno >> bmp->db_agl2size; + if (agno < 0 || agno >= MAXAG) { + jfs_error(bmp->db_ipbmap->i_sb, "%s: agno %d out of range\n", __func__, agno); + return -EIO; + } + /* determine the bit number and word within the dmap of the * starting block. */