Skip to content

Commit 41e3efd

Browse files
ahunter6storulf
authored andcommitted
mmc: block: Simplify cleaning up the queue
Use blk_cleanup_queue() to shutdown the queue when the driver is removed, and instead get an extra reference to the queue to prevent the queue being freed before the final mmc_blk_put(). Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Tested-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 4512bd3 commit 41e3efd

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

drivers/mmc/core/block.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static void mmc_blk_put(struct mmc_blk_data *md)
189189
md->usage--;
190190
if (md->usage == 0) {
191191
int devidx = mmc_get_devidx(md->disk);
192-
blk_cleanup_queue(md->queue.queue);
192+
blk_put_queue(md->queue.queue);
193193
ida_simple_remove(&mmc_blk_ida, devidx);
194194
put_disk(md->disk);
195195
kfree(md);
@@ -2156,6 +2156,17 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
21562156

21572157
md->queue.blkdata = md;
21582158

2159+
/*
2160+
* Keep an extra reference to the queue so that we can shutdown the
2161+
* queue (i.e. call blk_cleanup_queue()) while there are still
2162+
* references to the 'md'. The corresponding blk_put_queue() is in
2163+
* mmc_blk_put().
2164+
*/
2165+
if (!blk_get_queue(md->queue.queue)) {
2166+
mmc_cleanup_queue(&md->queue);
2167+
goto err_putdisk;
2168+
}
2169+
21592170
md->disk->major = MMC_BLOCK_MAJOR;
21602171
md->disk->first_minor = devidx * perdev_minors;
21612172
md->disk->fops = &mmc_bdops;
@@ -2471,10 +2482,6 @@ static void mmc_blk_remove_req(struct mmc_blk_data *md)
24712482
* from being accepted.
24722483
*/
24732484
card = md->queue.card;
2474-
spin_lock_irq(md->queue.queue->queue_lock);
2475-
queue_flag_set(QUEUE_FLAG_BYPASS, md->queue.queue);
2476-
spin_unlock_irq(md->queue.queue->queue_lock);
2477-
blk_set_queue_dying(md->queue.queue);
24782485
mmc_cleanup_queue(&md->queue);
24792486
if (md->disk->flags & GENHD_FL_UP) {
24802487
device_remove_file(disk_to_dev(md->disk), &md->force_ro);

drivers/mmc/core/queue.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ void mmc_cleanup_queue(struct mmc_queue *mq)
268268
blk_start_queue(q);
269269
spin_unlock_irqrestore(q->queue_lock, flags);
270270

271+
blk_cleanup_queue(q);
272+
271273
mq->card = NULL;
272274
}
273275

0 commit comments

Comments
 (0)