Skip to content

Commit

Permalink
sys_swapon: simplify error flow in read_swap_header()
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: 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 ca8bd38 commit 3871902
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions mm/swapfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ static unsigned long read_swap_header(struct swap_info_struct *p,

if (memcmp("SWAPSPACE2", swap_header->magic.magic, 10)) {
printk(KERN_ERR "Unable to find swap-space signature\n");
goto bad_swap;
return 0;
}

/* swap partition endianess hack... */
Expand All @@ -1944,7 +1944,7 @@ static unsigned long read_swap_header(struct swap_info_struct *p,
printk(KERN_WARNING
"Unable to handle swap header version %d\n",
swap_header->info.version);
goto bad_swap;
return 0;
}

p->lowest_bit = 1;
Expand Down Expand Up @@ -1976,22 +1976,19 @@ static unsigned long read_swap_header(struct swap_info_struct *p,
p->highest_bit = maxpages - 1;

if (!maxpages)
goto bad_swap;
return 0;
swapfilepages = i_size_read(inode) >> PAGE_SHIFT;
if (swapfilepages && maxpages > swapfilepages) {
printk(KERN_WARNING
"Swap area shorter than signature indicates\n");
goto bad_swap;
return 0;
}
if (swap_header->info.nr_badpages && S_ISREG(inode->i_mode))
goto bad_swap;
return 0;
if (swap_header->info.nr_badpages > MAX_SWAP_BADPAGES)
goto bad_swap;
return 0;

return maxpages;

bad_swap:
return 0;
}

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

0 comments on commit 3871902

Please sign in to comment.