Skip to content

Commit

Permalink
sys_swapon: simplify error flow in setup_swap_map_and_extents()
Browse files Browse the repository at this point in the history
Since there is no cleanup to do, there is no reason to jump to a label.
Return directly instead.

Signed-off-by: Cesar Eduardo Barros <[email protected]>
Tested-by: Eric B Munson <[email protected]>
Acked-by: Eric B Munson <[email protected]>
Reviewed-by: Pekka Enberg <[email protected]>
Reviewed-by: KAMEZAWA Hiroyuki <[email protected]>
Cc: Hugh Dickins <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
cesarb authored and torvalds committed Mar 23, 2011
1 parent 915d4d7 commit bdb8e3f
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions mm/swapfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1998,18 +1998,15 @@ static int setup_swap_map_and_extents(struct swap_info_struct *p,
sector_t *span)
{
int i;
int error;
unsigned int nr_good_pages;
int nr_extents;

nr_good_pages = maxpages - 1; /* omit header page */

for (i = 0; i < swap_header->info.nr_badpages; i++) {
unsigned int page_nr = swap_header->info.badpages[i];
if (page_nr == 0 || page_nr > swap_header->info.last_page) {
error = -EINVAL;
goto bad_swap;
}
if (page_nr == 0 || page_nr > swap_header->info.last_page)
return -EINVAL;
if (page_nr < maxpages) {
swap_map[page_nr] = SWAP_MAP_BAD;
nr_good_pages--;
Expand All @@ -2021,22 +2018,16 @@ static int setup_swap_map_and_extents(struct swap_info_struct *p,
p->max = maxpages;
p->pages = nr_good_pages;
nr_extents = setup_swap_extents(p, span);
if (nr_extents < 0) {
error = nr_extents;
goto bad_swap;
}
if (nr_extents < 0)
return nr_extents;
nr_good_pages = p->pages;
}
if (!nr_good_pages) {
printk(KERN_WARNING "Empty swap-file\n");
error = -EINVAL;
goto bad_swap;
return -EINVAL;
}

return nr_extents;

bad_swap:
return error;
}

SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
Expand Down

0 comments on commit bdb8e3f

Please sign in to comment.