diff options
author | Tejun Heo | 2013-02-27 19:03:56 -0600 |
---|---|---|
committer | Greg Kroah-Hartman | 2013-03-03 16:03:35 -0600 |
commit | ca4e7610b166ff557a5f357bac6f12ec66a1ac1a (patch) | |
tree | 9375191b66927a7e0a2d4dc23886d8f8044e7b0e /block | |
parent | bf9493433113145c9aa9a622d0c9dcc7b51c5d83 (diff) | |
download | kernel-video-ca4e7610b166ff557a5f357bac6f12ec66a1ac1a.tar.gz kernel-video-ca4e7610b166ff557a5f357bac6f12ec66a1ac1a.tar.xz kernel-video-ca4e7610b166ff557a5f357bac6f12ec66a1ac1a.zip |
block: fix synchronization and limit check in blk_alloc_devt()
commit ce23bba842aee98092225d9576dba47c82352521 upstream.
idr allocation in blk_alloc_devt() wasn't synchronized against lookup
and removal, and its limit check was off by one - 1 << MINORBITS is
the number of minors allowed, not the maximum allowed minor.
Add locking and rename MAX_EXT_DEVT to NR_EXT_DEVT and fix limit
checking.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'block')
-rw-r--r-- | block/genhd.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/block/genhd.c b/block/genhd.c index 35d0290885a..7dcfdd84efc 100644 --- a/block/genhd.c +++ b/block/genhd.c | |||
@@ -25,7 +25,7 @@ static DEFINE_MUTEX(block_class_lock); | |||
25 | struct kobject *block_depr; | 25 | struct kobject *block_depr; |
26 | 26 | ||
27 | /* for extended dynamic devt allocation, currently only one major is used */ | 27 | /* for extended dynamic devt allocation, currently only one major is used */ |
28 | #define MAX_EXT_DEVT (1 << MINORBITS) | 28 | #define NR_EXT_DEVT (1 << MINORBITS) |
29 | 29 | ||
30 | /* For extended devt allocation. ext_devt_mutex prevents look up | 30 | /* For extended devt allocation. ext_devt_mutex prevents look up |
31 | * results from going away underneath its user. | 31 | * results from going away underneath its user. |
@@ -424,19 +424,16 @@ int blk_alloc_devt(struct hd_struct *part, dev_t *devt) | |||
424 | return -ENOMEM; | 424 | return -ENOMEM; |
425 | mutex_lock(&ext_devt_mutex); | 425 | mutex_lock(&ext_devt_mutex); |
426 | rc = idr_get_new(&ext_devt_idr, part, &idx); | 426 | rc = idr_get_new(&ext_devt_idr, part, &idx); |
427 | if (!rc && idx >= NR_EXT_DEVT) { | ||
428 | idr_remove(&ext_devt_idr, idx); | ||
429 | rc = -EBUSY; | ||
430 | } | ||
427 | mutex_unlock(&ext_devt_mutex); | 431 | mutex_unlock(&ext_devt_mutex); |
428 | } while (rc == -EAGAIN); | 432 | } while (rc == -EAGAIN); |
429 | 433 | ||
430 | if (rc) | 434 | if (rc) |
431 | return rc; | 435 | return rc; |
432 | 436 | ||
433 | if (idx > MAX_EXT_DEVT) { | ||
434 | mutex_lock(&ext_devt_mutex); | ||
435 | idr_remove(&ext_devt_idr, idx); | ||
436 | mutex_unlock(&ext_devt_mutex); | ||
437 | return -EBUSY; | ||
438 | } | ||
439 | |||
440 | *devt = MKDEV(BLOCK_EXT_MAJOR, blk_mangle_minor(idx)); | 437 | *devt = MKDEV(BLOCK_EXT_MAJOR, blk_mangle_minor(idx)); |
441 | return 0; | 438 | return 0; |
442 | } | 439 | } |