Commit fb199746303a6bfd6121834ec9e810471185c530
Committed by
Jens Axboe
1 parent
2472892a3c
Exists in
master
and in
7 other branches
block: fix blk_register_queue() return value
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>
Showing 1 changed file with 8 additions and 2 deletions Side-by-side Diff
block/blk-sysfs.c
... | ... | @@ -276,9 +276,12 @@ |
276 | 276 | |
277 | 277 | struct request_queue *q = disk->queue; |
278 | 278 | |
279 | - if (!q || !q->request_fn) | |
279 | + if (WARN_ON(!q)) | |
280 | 280 | return -ENXIO; |
281 | 281 | |
282 | + if (!q->request_fn) | |
283 | + return 0; | |
284 | + | |
282 | 285 | ret = kobject_add(&q->kobj, kobject_get(&disk->dev.kobj), |
283 | 286 | "%s", "queue"); |
284 | 287 | if (ret < 0) |
... | ... | @@ -300,7 +303,10 @@ |
300 | 303 | { |
301 | 304 | struct request_queue *q = disk->queue; |
302 | 305 | |
303 | - if (q && q->request_fn) { | |
306 | + if (WARN_ON(!q)) | |
307 | + return; | |
308 | + | |
309 | + if (q->request_fn) { | |
304 | 310 | elv_unregister_queue(q); |
305 | 311 | |
306 | 312 | kobject_uevent(&q->kobj, KOBJ_REMOVE); |