Index: linux-2.6.17-rc5-mm2/mm/swapfile.c =================================================================== --- linux-2.6.17-rc5-mm2.orig/mm/swapfile.c 2006-06-01 10:03:07.127259731 -0700 +++ linux-2.6.17-rc5-mm2/mm/swapfile.c 2006-06-06 10:50:09.692165312 -0700 @@ -1363,12 +1363,11 @@ __initcall(procswaps_init); */ asmlinkage long sys_swapon(const char __user * specialfile, int swap_flags) { - struct swap_info_struct * p; + struct swap_info_struct *p,*q; char *name = NULL; struct block_device *bdev = NULL; struct file *swap_file = NULL; struct address_space *mapping; - unsigned int type; int i, prev; int error; static int least_priority; @@ -1387,29 +1386,19 @@ asmlinkage long sys_swapon(const char __ if (!capable(CAP_SYS_ADMIN)) return -EPERM; spin_lock(&swap_lock); - p = swap_info; - for (type = 0 ; type < nr_swapfiles ; type++,p++) + + for (p = swap_info; p < swap_info + MAX_SWAPFILES; p++) if (!(p->flags & SWP_USED)) break; error = -EPERM; - /* - * Test if adding another swap device is possible. There are - * two limiting factors: 1) the number of bits for the swap - * type swp_entry_t definition and 2) the number of bits for - * the swap type in the swap ptes as defined by the different - * architectures. To honor both limitations a swap entry - * with swap offset 0 and swap type ~0UL is created, encoded - * to a swap pte, decoded to a swp_entry_t again and finally - * the swap type part is extracted. This will mask all bits - * from the initial ~0UL that can't be encoded in either the - * swp_entry_t or the architecture definition of a swap pte. - */ - if (type > swp_type(pte_to_swp_entry(swp_entry_to_pte(swp_entry(~0UL,0))))) { + + if (p == swap_info + MAX_SWAPFILES) { spin_unlock(&swap_lock); goto out; } - if (type >= nr_swapfiles) - nr_swapfiles = type+1; + if (p >= swap_info + nr_swapfiles) + nr_swapfiles++; + INIT_LIST_HEAD(&p->extent_list); p->flags = SWP_USED; p->swap_file = NULL; @@ -1445,10 +1434,9 @@ asmlinkage long sys_swapon(const char __ inode = mapping->host; error = -EBUSY; - for (i = 0; i < nr_swapfiles; i++) { - struct swap_info_struct *q = &swap_info[i]; + for (q = swap_info; q < swap_info + nr_swapfiles; q++) { - if (i == type || !q->swap_file) + if (q == p || !q->swap_file) continue; if (mapping == q->swap_file->f_mapping) goto bad_swap;