From: Ming Lei ming.lei@redhat.com
mainline inclusion from mainline-5.4-rc1 commit 58c898ba370e68d39470cd0d932b524682c1f9be category: bugfix bugzilla: 21614 CVE: NA
---------------------------
There are 4 users which check if queue is registered, so add one helper to check it.
Cc: Christoph Hellwig hch@infradead.org Cc: Hannes Reinecke hare@suse.com Cc: Greg KH gregkh@linuxfoundation.org Cc: Mike Snitzer snitzer@redhat.com Cc: Bart Van Assche bvanassche@acm.org Reviewed-by: Bart Van Assche bvanassche@acm.org Signed-off-by: Ming Lei ming.lei@redhat.com Signed-off-by: Jens Axboe axboe@kernel.dk Reviewed-by: Yufen Yu yuyufen@huawei.com
Conflicts: block/blk-sysfs.c block/blk-wbt.c Signed-off-by: Yu Kuai yukuai3@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- block/blk-sysfs.c | 4 ++-- block/blk-wbt.c | 2 +- block/elevator.c | 2 +- include/linux/blkdev.h | 1 + 4 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 2d905a8b1473..ec20dc5e5e0f 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -897,7 +897,7 @@ int blk_register_queue(struct gendisk *disk) if (WARN_ON(!q)) return -ENXIO;
- WARN_ONCE(test_bit(QUEUE_FLAG_REGISTERED, &q->queue_flags), + WARN_ONCE(blk_queue_registered(q), "%s is registering an already registered queue\n", kobject_name(&dev->kobj)); queue_flag_set_unlocked(QUEUE_FLAG_REGISTERED, q); @@ -974,7 +974,7 @@ void blk_unregister_queue(struct gendisk *disk) return;
/* Return early if disk->queue was never registered. */ - if (!test_bit(QUEUE_FLAG_REGISTERED, &q->queue_flags)) + if (!blk_queue_registered(q)) return;
/* diff --git a/block/blk-wbt.c b/block/blk-wbt.c index bb8f588789c8..2217ba732b7b 100644 --- a/block/blk-wbt.c +++ b/block/blk-wbt.c @@ -704,7 +704,7 @@ void wbt_enable_default(struct request_queue *q) return;
/* Queue not registered? Maybe shutting down... */ - if (!test_bit(QUEUE_FLAG_REGISTERED, &q->queue_flags)) + if (!blk_queue_registered(q)) return;
if ((q->mq_ops && IS_ENABLED(CONFIG_BLK_WBT_MQ)) || diff --git a/block/elevator.c b/block/elevator.c index fae58b2f906f..aa878a90259e 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -1087,7 +1087,7 @@ static int __elevator_change(struct request_queue *q, const char *name) struct elevator_type *e;
/* Make sure queue is not in the middle of being removed */ - if (!test_bit(QUEUE_FLAG_REGISTERED, &q->queue_flags)) + if (!blk_queue_registered(q)) return -ENOENT;
/* diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 704901e80ee3..ec86ef372e25 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -771,6 +771,7 @@ bool blk_queue_flag_test_and_clear(unsigned int flag, struct request_queue *q); #define blk_queue_quiesced(q) test_bit(QUEUE_FLAG_QUIESCED, &(q)->queue_flags) #define blk_queue_pm_only(q) atomic_read(&(q)->pm_only) #define blk_queue_fua(q) test_bit(QUEUE_FLAG_FUA, &(q)->queue_flags) +#define blk_queue_registered(q) test_bit(QUEUE_FLAG_REGISTERED, &(q)->queue_flags)
extern void blk_set_pm_only(struct request_queue *q); extern void blk_clear_pm_only(struct request_queue *q);