Skip to contentSkip to conversation

mmc-block fixes

PATCH In review Adrian Hunter 2 participants 5 messages Dec 18, 2009 – Dec 22, 2009 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

cover mmc-block fixes

Hi

Here are 3 fixes for mmc-block:

Adrian Hunter (1):
mmc_block: fix queue cleanup

Anna Lemehova (1):
mmc_block: add dev_t initialization check

Jarkko Lavinen (1):
mmc_block: fix probe error cleanup bug

 drivers/mmc/card/block.c |    8 ++++++++
 drivers/mmc/card/queue.c |   18 +++++++++---------
 2 files changed, 17 insertions(+), 9 deletions(-)

Regards
Adrian

#1 lore raw

PATCH 1/3 mmc_block: add dev_t initialization check

Quoted 1 line

From 96404dc52f2cfa73541ed221febf83e54d7556a9 Mon Sep 17 00:00:00 2001

From: Anna Lemehova <[email protected]>
Date: Fri, 30 Oct 2009 10:45:54 +0100
Subject: [PATCH] mmc_block: add dev_t initialization check

When a card is removed before mmc_blk_probe() has called add_disk(), then the minor field is uninitialized and has value 0. This caused mmc_blk_put() to always release devidx 0 even if 0 was still in use. Then the next mmc_blk_probe() used the first free idx of 0, which oopses in sysfs, since it is used by another card.

---
 drivers/mmc/card/block.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
drivers/mmc/card/block.c +5 -0
index 85f0e8c..5988573 100644
@@ -85,7 +85,12 @@ static void mmc_blk_put(struct mmc_blk_data *md)
 	mutex_lock(&open_lock);
 	md->usage--;
 	if (md->usage == 0) {
+		int devmaj = MAJOR(disk_devt(md->disk));
 		int devidx = MINOR(disk_devt(md->disk)) >> MMC_SHIFT;
+
+		if (!devmaj)
+			devidx = md->disk->first_minor >> MMC_SHIFT;
+
 		__clear_bit(devidx, dev_use);
 
 		put_disk(md->disk);
Signature · 1 line
1.6.0.4
#2 lore raw

PATCH 2/3 mmc_block: fix probe error cleanup bug

In reply to Adrian Hunter
Quoted 1 line

From b61100e0ec8f994bca8d1dc423870bdf158b733e Mon Sep 17 00:00:00 2001

From: Jarkko Lavinen <[email protected]>
Date: Wed, 11 Nov 2009 11:52:21 +0200
Subject: [PATCH] mmc_block: fix probe error cleanup bug

If mmc_blk_set_blksize() fails mmc_blk_probe() the request queue and its thread have been set up and they need to be shut down properly before putting the disk.

---
 drivers/mmc/card/block.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/mmc/card/block.c +1 -0
index 5988573..ee87911 100644
@@ -618,6 +618,7 @@ static int mmc_blk_probe(struct mmc_card *card)
 	return 0;
 
  out:
+	mmc_cleanup_queue(&md->queue);
 	mmc_blk_put(md);
 
 	return err;
Signature · 1 line
1.6.0.4
#3 lore raw

PATCH 3/3 mmc_block: fix queue cleanup

In reply to Adrian Hunter
Quoted 1 line

From 010e6bcca45e7a0bcd9e8b27b39330cb375a7eda Mon Sep 17 00:00:00 2001

From: Adrian Hunter <[email protected]>
Date: Sat, 14 Nov 2009 10:44:03 +0200
Subject: [PATCH] mmc_block: fix queue cleanup

The main bug was that 'blk_cleanup_queue()' was called while the block device could still be in use, for example, because the card was removed while files were still open.

In addition, to be sure that 'mmc_request()' will get called for all new requests (so it can error them out), the queue is emptied during cleanup. This is done after the worker thread is stopped to avoid racing with it.

Finally, it is not a device error for this to be happening, so quiet the (sometimes very many) error messages.

---
 drivers/mmc/card/block.c |    2 ++
 drivers/mmc/card/queue.c |   18 +++++++++---------
 2 files changed, 11 insertions(+), 9 deletions(-)
drivers/mmc/card/block.c +2 -0
index ee87911..1f552c6 100644
@@ -91,6 +91,8 @@ static void mmc_blk_put(struct mmc_blk_data *md)
 		if (!devmaj)
 			devidx = md->disk->first_minor >> MMC_SHIFT;
 
+		blk_cleanup_queue(md->queue.queue);
+
 		__clear_bit(devidx, dev_use);
 
 		put_disk(md->disk);
drivers/mmc/card/queue.c +9 -9
index 49e5823..c5a7a85 100644
@@ -90,9 +90,10 @@ static void mmc_request(struct request_queue *q)
 	struct request *req;
 
 	if (!mq) {
-		printk(KERN_ERR "MMC: killing requests for dead queue\n");
-		while ((req = blk_fetch_request(q)) != NULL)
+		while ((req = blk_fetch_request(q)) != NULL) {
+			req->cmd_flags |= REQ_QUIET;
 			__blk_end_request_all(req, -EIO);
+		}
 		return;
 	}
 
@@ -223,17 +224,18 @@ void mmc_cleanup_queue(struct mmc_queue *mq)
 	struct request_queue *q = mq->queue;
 	unsigned long flags;
 
-	/* Mark that we should start throwing out stragglers */
-	spin_lock_irqsave(q->queue_lock, flags);
-	q->queuedata = NULL;
-	spin_unlock_irqrestore(q->queue_lock, flags);
-
 	/* Make sure the queue isn't suspended, as that will deadlock */
 	mmc_queue_resume(mq);
 
 	/* Then terminate our worker thread */
 	kthread_stop(mq->thread);
 
+	/* Empty the queue */
+	spin_lock_irqsave(q->queue_lock, flags);
+	q->queuedata = NULL;
+	blk_start_queue(q);
+	spin_unlock_irqrestore(q->queue_lock, flags);
+
  	if (mq->bounce_sg)
  		kfree(mq->bounce_sg);
  	mq->bounce_sg = NULL;
@@ -245,8 +247,6 @@ void mmc_cleanup_queue(struct mmc_queue *mq)
 		kfree(mq->bounce_buf);
 	mq->bounce_buf = NULL;
 
-	blk_cleanup_queue(mq->queue);
-
 	mq->card = NULL;
 }
 EXPORT_SYMBOL(mmc_cleanup_queue);
Signature · 1 line
1.6.0.4
#4 lore raw

Re: [PATCH 3/3] mmc_block: fix queue cleanup

Quoted 11 lines · On Fri, 18 Dec 2009 14:15:48 +0200 Adrian Hunter <[email protected]>…

The main bug was that 'blk_cleanup_queue()' was called while the block device could still be in use, for example, because the card was removed while files were still open.

In addition, to be sure that 'mmc_request()' will get called for all new requests (so it can error them out), the queue is emptied during cleanup. This is done after the worker thread is stopped to avoid racing with it.

Finally, it is not a device error for this to be happening, so quiet the (sometimes very many) error messages.

What nice changelogs.

Thanks, I tagged all three patches for a 2.6.32.x backport. They do appear to be applicable to 2.6.31 and perhaps earlier, also.