Commit 858a2990 authored by Hugh Dickins's avatar Hugh Dickins Committed by Linus Torvalds

swapfile: change discard pgoff_t to sector_t

Change pgoff_t nr_blocks in discard_swap() and discard_swap_cluster() to
sector_t: given the constraints on swap offsets (in particular, the 5 bits
of swap type accommodated in the same unsigned long), pgoff_t was actually
safe as is, but it certainly looked worrying when shifted left.

[akpm@linux-foundation.org: fix shift overflow]
Signed-off-by: default avatarHugh Dickins <hugh@veritas.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Jens Axboe <jens.axboe@oracle.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Joern Engel <joern@logfs.org>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Donjun Shin <djshin90@gmail.com>
Cc: Tejun Heo <teheo@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent c60aa176
...@@ -96,7 +96,7 @@ static int discard_swap(struct swap_info_struct *si) ...@@ -96,7 +96,7 @@ static int discard_swap(struct swap_info_struct *si)
list_for_each_entry(se, &si->extent_list, list) { list_for_each_entry(se, &si->extent_list, list) {
sector_t start_block = se->start_block << (PAGE_SHIFT - 9); sector_t start_block = se->start_block << (PAGE_SHIFT - 9);
pgoff_t nr_blocks = se->nr_pages << (PAGE_SHIFT - 9); sector_t nr_blocks = (sector_t)se->nr_pages << (PAGE_SHIFT - 9);
if (se->start_page == 0) { if (se->start_page == 0) {
/* Do not discard the swap header page! */ /* Do not discard the swap header page! */
...@@ -133,7 +133,7 @@ static void discard_swap_cluster(struct swap_info_struct *si, ...@@ -133,7 +133,7 @@ static void discard_swap_cluster(struct swap_info_struct *si,
start_page < se->start_page + se->nr_pages) { start_page < se->start_page + se->nr_pages) {
pgoff_t offset = start_page - se->start_page; pgoff_t offset = start_page - se->start_page;
sector_t start_block = se->start_block + offset; sector_t start_block = se->start_block + offset;
pgoff_t nr_blocks = se->nr_pages - offset; sector_t nr_blocks = se->nr_pages - offset;
if (nr_blocks > nr_pages) if (nr_blocks > nr_pages)
nr_blocks = nr_pages; nr_blocks = nr_pages;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment