Skip to content

Commit

Permalink
block: simplify calling convention of elv_unregister_queue()
Browse files Browse the repository at this point in the history
Make elv_unregister_queue() a no-op if q->elevator is NULL or is not
registered.

This simplifies the existing callers, as well as the future caller in
the error path of blk_register_queue().

Also don't bother checking whether q is NULL, since it never is.

Reviewed-by: Hannes Reinecke <[email protected]>
Reviewed-by: Bart Van Assche <[email protected]>
Signed-off-by: Eric Biggers <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
ebiggers authored and axboe committed Feb 28, 2022
1 parent 483546c commit f5ec592
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions block/blk-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,7 @@ void blk_unregister_queue(struct gendisk *disk)
blk_trace_remove_sysfs(disk_to_dev(disk));

mutex_lock(&q->sysfs_lock);
if (q->elevator)
elv_unregister_queue(q);
elv_unregister_queue(q);
disk_unregister_independent_access_ranges(disk);
mutex_unlock(&q->sysfs_lock);
mutex_unlock(&q->sysfs_dir_lock);
Expand Down
8 changes: 4 additions & 4 deletions block/elevator.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,11 @@ int elv_register_queue(struct request_queue *q, bool uevent)

void elv_unregister_queue(struct request_queue *q)
{
struct elevator_queue *e = q->elevator;

lockdep_assert_held(&q->sysfs_lock);

if (q) {
if (e && e->registered) {
struct elevator_queue *e = q->elevator;

kobject_uevent(&e->kobj, KOBJ_REMOVE);
Expand Down Expand Up @@ -593,9 +595,7 @@ int elevator_switch_mq(struct request_queue *q,
lockdep_assert_held(&q->sysfs_lock);

if (q->elevator) {
if (q->elevator->registered)
elv_unregister_queue(q);

elv_unregister_queue(q);
ioc_clear_queue(q);
blk_mq_sched_free_rqs(q);
elevator_exit(q);
Expand Down

0 comments on commit f5ec592

Please sign in to comment.