Skip to contentSkip to conversation

Use command class to determine read-only status.

PATCH Applied Pierre Ossman 2 participants 4 messages Oct 28, 2005 – Oct 30, 2005 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use command class to determine read-only status.

If a card doesn't support the "write block" command class then any attempts to open the device should reflect this by denying write access.

---

 drivers/mmc/mmc_block.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
drivers/mmc/mmc_block.c +7 -4
@@ -97,7 +97,8 @@ static int mmc_blk_open(struct inode *in
 		ret = 0;
 
 		if ((filp->f_mode & FMODE_WRITE) &&
-			mmc_card_readonly(md->queue.card))
+			(!(md->queue.card->csd.cmdclass & CCC_BLOCK_WRITE) ||
+			mmc_card_readonly(md->queue.card)))
 			ret = -EROFS;
 	}
 
@@ -407,10 +408,12 @@ static int mmc_blk_probe(struct mmc_card
 	if (err)
 		goto out;
 
-	printk(KERN_INFO "%s: %s %s %dKiB %s\n",
+	printk(KERN_INFO "%s: %s %s %dKiB",
 		md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
-		(card->csd.capacity << card->csd.read_blkbits) / 1024,
-		mmc_card_readonly(card)?"(ro)":"");
+		(card->csd.capacity << card->csd.read_blkbits) / 1024);
+	if (mmc_card_readonly(card) || !(card->csd.cmdclass & CCC_BLOCK_WRITE))
+		printk("(ro)");
+	printk("\n");
 
 	mmc_set_drvdata(card, md);
 	add_disk(md->disk);
#1 lore raw
Quoted 3 lines · Pierre Ossman

If a card doesn't support the "write block" command class then any attempts to open the device should reflect this by denying write access.

I'd rather we kept printk messages as one printk if at all possible. How about encapsulating both of these conditions into an inline function:

static inline int mmc_blk_readonly(struct mmc_card *card)

{
	return mmc_card_readonly(card) ||
	       !(card->csd.cmdclass & CCC_BLOCK_WRITE);
}

drivers/mmc/mmc_block.c static int mmc_blk_open(struct inode *in · line 100

Quoted 8 lines
drivers/mmc/mmc_block.c +0 -1
@@ -97,7 +97,8 @@ static int mmc_blk_open(struct inode *in
 		ret = 0;
 
 		if ((filp->f_mode & FMODE_WRITE) &&
-			mmc_card_readonly(md->queue.card))

+ mmc_blk_readonly(md->queue.card))

drivers/mmc/mmc_block.c static int mmc_blk_probe(struct mmc_card · line 413

Quoted 4 lines
drivers/mmc/mmc_block.c +0 -2
 	printk(KERN_INFO "%s: %s %s %dKiB %s\n",
 		md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
-		(card->csd.capacity << card->csd.read_blkbits) / 1024,
-		mmc_card_readonly(card)?"(ro)":"");

+ mmc_blk_readonly(card) ? "(ro)" : "");

As a bonus, I think this makes the code a lot more readable... but then I am biased. 8)

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#2 lore raw
Quoted 9 lines · Russell King
Quoted 3 lines · Pierre Ossman

If a card doesn't support the "write block" command class then any attempts to open the device should reflect this by denying write access.

I'd rather we kept printk messages as one printk if at all possible. How about encapsulating both of these conditions into an inline function:

Ok with me. New patch included.

[MMC] Use command class to determine read-only status.

If a card doesn't support the "write block" command class then any attempts to open the device should reflect this by denying write access.

---

 drivers/mmc/mmc_block.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
drivers/mmc/mmc_block.c +8 -2
@@ -85,6 +85,12 @@ static void mmc_blk_put(struct mmc_blk_d
 	up(&open_lock);
 }
 
+static inline int mmc_blk_readonly(struct mmc_card *card)
+{
+	return mmc_card_readonly(card) ||
+	       !(card->csd.cmdclass & CCC_BLOCK_WRITE);
+}
+
 static int mmc_blk_open(struct inode *inode, struct file *filp)
 {
 	struct mmc_blk_data *md;
@@ -97,7 +103,7 @@ static int mmc_blk_open(struct inode *in
 		ret = 0;
 
 		if ((filp->f_mode & FMODE_WRITE) &&
-			mmc_card_readonly(md->queue.card))
+			mmc_blk_readonly(md->queue.card))
 			ret = -EROFS;
 	}
 
@@ -410,7 +416,7 @@ static int mmc_blk_probe(struct mmc_card
 	printk(KERN_INFO "%s: %s %s %dKiB %s\n",
 		md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
 		(card->csd.capacity << card->csd.read_blkbits) / 1024,
-		mmc_card_readonly(card)?"(ro)":"");
+		mmc_blk_readonly(card)?"(ro)":"");
 
 	mmc_set_drvdata(card, md);
 	add_disk(md->disk);
Applied
#3 lore raw
Quoted 6 lines · Pierre Ossman
Quoted 5 lines · Russell King
Quoted 3 lines · Pierre Ossman

If a card doesn't support the "write block" command class then any attempts to open the device should reflect this by denying write access.

Quoted 6 lines
Quoted 4 lines

I'd rather we kept printk messages as one printk if at all possible. How about encapsulating both of these conditions into an inline function:

Ok with me. New patch included.

Applied, thanks.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core