diff --git a/fs/jfs/jfs_extent.c b/fs/jfs/jfs_extent.c
index ae99a7e232ee..68307e686d8d 100644
--- a/fs/jfs/jfs_extent.c
+++ b/fs/jfs/jfs_extent.c
@@ -311,7 +311,11 @@ extBalloc(struct inode *ip, s64 hint, s64 * nblocks, s64 * blkno)
 	 * blocks in the map. in that case, we'll start off with the
 	 * maximum free.
 	 */
-	max = (s64) 1 << bmp->db_maxfreebud;
+	if (bmp->db_maxfreebud < 0) {
+		max = 0;
+	} else {
+		max = (s64) 1 << bmp->db_maxfreebud;
+	}
 	if (*nblocks >= max && *nblocks > nbperpage)
 		nb = nblks = (max > nbperpage) ? max : nbperpage;
 	else
diff --git a/fs/jfs/jfs_xtree.c b/fs/jfs/jfs_xtree.c
index 2d304cee884c..6fd6ff1fd1cf 100644
--- a/fs/jfs/jfs_xtree.c
+++ b/fs/jfs/jfs_xtree.c
@@ -542,6 +542,10 @@ int xtInsert(tid_t tid,		/* transaction id */
 		return rc;
 
 	/* retrieve search result */
+	if (btstack.top->index > XTROOTMAXSLOT) {
+		rc = -ENOMEM;
+		return rc;
+	}
 	XT_GETSEARCH(ip, btstack.top, bn, mp, p, index);
 
 	/* This test must follow XT_GETSEARCH since mp must be valid if