Skip to contentSkip to conversation

Cleanup of mtd->type and mtd->flags

PATCH In review Jörn Engel 3 participants 8 messages Apr 13, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Cleanup of mtd->type and mtd->flags

Currently, there appears to be a great confusion surrounding mtd->type and mtd->flags. Various combinations of type and flags are used by device drivers to give some hints to users. Some users interpret these hints as seems to be intended by the drivers, others don't. Mismatches are caused by both drivers and users being confused and the whole system being less than clear.

This patchset is part of a larger work trying to clean things up. Patches are fairly simple and shouldn't need any discussion.

Jörn

#1 lore raw

PATCH 1/4 Simplify test for RAM devices

mtdblock is the only user of aggregate capabilities in mtd. This is clearly bogus and should be changed. In particular, it tries to determine whether the device in question is a piece of RAM. For every single driver that fits the current criteria, an easier test would be to check for the type being MTD_RAM.

---

 drivers/mtd/mtdblock.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mtd/mtdblock.c renamed from drivers/mtd/mtdblock.c~mtdblock_ram_test +1 -2
@@ -288,8 +288,7 @@ static int mtdblock_open(struct mtd_blkt
 
 	mutex_init(&mtdblk->cache_mutex);
 	mtdblk->cache_state = STATE_EMPTY;
-	if ((mtdblk->mtd->flags & MTD_CAP_RAM) != MTD_CAP_RAM &&
-	    mtdblk->mtd->erasesize) {
+	if (mtdblk->mtd->type != MTD_RAM && mtdblk->mtd->erasesize) {
 		mtdblk->cache_size = mtdblk->mtd->erasesize;
 		mtdblk->cache_data = NULL;
 	}
#2 lore raw

PATCH 2/4 Make mtdblock_ro unconditionally readonly

In reply to Jörn Engel

mtdblock_ro is by definition readonly. Remove the silly checks.

---

 drivers/mtd/mtdblock_ro.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mtd/mtdblock_ro.c renamed from drivers/mtd/mtdblock_ro.c~mtdblock_ro +1 -3
@@ -45,9 +45,7 @@ static void mtdblock_add_mtd(struct mtd_
 	dev->blksize = 512;
 	dev->size = mtd->size >> 9;
 	dev->tr = tr;
-	if ((mtd->flags & (MTD_CLEAR_BITS|MTD_SET_BITS|MTD_WRITEABLE)) !=
-	    (MTD_CLEAR_BITS|MTD_SET_BITS|MTD_WRITEABLE))
-		dev->readonly = 1;
+	dev->readonly = 1;
 
 	add_mtd_blktrans_dev(dev);
 }
#3 lore raw

PATCH 3/4 Remove unchecked flags

In reply to Jörn Engel

Several flags are set by some devices, but never checked. Remove them.

---

 drivers/mtd/chips/map_ram.c |    2 +-
 drivers/mtd/devices/phram.c |    2 +-
 drivers/mtd/devices/slram.c |    3 +--
 include/mtd/mtd-abi.h       |   12 +++---------
 4 files changed, 6 insertions(+), 13 deletions(-)
include/mtd/mtd-abi.h renamed from include/mtd/mtd-abi.h~unchecked_flags +3 -9
@@ -35,20 +35,14 @@ struct mtd_oob_buf {
 
 #define MTD_CLEAR_BITS		1       // Bits can be cleared (flash)
 #define MTD_SET_BITS		2       // Bits can be set
-#define MTD_ERASEABLE		4       // Has an erase function
-#define MTD_WRITEB_WRITEABLE	8       // Direct IO is possible
-#define MTD_VOLATILE		16      // Set for RAMs
-#define MTD_XIP			32	// eXecute-In-Place possible
-#define MTD_OOB			64	// Out-of-band data (NAND flash)
 #define MTD_ECC			128	// Device capable of automatic ECC
-#define MTD_NO_VIRTBLOCKS	256	// Virtual blocks not allowed
 #define MTD_PROGRAM_REGIONS	512	// Configurable Programming Regions
 
 // Some common devices / combinations of capabilities
 #define MTD_CAP_ROM		0
-#define MTD_CAP_RAM		(MTD_CLEAR_BITS|MTD_SET_BITS|MTD_WRITEB_WRITEABLE)
-#define MTD_CAP_NORFLASH        (MTD_CLEAR_BITS|MTD_ERASEABLE)
-#define MTD_CAP_NANDFLASH       (MTD_CLEAR_BITS|MTD_ERASEABLE|MTD_OOB)
+#define MTD_CAP_RAM		(MTD_CLEAR_BITS|MTD_SET_BITS)
+#define MTD_CAP_NORFLASH	(MTD_CLEAR_BITS)
+#define MTD_CAP_NANDFLASH	(MTD_CLEAR_BITS)
 #define MTD_WRITEABLE		(MTD_CLEAR_BITS|MTD_SET_BITS)
 
 
drivers/mtd/devices/phram.c renamed from drivers/mtd/devices/phram.c~unchecked_flags +1 -1
@@ -142,7 +142,7 @@ static int register_device(char *name, u
 
 	new->mtd.name = name;
 	new->mtd.size = len;
-	new->mtd.flags = MTD_CAP_RAM | MTD_ERASEABLE | MTD_VOLATILE;
+	new->mtd.flags = MTD_CAP_RAM;
         new->mtd.erase = phram_erase;
 	new->mtd.point = phram_point;
 	new->mtd.unpoint = phram_unpoint;
drivers/mtd/chips/map_ram.c renamed from drivers/mtd/chips/map_ram.c~unchecked_flags +1 -1
@@ -70,7 +70,7 @@ static struct mtd_info *map_ram_probe(st
 	mtd->read = mapram_read;
 	mtd->write = mapram_write;
 	mtd->sync = mapram_nop;
-	mtd->flags = MTD_CAP_RAM | MTD_VOLATILE;
+	mtd->flags = MTD_CAP_RAM;
 
 	mtd->erasesize = PAGE_SIZE;
  	while(mtd->size & (mtd->erasesize - 1))
drivers/mtd/devices/slram.c renamed from drivers/mtd/devices/slram.c~unchecked_flags +1 -2
@@ -200,8 +200,7 @@ static int register_device(char *name, u
 
 	(*curmtd)->mtdinfo->name = name;
 	(*curmtd)->mtdinfo->size = length;
-	(*curmtd)->mtdinfo->flags = MTD_CLEAR_BITS | MTD_SET_BITS |
-					MTD_WRITEB_WRITEABLE | MTD_VOLATILE | MTD_CAP_RAM;
+	(*curmtd)->mtdinfo->flags = MTD_CAP_RAM;
         (*curmtd)->mtdinfo->erase = slram_erase;
 	(*curmtd)->mtdinfo->point = slram_point;
 	(*curmtd)->mtdinfo->unpoint = slram_unpoint;
#4 lore raw

Re: [PATCH 3/4] Remove unchecked flags

Quoted 1 line · Jörn Engel

Several flags are set by some devices, but never checked. Remove them.

As a side note, these will also need to be removed from the mtd-utils tree. The switch to git meant that mtd-utils has it's own copy of the sanitized headers. The patch for mtd-abi.h should apply there as well.

josh

#5 lore raw

Re: [PATCH 3/4] Remove unchecked flags

Quoted 4 lines · Josh Boyer

As a side note, these will also need to be removed from the mtd-utils tree. The switch to git meant that mtd-utils has it's own copy of the sanitized headers. The patch for mtd-abi.h should apply there as well.

The idea is that include/mtd/ is sanitised for userspace, and those headers should be identical. Having switched to git and separated the userspace and kernel repositories, I hadn't yet worked out how to address that.

Signature · 1 line
dwmw2
#6 lore raw

Re: [PATCH 3/4] Remove unchecked flags

Quoted 10 lines · David Woodhouse
Quoted 4 lines · Josh Boyer

As a side note, these will also need to be removed from the mtd-utils tree. The switch to git meant that mtd-utils has it's own copy of the sanitized headers. The patch for mtd-abi.h should apply there as well.

The idea is that include/mtd/ is sanitised for userspace, and those headers should be identical. Having switched to git and separated the userspace and kernel repositories, I hadn't yet worked out how to address that.

We sorta addressed it already. The repositories each have their own copy of those files. They should still be identical, which means double maintenance on them. That sucks, but I don't know of a better way to do it offhand.

josh

#7 lore raw

PATCH 4/4 Remove unused types

In reply to Jörn Engel

Three types are never set or checked for. Remove.

---

 include/mtd/mtd-abi.h |    3 ---
 1 file changed, 3 deletions(-)
include/mtd/mtd-abi.h renamed from include/mtd/mtd-abi.h~unused_types +0 -3
@@ -28,10 +28,7 @@ struct mtd_oob_buf {
 #define MTD_ROM			2
 #define MTD_NORFLASH		3
 #define MTD_NANDFLASH		4
-#define MTD_PEROM		5
 #define MTD_DATAFLASH		6
-#define MTD_OTHER		14
-#define MTD_UNKNOWN		15
 
 #define MTD_CLEAR_BITS		1       // Bits can be cleared (flash)
 #define MTD_SET_BITS		2       // Bits can be set