VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   32 Branches   54 Tags
author: Ritesh Harjani <riteshh@linux.ibm.com> 2021-03-09 09:29:11 -0800 committer: Darrick J. Wong <djwong@djwong.org> 2021-03-09 09:29:11 -0800 commit: 5808fecc572391867fcd929662b29c12e6d08d81 parent: a38fd8748464831584a19438cbb3082b5a2dab15
Commit Summary:
iomap: Fix negative assignment to unsigned sis->pages in iomap_swapfile_activate
Diffstat:
1 file changed, 10 insertions, 0 deletions
diff --git a/fs/iomap/swapfile.c b/fs/iomap/swapfile.c
index a648dbf6991e..a5e478de1417 100644
--- a/fs/iomap/swapfile.c
+++ b/fs/iomap/swapfile.c
@@ -170,6 +170,16 @@ int iomap_swapfile_activate(struct swap_info_struct *sis,
 			return ret;
 	}
 
+	/*
+	 * If this swapfile doesn't contain even a single page-aligned
+	 * contiguous range of blocks, reject this useless swapfile to
+	 * prevent confusion later on.
+	 */
+	if (isi.nr_pages == 0) {
+		pr_warn("swapon: Cannot find a single usable page in file.\n");
+		return -EINVAL;
+	}
+
 	*pagespan = 1 + isi.highest_ppage - isi.lowest_ppage;
 	sis->max = isi.nr_pages;
 	sis->pages = isi.nr_pages - 1;