From: Rob Landley Problem: In some circumstances, bd_claim() is returning the wrong error code. If we try to swapon an unused block device that isn't swap formatted, we get -EINVAL. But if that same block device is already mounted, we instead get -EBUSY, even though it still isn't a valid swap device. This issue came up on the busybox list trying to get the error message from "swapon -a" right. If a swap device is already enabled, we get -EBUSY, and we shouldn't report this as an error. But we can't distinguish the two -EBUSY conditions, which are very different errors. In the code, bd_claim() returns either 0 or -EBUSY, but in this case busy means "somebody other than sys_swapon has already claimed this", and _that_ means this block device can't be a valid swap device. So return -EINVAL there. Signed-off-by: Rob Landley Signed-off-by: Andrew Morton --- mm/swapfile.c | 1 + 1 files changed, 1 insertion(+) diff -puN mm/swapfile.c~fix-bd_claim-error-code mm/swapfile.c --- 25/mm/swapfile.c~fix-bd_claim-error-code Tue Sep 20 14:09:43 2005 +++ 25-akpm/mm/swapfile.c Tue Sep 20 14:09:43 2005 @@ -1381,6 +1381,7 @@ asmlinkage long sys_swapon(const char __ error = bd_claim(bdev, sys_swapon); if (error < 0) { bdev = NULL; + error = -EINVAL; goto bad_swap; } p->old_block_size = block_size(bdev); _