diff options
author | Nitin Gupta <ngupta@vflare.org> | 2010-01-28 10:49:59 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-03-03 19:42:53 -0500 |
commit | c25d75a234df36446dc0d9bb3365ab8b83374d50 (patch) | |
tree | a7fe3c20e9b8eb8837e952ffc0306017514ec004 /drivers | |
parent | 2e882281742f7e483e751bbbaf6c0946b5f8513f (diff) |
Staging: ramzswap: Handle case for invalid backing swap
Currently, we crash (issue BUG_ON) if backing swap
disk size is zero. This can happen is user specified
an extended partition or simply a bad disk as backing
swap. A crash is really an unpleasant surprise to user
for such trivial problems.
Now, we check for this condition and simply fail device
initialization if this is the case.
Additional cleanups:
* use static for all functions
* remove extra newline between functions
* memset backing_swap_name to NULL on device reset
Signed-off-by: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/ramzswap/ramzswap_drv.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/drivers/staging/ramzswap/ramzswap_drv.c b/drivers/staging/ramzswap/ramzswap_drv.c index 7e0a3fab9cd4..1bca069211a8 100644 --- a/drivers/staging/ramzswap/ramzswap_drv.c +++ b/drivers/staging/ramzswap/ramzswap_drv.c | |||
@@ -220,7 +220,7 @@ out: | |||
220 | return ret; | 220 | return ret; |
221 | } | 221 | } |
222 | 222 | ||
223 | void ramzswap_ioctl_get_stats(struct ramzswap *rzs, | 223 | static void ramzswap_ioctl_get_stats(struct ramzswap *rzs, |
224 | struct ramzswap_ioctl_stats *s) | 224 | struct ramzswap_ioctl_stats *s) |
225 | { | 225 | { |
226 | strncpy(s->backing_swap_name, rzs->backing_swap_name, | 226 | strncpy(s->backing_swap_name, rzs->backing_swap_name, |
@@ -502,6 +502,14 @@ static int setup_backing_swap(struct ramzswap *rzs) | |||
502 | goto bad_param; | 502 | goto bad_param; |
503 | } | 503 | } |
504 | disksize = i_size_read(inode); | 504 | disksize = i_size_read(inode); |
505 | /* | ||
506 | * Can happen if user gives an extended partition as | ||
507 | * backing swap or simply a bad disk. | ||
508 | */ | ||
509 | if (!disksize) { | ||
510 | pr_err("Error reading backing swap size.\n"); | ||
511 | goto bad_param; | ||
512 | } | ||
505 | } else if (S_ISREG(inode->i_mode)) { | 513 | } else if (S_ISREG(inode->i_mode)) { |
506 | bdev = inode->i_sb->s_bdev; | 514 | bdev = inode->i_sb->s_bdev; |
507 | if (IS_SWAPFILE(inode)) { | 515 | if (IS_SWAPFILE(inode)) { |
@@ -519,7 +527,6 @@ static int setup_backing_swap(struct ramzswap *rzs) | |||
519 | rzs->swap_file = swap_file; | 527 | rzs->swap_file = swap_file; |
520 | rzs->backing_swap = bdev; | 528 | rzs->backing_swap = bdev; |
521 | rzs->disksize = disksize; | 529 | rzs->disksize = disksize; |
522 | BUG_ON(!rzs->disksize); | ||
523 | 530 | ||
524 | return 0; | 531 | return 0; |
525 | 532 | ||
@@ -537,7 +544,7 @@ out: | |||
537 | * Map logical page number 'pagenum' to physical page number | 544 | * Map logical page number 'pagenum' to physical page number |
538 | * on backing swap device. For block device, this is a nop. | 545 | * on backing swap device. For block device, this is a nop. |
539 | */ | 546 | */ |
540 | u32 map_backing_swap_page(struct ramzswap *rzs, u32 pagenum) | 547 | static u32 map_backing_swap_page(struct ramzswap *rzs, u32 pagenum) |
541 | { | 548 | { |
542 | u32 skip_pages, entries_per_page; | 549 | u32 skip_pages, entries_per_page; |
543 | size_t delta, se_offset, skipped; | 550 | size_t delta, se_offset, skipped; |
@@ -668,7 +675,6 @@ static int handle_uncompressed_page(struct ramzswap *rzs, struct bio *bio) | |||
668 | return 0; | 675 | return 0; |
669 | } | 676 | } |
670 | 677 | ||
671 | |||
672 | /* | 678 | /* |
673 | * Called when request page is not present in ramzswap. | 679 | * Called when request page is not present in ramzswap. |
674 | * Its either in backing swap device (if present) or | 680 | * Its either in backing swap device (if present) or |
@@ -936,7 +942,6 @@ out: | |||
936 | return 0; | 942 | return 0; |
937 | } | 943 | } |
938 | 944 | ||
939 | |||
940 | /* | 945 | /* |
941 | * Check if request is within bounds and page aligned. | 946 | * Check if request is within bounds and page aligned. |
942 | */ | 947 | */ |
@@ -1064,6 +1069,7 @@ static void reset_device(struct ramzswap *rzs) | |||
1064 | bd_release(rzs->backing_swap); | 1069 | bd_release(rzs->backing_swap); |
1065 | filp_close(rzs->swap_file, NULL); | 1070 | filp_close(rzs->swap_file, NULL); |
1066 | rzs->backing_swap = NULL; | 1071 | rzs->backing_swap = NULL; |
1072 | memset(rzs->backing_swap_name, 0, MAX_SWAP_NAME_LEN); | ||
1067 | } | 1073 | } |
1068 | 1074 | ||
1069 | /* Reset stats */ | 1075 | /* Reset stats */ |