Skip to content

Commit

Permalink
block: fix blk_register_queue() return value
Browse files Browse the repository at this point in the history
blk_register_queue() returns -ENXIO when queue->request_fn is NULL.  But there
are some block drivers that call blk_register_queue() via add_disk() with
queue->request_fn == NULL.  (For example, brd, loop)

Although no one checks return value of blk_register_queue(), this patch makes
it return 0 instead of -ENXIO when queue->request_fn is NULL,

Also this patch adds warning when blk_register_queue() and
blk_unregister_queue() are called with queue == NULL rather than ignore
invalid usage silently.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
  • Loading branch information
mita authored and Jens Axboe committed Apr 21, 2008
1 parent 2472892 commit fb19974
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions block/blk-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,12 @@ int blk_register_queue(struct gendisk *disk)

struct request_queue *q = disk->queue;

if (!q || !q->request_fn)
if (WARN_ON(!q))
return -ENXIO;

if (!q->request_fn)
return 0;

ret = kobject_add(&q->kobj, kobject_get(&disk->dev.kobj),
"%s", "queue");
if (ret < 0)
Expand All @@ -300,7 +303,10 @@ void blk_unregister_queue(struct gendisk *disk)
{
struct request_queue *q = disk->queue;

if (q && q->request_fn) {
if (WARN_ON(!q))
return;

if (q->request_fn) {
elv_unregister_queue(q);

kobject_uevent(&q->kobj, KOBJ_REMOVE);
Expand Down

0 comments on commit fb19974

Please sign in to comment.