Skip to contentSkip to conversation

mtd: remove retlen zeroing duplication

PATCH In review Artem Bityutskiy 2 participants 10 messages Feb 6, 2012 – Feb 8, 2012

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

PATCH 1/3 mtd: remove retlen zeroing duplication

From: Artem Bityutskiy <[email protected]>

The MTD API function now zero the 'retlen' parameter before calling the driver's method - do not do this again in dirvers. This removes duplicated '*retlen = 0' assignent from the following methods:

    'mtd_point()'
    'mtd_read()'
    'mtd_write()'
    'mtd_writev()'
    'mtd_panic_write()'
---
 drivers/mtd/chips/cfi_cmdset_0001.c |    5 -----
 drivers/mtd/chips/cfi_cmdset_0002.c |   12 ------------
 drivers/mtd/chips/cfi_cmdset_0020.c |    3 ---
 drivers/mtd/chips/map_absent.c      |    2 --
 drivers/mtd/devices/block2mtd.c     |    5 -----
 drivers/mtd/devices/doc2000.c       |    4 ----
 drivers/mtd/devices/doc2001.c       |    1 -
 drivers/mtd/devices/doc2001plus.c   |    1 -
 drivers/mtd/devices/lart.c          |    2 --
 drivers/mtd/devices/m25p80.c        |    7 -------
 drivers/mtd/devices/mtd_dataflash.c |    4 ----
 drivers/mtd/devices/phram.c         |    2 --
 drivers/mtd/devices/spear_smi.c     |   10 ----------
 drivers/mtd/devices/sst25l.c        |    3 ---
 drivers/mtd/lpddr/lpddr_cmds.c      |    3 ---
 drivers/mtd/mtdconcat.c             |    6 ------
 drivers/mtd/onenand/onenand_base.c  |    3 ---
 17 files changed, 0 insertions(+), 73 deletions(-)
drivers/mtd/chips/cfi_cmdset_0001.c +0 -5
index 27008ae..dc66df6 100644
@@ -1334,7 +1334,6 @@ static int cfi_intelext_point(struct mtd_info *mtd, loff_t from, size_t len,
 	ofs = from - (chipnum << cfi->chipshift);
 
 	*virt = map->virt + cfi->chips[chipnum].start + ofs;
-	*retlen = 0;
 	if (phys)
 		*phys = map->phys + cfi->chips[chipnum].start + ofs;
 
@@ -1460,8 +1459,6 @@ static int cfi_intelext_read (struct mtd_info *mtd, loff_t from, size_t len, siz
 	chipnum = (from >> cfi->chipshift);
 	ofs = from - (chipnum <<  cfi->chipshift);
 
-	*retlen = 0;
-
 	while (len) {
 		unsigned long thislen;
 
@@ -1569,7 +1566,6 @@ static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le
 	int chipnum;
 	unsigned long ofs;
 
-	*retlen = 0;
 	if (!len)
 		return 0;
 
@@ -1817,7 +1813,6 @@ static int cfi_intelext_writev (struct mtd_info *mtd, const struct kvec *vecs,
 	for (i = 0; i < count; i++)
 		len += vecs[i].iov_len;
 
-	*retlen = 0;
 	if (!len)
 		return 0;
 
drivers/mtd/chips/cfi_cmdset_0002.c +0 -12
index 27ac062..a89d899 100644
@@ -1017,13 +1017,9 @@ static int cfi_amdstd_read (struct mtd_info *mtd, loff_t from, size_t len, size_
 	int ret = 0;
 
 	/* ofs: offset within the first chip that the first read should start */
-
 	chipnum = (from >> cfi->chipshift);
 	ofs = from - (chipnum <<  cfi->chipshift);
 
-
-	*retlen = 0;
-
 	while (len) {
 		unsigned long thislen;
 
@@ -1101,16 +1097,11 @@ static int cfi_amdstd_secsi_read (struct mtd_info *mtd, loff_t from, size_t len,
 	int chipnum;
 	int ret = 0;
 
-
 	/* ofs: offset within the first chip that the first read should start */
-
 	/* 8 secsi bytes per chip */
 	chipnum=from>>3;
 	ofs=from & 7;
 
-
-	*retlen = 0;
-
 	while (len) {
 		unsigned long thislen;
 
@@ -1255,7 +1246,6 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
 	unsigned long ofs, chipstart;
 	DECLARE_WAITQUEUE(wait, current);
 
-	*retlen = 0;
 	if (!len)
 		return 0;
 
@@ -1497,7 +1487,6 @@ static int cfi_amdstd_write_buffers(struct mtd_info *mtd, loff_t to, size_t len,
 	int chipnum;
 	unsigned long ofs;
 
-	*retlen = 0;
 	if (!len)
 		return 0;
 
@@ -1708,7 +1697,6 @@ static int cfi_amdstd_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 	int ret = 0;
 	int chipnum;
 
-	*retlen = 0;
 	if (!len)
 		return 0;
 
drivers/mtd/chips/cfi_cmdset_0020.c +0 -3
index 160402f..d690b7d 100644
@@ -394,8 +394,6 @@ static int cfi_staa_read (struct mtd_info *mtd, loff_t from, size_t len, size_t
 	chipnum = (from >> cfi->chipshift);
 	ofs = from - (chipnum <<  cfi->chipshift);
 
-	*retlen = 0;
-
 	while (len) {
 		unsigned long thislen;
 
@@ -617,7 +615,6 @@ static int cfi_staa_write_buffers (struct mtd_info *mtd, loff_t to,
 	int chipnum;
 	unsigned long ofs;
 
-	*retlen = 0;
 	if (!len)
 		return 0;
 
drivers/mtd/chips/map_absent.c +0 -2
index 6be2edd..f7a5bca 100644
@@ -70,13 +70,11 @@ static struct mtd_info *map_absent_probe(struct map_info *map)
 
 static int map_absent_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
 {
-	*retlen = 0;
 	return -ENODEV;
 }
 
 static int map_absent_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
 {
-	*retlen = 0;
 	return -ENODEV;
 }
 
drivers/mtd/devices/block2mtd.c +0 -5
index 4c2f84c..ba2d74b 100644
@@ -104,9 +104,6 @@ static int block2mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
 	int offset = from & (PAGE_SIZE-1);
 	int cpylen;
 
-	if (retlen)
-		*retlen = 0;
-
 	while (len) {
 		if ((offset + len) > PAGE_SIZE)
 			cpylen = PAGE_SIZE - offset;	// multiple pages
@@ -143,8 +140,6 @@ static int _block2mtd_write(struct block2mtd_dev *dev, const u_char *buf,
 	int offset = to & ~PAGE_MASK;	// page offset
 	int cpylen;
 
-	if (retlen)
-		*retlen = 0;
 	while (len) {
 		if ((offset+len) > PAGE_SIZE)
 			cpylen = PAGE_SIZE - offset;	// multiple pages
drivers/mtd/devices/doc2000.c +0 -4
index ee4ee0b..7ad7b05 100644
@@ -603,8 +603,6 @@ static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
 	size_t left = len;
 
 	mutex_lock(&this->lock);
-
-	*retlen = 0;
 	while (left) {
 		len = left;
 
@@ -745,8 +743,6 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
 	int status;
 
 	mutex_lock(&this->lock);
-
-	*retlen = 0;
 	while (left) {
 		len = left;
 
drivers/mtd/devices/doc2001.c +0 -1
index 1784415..7bff54e 100644
@@ -591,7 +591,6 @@ static int doc_write (struct mtd_info *mtd, loff_t to, size_t len,
 		printk("Error programming flash\n");
 		/* Error in programming
 		   FIXME: implement Bad Block Replacement (in nftl.c ??) */
-		*retlen = 0;
 		ret = -EIO;
 	}
 	dummy = ReadDOC(docptr, LastDataRead);
drivers/mtd/devices/doc2001plus.c +0 -1
index a472bab..4a03d86 100644
@@ -792,7 +792,6 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
 		printk("MTD: Error 0x%x programming at 0x%x\n", dummy, (int)to);
 		/* Error in programming
 		   FIXME: implement Bad Block Replacement (in nftl.c ??) */
-		*retlen = 0;
 		ret = -EIO;
 	}
 	dummy = ReadDOC(docptr, Mplus_LastDataRead);
drivers/mtd/devices/lart.c +0 -2
index c9ae601..6fb8dba 100644
@@ -518,8 +518,6 @@ static int flash_write (struct mtd_info *mtd,loff_t to,size_t len,size_t *retlen
    printk (KERN_DEBUG "%s(to = 0x%.8x, len = %d)\n", __func__, (__u32)to, len);
 #endif
 
-   *retlen = 0;
-
    /* sanity checks */
    if (!len) return (0);
 
drivers/mtd/devices/m25p80.c +0 -7
index 0955a8f..45cc4a1 100644
@@ -365,9 +365,6 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
 	t[1].len = len;
 	spi_message_add_tail(&t[1], &m);
 
-	/* Byte count starts at zero. */
-	*retlen = 0;
-
 	mutex_lock(&flash->lock);
 
 	/* Wait till previous write/erase is done. */
@@ -411,8 +408,6 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
 	pr_debug("%s: %s to 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
 			__func__, (u32)to, len);
 
-	*retlen = 0;
-
 	/* sanity checks */
 	if (!len)
 		return(0);
@@ -500,8 +495,6 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
 	pr_debug("%s: %s to 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
 			__func__, (u32)to, len);
 
-	*retlen = 0;
-
 	/* sanity checks */
 	if (!len)
 		return 0;
drivers/mtd/devices/mtd_dataflash.c +0 -4
index fc5c781..c76b446 100644
@@ -249,8 +249,6 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,
 	pr_debug("%s: read 0x%x..0x%x\n", dev_name(&priv->spi->dev),
 			(unsigned)from, (unsigned)(from + len));
 
-	*retlen = 0;
-
 	/* Sanity checks */
 	if (!len)
 		return 0;
@@ -323,8 +321,6 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
 	pr_debug("%s: write 0x%x..0x%x\n",
 		dev_name(&spi->dev), (unsigned)to, (unsigned)(to + len));
 
-	*retlen = 0;
-
 	/* Sanity checks */
 	if (!len)
 		return 0;
drivers/mtd/devices/phram.c +0 -2
index d0e8dc6..d3474a4 100644
@@ -85,8 +85,6 @@ static int phram_write(struct mtd_info *mtd, loff_t to, size_t len,
 	return 0;
 }
 
-
-
 static void unregister_devices(void)
 {
 	struct phram_mtd_list *this, *safe;
drivers/mtd/devices/spear_smi.c +0 -10
index f7b9949..520e387 100644
@@ -576,11 +576,6 @@ static int spear_mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
 		return -EINVAL;
 	}
 
-	if (!retlen)
-		return -EINVAL;
-	else
-		*retlen = 0;
-
 	/* select address as per bank number */
 	src = flash->base_addr + from;
 
@@ -677,11 +672,6 @@ static int spear_mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
 		return -EINVAL;
 	}
 
-	if (!retlen)
-		return -EINVAL;
-	else
-		*retlen = 0;
-
 	/* select address as per bank number */
 	dest = flash->base_addr + to;
 	mutex_lock(&flash->lock);
drivers/mtd/devices/sst25l.c +0 -3
index 99d4a3c..5c2613c 100644
@@ -224,9 +224,6 @@ static int sst25l_read(struct mtd_info *mtd, loff_t from, size_t len,
 	if (len == 0)
 		return 0;
 
-	if (retlen)
-		*retlen = 0;
-
 	spi_message_init(&message);
 	memset(&transfer, 0, sizeof(transfer));
 
drivers/mtd/lpddr/lpddr_cmds.c +0 -3
index 0f3731c..a92906b 100644
@@ -535,9 +535,7 @@ static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len,
 
 	/* ofs: offset within the first chip that the first read should start */
 	ofs = adr - (chipnum << lpddr->chipshift);
-
 	*mtdbuf = (void *)map->virt + chip->start + ofs;
-	*retlen = 0;
 
 	while (len) {
 		unsigned long thislen;
@@ -647,7 +645,6 @@ static int lpddr_writev(struct mtd_info *mtd, const struct kvec *vecs,
 	for (i = 0; i < count; i++)
 		len += vecs[i].iov_len;
 
-	*retlen = 0;
 	if (!len)
 		return 0;
 
drivers/mtd/mtdconcat.c +0 -6
index dd24232..f7a31cc 100644
@@ -72,8 +72,6 @@ concat_read(struct mtd_info *mtd, loff_t from, size_t len,
 	int ret = 0, err;
 	int i;
 
-	*retlen = 0;
-
 	for (i = 0; i < concat->num_subdev; i++) {
 		struct mtd_info *subdev = concat->subdev[i];
 		size_t size, retsize;
@@ -126,8 +124,6 @@ concat_write(struct mtd_info *mtd, loff_t to, size_t len,
 	int err = -EINVAL;
 	int i;
 
-	*retlen = 0;
-
 	for (i = 0; i < concat->num_subdev; i++) {
 		struct mtd_info *subdev = concat->subdev[i];
 		size_t size, retsize;
@@ -169,8 +165,6 @@ concat_writev(struct mtd_info *mtd, const struct kvec *vecs,
 	int i;
 	int err = -EINVAL;
 
-	*retlen = 0;
-
 	/* Calculate total length of data */
 	for (i = 0; i < count; i++)
 		total_len += vecs[i].iov_len;
drivers/mtd/onenand/onenand_base.c +0 -3
index 9c6445d..a1592cf 100644
@@ -1753,9 +1753,6 @@ static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 	pr_debug("%s: to = 0x%08x, len = %i\n", __func__, (unsigned int)to,
 			(int)len);
 
-	/* Initialize retlen, in case of early exit */
-	*retlen = 0;
-
 	/* Reject writes, which are not page aligned */
         if (unlikely(NOTALIGNED(to) || NOTALIGNED(len))) {
 		printk(KERN_ERR "%s: Attempt to write not page aligned data\n",
Signature · 1 line
1.7.9
#1 lore raw

PATCH 2/3 mtd: move zero length verification to MTD API functions

From: Artem Bityutskiy <[email protected]>

In many places in drivers we verify for the zero length, but this is very inconsistent across drivers. This is obviously the right thing to do, though. This patch moves the check to the MTD API functions instead and removes a lot of duplication.

---
 drivers/mtd/chips/cfi_cmdset_0001.c |    3 ---
 drivers/mtd/chips/cfi_cmdset_0002.c |    9 ---------
 drivers/mtd/chips/cfi_cmdset_0020.c |    3 ---
 drivers/mtd/devices/block2mtd.c     |    3 ---
 drivers/mtd/devices/lart.c          |    3 ---
 drivers/mtd/devices/m25p80.c        |   12 ------------
 drivers/mtd/devices/mtd_dataflash.c |   10 ----------
 drivers/mtd/devices/spear_smi.c     |    6 ------
 drivers/mtd/devices/sst25l.c        |    8 --------
 drivers/mtd/lpddr/lpddr_cmds.c      |    1 -
 drivers/mtd/maps/vmu-flash.c        |    8 --------
 drivers/mtd/mtdcore.c               |   21 +++++++++++++++++++++
 drivers/mtd/nand/nand_base.c        |   10 ----------
 13 files changed, 21 insertions(+), 76 deletions(-)
drivers/mtd/chips/cfi_cmdset_0001.c +0 -3
index dc66df6..2d96690 100644
@@ -1566,9 +1566,6 @@ static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le
 	int chipnum;
 	unsigned long ofs;
 
-	if (!len)
-		return 0;
-
 	chipnum = to >> cfi->chipshift;
 	ofs = to  - (chipnum << cfi->chipshift);
 
drivers/mtd/chips/cfi_cmdset_0002.c +0 -9
index a89d899..c1d4624 100644
@@ -1246,9 +1246,6 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
 	unsigned long ofs, chipstart;
 	DECLARE_WAITQUEUE(wait, current);
 
-	if (!len)
-		return 0;
-
 	chipnum = to >> cfi->chipshift;
 	ofs = to  - (chipnum << cfi->chipshift);
 	chipstart = cfi->chips[chipnum].start;
@@ -1487,9 +1484,6 @@ static int cfi_amdstd_write_buffers(struct mtd_info *mtd, loff_t to, size_t len,
 	int chipnum;
 	unsigned long ofs;
 
-	if (!len)
-		return 0;
-
 	chipnum = to >> cfi->chipshift;
 	ofs = to  - (chipnum << cfi->chipshift);
 
@@ -1697,9 +1691,6 @@ static int cfi_amdstd_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 	int ret = 0;
 	int chipnum;
 
-	if (!len)
-		return 0;
-
 	chipnum = to >> cfi->chipshift;
 	ofs = to - (chipnum << cfi->chipshift);
 	chipstart = cfi->chips[chipnum].start;
drivers/mtd/chips/cfi_cmdset_0020.c +0 -3
index d690b7d..096993f 100644
@@ -615,9 +615,6 @@ static int cfi_staa_write_buffers (struct mtd_info *mtd, loff_t to,
 	int chipnum;
 	unsigned long ofs;
 
-	if (!len)
-		return 0;
-
 	chipnum = to >> cfi->chipshift;
 	ofs = to  - (chipnum << cfi->chipshift);
 
drivers/mtd/devices/block2mtd.c +0 -3
index ba2d74b..a4a80b7 100644
@@ -178,9 +178,6 @@ static int block2mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
 	struct block2mtd_dev *dev = mtd->priv;
 	int err;
 
-	if (!len)
-		return 0;
-
 	mutex_lock(&dev->write_mutex);
 	err = _block2mtd_write(dev, buf, to, len, retlen);
 	mutex_unlock(&dev->write_mutex);
drivers/mtd/devices/lart.c +0 -3
index 6fb8dba..82bd00a 100644
@@ -437,9 +437,6 @@ static int flash_read (struct mtd_info *mtd,loff_t from,size_t len,size_t *retle
    printk (KERN_DEBUG "%s(from = 0x%.8x, len = %d)\n", __func__, (__u32)from, len);
 #endif
 
-   /* sanity checks */
-   if (!len) return (0);
-
    /* we always read len bytes */
    *retlen = len;
 
drivers/mtd/devices/m25p80.c +0 -12
index 45cc4a1..1924d24 100644
@@ -346,10 +346,6 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
 	pr_debug("%s: %s from 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
 			__func__, (u32)from, len);
 
-	/* sanity checks */
-	if (!len)
-		return 0;
-
 	spi_message_init(&m);
 	memset(t, 0, (sizeof t));
 
@@ -408,10 +404,6 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
 	pr_debug("%s: %s to 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
 			__func__, (u32)to, len);
 
-	/* sanity checks */
-	if (!len)
-		return(0);
-
 	spi_message_init(&m);
 	memset(t, 0, (sizeof t));
 
@@ -495,10 +487,6 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
 	pr_debug("%s: %s to 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
 			__func__, (u32)to, len);
 
-	/* sanity checks */
-	if (!len)
-		return 0;
-
 	spi_message_init(&m);
 	memset(t, 0, (sizeof t));
 
drivers/mtd/devices/mtd_dataflash.c +0 -10
index c76b446..928fb0e 100644
@@ -249,10 +249,6 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,
 	pr_debug("%s: read 0x%x..0x%x\n", dev_name(&priv->spi->dev),
 			(unsigned)from, (unsigned)(from + len));
 
-	/* Sanity checks */
-	if (!len)
-		return 0;
-
 	/* Calculate flash page/byte address */
 	addr = (((unsigned)from / priv->page_size) << priv->page_offset)
 		+ ((unsigned)from % priv->page_size);
@@ -321,10 +317,6 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
 	pr_debug("%s: write 0x%x..0x%x\n",
 		dev_name(&spi->dev), (unsigned)to, (unsigned)(to + len));
 
-	/* Sanity checks */
-	if (!len)
-		return 0;
-
 	spi_message_init(&msg);
 
 	x[0].tx_buf = command = priv->command;
@@ -479,8 +471,6 @@ static ssize_t otp_read(struct spi_device *spi, unsigned base,
 
 	if ((off + len) > 64)
 		len = 64 - off;
-	if (len == 0)
-		return len;
 
 	spi_message_init(&m);
 
drivers/mtd/devices/spear_smi.c +0 -6
index 520e387..4f7b682 100644
@@ -565,9 +565,6 @@ static int spear_mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
 	u32 ctrlreg1, val;
 	int ret;
 
-	if (!len)
-		return 0;
-
 	if (!flash || !dev)
 		return -ENODEV;
 
@@ -664,9 +661,6 @@ static int spear_mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
 	if (!flash || !dev)
 		return -ENODEV;
 
-	if (!len)
-		return 0;
-
 	if (flash->bank > dev->num_flashes - 1) {
 		dev_err(&dev->pdev->dev, "Invalid Bank Num");
 		return -EINVAL;
drivers/mtd/devices/sst25l.c +0 -8
index 5c2613c..51b2df3 100644
@@ -220,10 +220,6 @@ static int sst25l_read(struct mtd_info *mtd, loff_t from, size_t len,
 	unsigned char command[4];
 	int ret;
 
-	/* Sanity checking */
-	if (len == 0)
-		return 0;
-
 	spi_message_init(&message);
 	memset(&transfer, 0, sizeof(transfer));
 
@@ -265,10 +261,6 @@ static int sst25l_write(struct mtd_info *mtd, loff_t to, size_t len,
 	int i, j, ret, bytes, copied = 0;
 	unsigned char command[5];
 
-	/* Sanity checks */
-	if (!len)
-		return 0;
-
 	if ((uint32_t)to % mtd->writesize)
 		return -EINVAL;
 
drivers/mtd/lpddr/lpddr_cmds.c +0 -1
index a92906b..d3cfe26b 100644
@@ -639,7 +639,6 @@ static int lpddr_writev(struct mtd_info *mtd, const struct kvec *vecs,
 	int chipnum;
 	unsigned long ofs, vec_seek, i;
 	int wbufsize = 1 << lpddr->qinfo->BufSizeShift;
-
 	size_t len = 0;
 
 	for (i = 0; i < count; i++)
drivers/mtd/maps/vmu-flash.c +0 -8
index 48a803e..2e2b094 100644
@@ -360,9 +360,6 @@ static int vmu_flash_read(struct mtd_info *mtd, loff_t from, size_t len,
 	int index = 0, retval, partition, leftover, numblocks;
 	unsigned char cx;
 
-	if (len < 1)
-		return -EIO;
-
 	mpart = mtd->priv;
 	mdev = mpart->mdev;
 	partition = mpart->partition;
@@ -434,11 +431,6 @@ static int vmu_flash_write(struct mtd_info *mtd, loff_t to, size_t len,
 	partition = mpart->partition;
 	card = maple_get_drvdata(mdev);
 
-	/* simple sanity checks */
-	if (len < 1) {
-		error = -EIO;
-		goto failed;
-	}
 	numblocks = card->parts[partition].numblocks;
 	if (to + len > numblocks * card->blocklen)
 		len = numblocks * card->blocklen - to;
drivers/mtd/mtdcore.c +21 -0
index ad76a6a..9c49d87 100644
@@ -695,6 +695,11 @@ int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
 		return -EINVAL;
 	if (!(mtd->flags & MTD_WRITEABLE))
 		return -EROFS;
+	if (!instr->len) {
+		instr->state = MTD_ERASE_DONE;
+		mtd_erase_callback(instr);
+		return 0;
+	}
 	return mtd->_erase(mtd, instr);
 }
 EXPORT_SYMBOL_GPL(mtd_erase);
@@ -712,6 +717,8 @@ int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
 		return -EOPNOTSUPP;
 	if (from < 0 || from > mtd->size || len > mtd->size - from)
 		return -EINVAL;
+	if (!len)
+		return 0;
 	return mtd->_point(mtd, from, len, retlen, virt, phys);
 }
 EXPORT_SYMBOL_GPL(mtd_point);
@@ -723,6 +730,8 @@ int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
 		return -EOPNOTSUPP;
 	if (from < 0 || from > mtd->size || len > mtd->size - from)
 		return -EINVAL;
+	if (!len)
+		return 0;
 	return mtd->_unpoint(mtd, from, len);
 }
 EXPORT_SYMBOL_GPL(mtd_unpoint);
@@ -748,6 +757,8 @@ int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
 {
 	if (from < 0 || from > mtd->size || len > mtd->size - from)
 		return -EINVAL;
+	if (!len)
+		return 0;
 	return mtd->_read(mtd, from, len, retlen, buf);
 }
 EXPORT_SYMBOL_GPL(mtd_read);
@@ -760,6 +771,8 @@ int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
 		return -EINVAL;
 	if (!mtd->_write || !(mtd->flags & MTD_WRITEABLE))
 		return -EROFS;
+	if (!len)
+		return 0;
 	return mtd->_write(mtd, to, len, retlen, buf);
 }
 EXPORT_SYMBOL_GPL(mtd_write);
@@ -781,6 +794,8 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
 		return -EINVAL;
 	if (!(mtd->flags & MTD_WRITEABLE))
 		return -EROFS;
+	if (!len)
+		return 0;
 	return mtd->_panic_write(mtd, to, len, retlen, buf);
 }
 EXPORT_SYMBOL_GPL(mtd_panic_write);
@@ -792,6 +807,8 @@ int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 		return -EOPNOTSUPP;
 	if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
 		return -EINVAL;
+	if (!len)
+		return 0;
 	return mtd->_lock(mtd, ofs, len);
 }
 EXPORT_SYMBOL_GPL(mtd_lock);
@@ -802,6 +819,8 @@ int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 		return -EOPNOTSUPP;
 	if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
 		return -EINVAL;
+	if (!len)
+		return 0;
 	return mtd->_unlock(mtd, ofs, len);
 }
 EXPORT_SYMBOL_GPL(mtd_unlock);
@@ -812,6 +831,8 @@ int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 		return -EOPNOTSUPP;
 	if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
 		return -EINVAL;
+	if (!len)
+		return 0;
 	return mtd->_is_locked(mtd, ofs, len);
 }
 EXPORT_SYMBOL_GPL(mtd_is_locked);
drivers/mtd/nand/nand_base.c +0 -10
index daaa6a5..2d010e4 100644
@@ -1602,9 +1602,6 @@ static int nand_read(struct mtd_info *mtd, loff_t from, size_t len,
 	struct mtd_oob_ops ops;
 	int ret;
 
-	if (!len)
-		return 0;
-
 	nand_get_device(chip, mtd, FL_READING);
 	ops.len = len;
 	ops.datbuf = buf;
@@ -2301,10 +2298,6 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len,
 	struct mtd_oob_ops ops;
 	int ret;
 
-	/* Do not allow reads past end of device */
-	if (!len)
-		return 0;
-
 	/* Wait for the device to get ready */
 	panic_nand_wait(mtd, chip, 400);
 
@@ -2339,9 +2332,6 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
 	struct mtd_oob_ops ops;
 	int ret;
 
-	if (!len)
-		return 0;
-
 	nand_get_device(chip, mtd, FL_WRITING);
 	ops.len = len;
 	ops.datbuf = (uint8_t *)buf;
Signature · 1 line
1.7.9
#2 lore raw

Re: [PATCH 2/3] mtd: move zero length verification to MTD API functions

drivers/mtd/mtdcore.c int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, · line 723

Quoted 8 lines · On Mon, 6 Feb 2012 14:03:08 +0200 Artem Bityutskiy <[email protected]> wrote:
drivers/mtd/mtdcore.c +2 -0
@@ -712,6 +717,8 @@ int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
 		return -EOPNOTSUPP;
 	if (from < 0 || from > mtd->size || len > mtd->size - from)
 		return -EINVAL;
+	if (!len)
+		return 0;
 	return mtd->_point(mtd, from, len, retlen, virt, phys);
 }

Previously, '_point' implementors usually assigned *virt (e.g. for NOR - to the relevant ioremapped address), regardless 'len' value. Meaning, *virt was set, even in the 'len == 0' case.
New 'mtd_point()' does not set *virt in this case.

(Luckily, seems there are no calls to 'mtd_point' with zero 'len'...)

I guess it is safe to assume the *virt assignment in the '!len' case was wrong?

Regards
Shmulik

#3 lore raw

Re: [PATCH 2/3] mtd: move zero length verification to MTD API functions

Quoted 15 lines · Shmulik Ladkani

drivers/mtd/mtdcore.c int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, · line 723

Quoted 8 lines · On Mon, 6 Feb 2012 14:03:08 +0200 Artem Bityutskiy <[email protected]> wrote:
drivers/mtd/mtdcore.c +2 -0
@@ -712,6 +717,8 @@ int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
 		return -EOPNOTSUPP;
 	if (from < 0 || from > mtd->size || len > mtd->size - from)
 		return -EINVAL;
+	if (!len)
+		return 0;
 	return mtd->_point(mtd, from, len, retlen, virt, phys);
 }

Previously, '_point' implementors usually assigned *virt (e.g. for NOR - to the relevant ioremapped address), regardless 'len' value. Meaning, *virt was set, even in the 'len == 0' case.
New 'mtd_point()' does not set *virt in this case.

Quoted 4 lines

(Luckily, seems there are no calls to 'mtd_point' with zero 'len'...)

I guess it is safe to assume the *virt assignment in the '!len' case was wrong?

If length is zero then 'virt' is anyway useless. But we should set it to NULL in 'mtd_point()' to make sure that if someone accesses it he gets an oops. I'll amend the patch and update the commit message correspondingly, thanks a lot for review.

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#4 lore raw

Re: [PATCH 2/3] mtd: move zero length verification to MTD API functions

Quoted 18 lines · Artem Bityutskiy
Quoted 17 lines · Shmulik Ladkani

Review int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, · line 723

Quoted 8 lines · On Mon, 6 Feb 2012 14:03:08 +0200 Artem Bityutskiy <[email protected]> wrote:
(quoted diff) +2 -0
@@ -712,6 +717,8 @@ int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
 		return -EOPNOTSUPP;
 	if (from < 0 || from > mtd->size || len > mtd->size - from)
 		return -EINVAL;
+	if (!len)
+		return 0;
 	return mtd->_point(mtd, from, len, retlen, virt, phys);
 }

Previously, '_point' implementors usually assigned *virt (e.g. for NOR - to the relevant ioremapped address), regardless 'len' value. Meaning, *virt was set, even in the 'len == 0' case.
New 'mtd_point()' does not set *virt in this case.

(Luckily, seems there are no calls to 'mtd_point' with zero 'len'...)

Quoted 7 lines
Quoted 2 lines

I guess it is safe to assume the *virt assignment in the '!len' case was wrong?

If length is zero then 'virt' is anyway useless. But we should set it to NULL in 'mtd_point()' to make sure that if someone accesses it he gets an oops. I'll amend the patch and update the commit message correspondingly, thanks a lot for review.

I guess we can go a bit further and sanitize 'mtd_point()' like this:

From: Artem Bityutskiy <[email protected]>
Date: Wed, 8 Feb 2012 15:13:26 +0200
Subject: [PATCH] mtd: harmonize mtd_point interface implementation

Some MTD drivers return -EINVAL if the 'phys' parameter is not NULL, trying to convey that they cannot return the physical address. However, this is not very logical because they still can return the virtual address ('virt'). But some drivers (lpddr) just ignore the 'phys' parameter instead, which is a more logical thing to do.

Let's harmonize this and:

1. Always initialize 'virt' and 'phys' to 'NULL' in 'mtd_point()'.
2. Do not return an error if the physical address cannot be found.

So as a result, all drivers will set 'phys' to 'NULL' if it is not supported. None of the 'mtd_point()' users use 'phys' anyway, so this should not break anything. I guess we could also just delete this parameter later.

---
 drivers/mtd/devices/mtdram.c |    3 ---
 drivers/mtd/devices/phram.c  |    4 ----
 drivers/mtd/devices/pmc551.c |    4 ----
 drivers/mtd/devices/slram.c  |    3 ---
 drivers/mtd/mtdcore.c        |    3 +++
 5 files changed, 3 insertions(+), 14 deletions(-)
drivers/mtd/devices/mtdram.c +0 -3
index 0e0e6ed..ec59d65 100644
@@ -43,9 +43,6 @@ static int ram_erase(struct mtd_info *mtd, struct erase_info *instr)
 static int ram_point(struct mtd_info *mtd, loff_t from, size_t len,
 		size_t *retlen, void **virt, resource_size_t *phys)
 {
-	/* can we return a physical address with this driver? */
-	if (phys)
-		return -EINVAL;
 	*virt = mtd->priv + from;
 	*retlen = len;
 	return 0;
drivers/mtd/devices/phram.c +0 -4
index d3474a4..9d2bf17 100644
@@ -51,10 +51,6 @@ static int phram_erase(struct mtd_info *mtd, struct erase_info *instr)
 static int phram_point(struct mtd_info *mtd, loff_t from, size_t len,
 		size_t *retlen, void **virt, resource_size_t *phys)
 {
-	/* can we return a physical address with this driver? */
-	if (phys)
-		return -EINVAL;
-
 	*virt = mtd->priv + from;
 	*retlen = len;
 	return 0;
drivers/mtd/devices/pmc551.c +0 -4
index 6269a43..c4368ec 100644
@@ -205,10 +205,6 @@ static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len,
 	printk(KERN_DEBUG "pmc551_point(%ld, %ld)\n", (long)from, (long)len);
 #endif
 
-	/* can we return a physical address with this driver? */
-	if (phys)
-		return -EINVAL;
-
 	soff_hi = from & ~(priv->asize - 1);
 	soff_lo = from & (priv->asize - 1);
 
drivers/mtd/devices/slram.c +0 -3
index 842e489..ccd39ff 100644
@@ -99,9 +99,6 @@ static int slram_point(struct mtd_info *mtd, loff_t from, size_t len,
 {
 	slram_priv_t *priv = mtd->priv;
 
-	/* can we return a physical address with this driver? */
-	if (phys)
-		return -EINVAL;
 	*virt = priv->start + from;
 	*retlen = len;
 	return(0);
drivers/mtd/mtdcore.c +3 -0
index ead52b3..1680ef5 100644
@@ -706,6 +706,9 @@ int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
 	      void **virt, resource_size_t *phys)
 {
 	*retlen = 0;
+	*virt = NULL;
+	if (phys)
+		*phys = NULL;
 	if (!mtd->_point)
 		return -EOPNOTSUPP;
 	if (from < 0 || from > mtd->size || len > mtd->size - from)
Signature · 5 lines
1.7.9

-- 
Best Regards,
Artem Bityutskiy
Reviewed-by
#5 lore raw

Re: [PATCH 2/3] mtd: move zero length verification to MTD API functions

Quoted 12 lines · On Wed, 08 Feb 2012 15:26:38 +0200 Artem Bityutskiy <[email protected]> wrote:

I guess we can go a bit further and sanitize 'mtd_point()' like this:

From: Artem Bityutskiy <[email protected]>
Date: Wed, 8 Feb 2012 15:13:26 +0200
Subject: [PATCH] mtd: harmonize mtd_point interface implementation

Some MTD drivers return -EINVAL if the 'phys' parameter is not NULL, trying to convey that they cannot return the physical address. However, this is not very logical because they still can return the virtual address ('virt'). But some drivers (lpddr) just ignore the 'phys' parameter instead, which is a more logical thing to do.

Quoted 8 lines

Let's harmonize this and:

1. Always initialize 'virt' and 'phys' to 'NULL' in 'mtd_point()'.
2. Do not return an error if the physical address cannot be found.

So as a result, all drivers will set 'phys' to 'NULL' if it is not supported. None of the 'mtd_point()' users use 'phys' anyway, so this should not break anything. I guess we could also just delete this parameter later.

According to a98889f3, it makes some sense to return an error when users explicitly asked for the 'phys' but driver is unable to return it.

I guess new interface (checking the returned 'phys') is reasonable as well. And, nothing gets broken since no such users...

Reviewed-by [email protected]
author Reviewed-by Shmulik Ladkani
#6 lore raw

Re: [PATCH 2/3] mtd: move zero length verification to MTD API functions

Quoted 4 lines · Shmulik Ladkani

I guess new interface (checking the returned 'phys') is reasonable as well. And, nothing gets broken since no such users...

Reviewed-by [email protected]

Thanks, but I added more preferable

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#7 lore raw

PATCH 3/3 mtd: remove junk pmc551.h

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

This header is tiny and contains only pmc551-private stuff, so it should not live in 'include/linux' - let's just merge it with pmc551.c.

---
 drivers/mtd/devices/pmc551.c |   40 ++++++++++++++++++++-
 include/linux/mtd/pmc551.h   |   77 ------------------------------------------
 2 files changed, 38 insertions(+), 79 deletions(-)
 delete mode 100644 include/linux/mtd/pmc551.h
drivers/mtd/devices/pmc551.c +38 -2
index 725198d..ced47ce 100644
@@ -95,9 +95,45 @@
 #include <asm/io.h>
 #include <asm/system.h>
 #include <linux/pci.h>
-
 #include <linux/mtd/mtd.h>
-#include <linux/mtd/pmc551.h>
+
+#define PMC551_VERSION \
+       "Ramix PMC551 PCI Mezzanine Ram Driver. (C) 1999,2000 Nortel Networks.\n"
+
+#define PCI_VENDOR_ID_V3_SEMI             0x11b0
+#define PCI_DEVICE_ID_V3_SEMI_V370PDC     0x0200
+
+#define PMC551_PCI_MEM_MAP0	0x50
+#define PMC551_PCI_MEM_MAP1	0x54
+#define PMC551_PCI_MEM_MAP_MAP_ADDR_MASK	0x3ff00000
+#define PMC551_PCI_MEM_MAP_APERTURE_MASK	0x000000f0
+#define PMC551_PCI_MEM_MAP_REG_EN		0x00000002
+#define PMC551_PCI_MEM_MAP_ENABLE		0x00000001
+
+#define PMC551_SDRAM_MA		0x60
+#define PMC551_SDRAM_CMD	0x62
+#define PMC551_DRAM_CFG		0x64
+#define PMC551_SYS_CTRL_REG	0x78
+
+#define PMC551_DRAM_BLK0	0x68
+#define PMC551_DRAM_BLK1	0x6c
+#define PMC551_DRAM_BLK2	0x70
+#define PMC551_DRAM_BLK3	0x74
+#define PMC551_DRAM_BLK_GET_SIZE(x) (524288<<((x>>4)&0x0f))
+#define PMC551_DRAM_BLK_SET_COL_MUX(x,v) (((x) & ~0x00007000) | (((v) & 0x7) << 12))
+#define PMC551_DRAM_BLK_SET_ROW_MUX(x,v) (((x) & ~0x00000f00) | (((v) & 0xf) << 8))
+
+/*
+ * Our personal and private information
+ */
+struct mypriv {
+        struct pci_dev *dev;
+        u_char *start;
+        u32    base_map0;
+        u32    curr_map0;
+        u32    asize;
+	struct mtd_info *nextpmc551;
+};
 
 static struct mtd_info *pmc551list;
 
include/linux/mtd/pmc551.h deleted +0 -77

77 lines not on this page · raw message

Signature · 1 line
1.7.9
#8 lore raw
In reply to Artem Bityutskiy
Quoted 6 lines · On Mon, 6 Feb 2012 14:03:07 +0200 Artem Bityutskiy <[email protected]> wrote:

From: Artem Bityutskiy <[email protected]>

The MTD API function now zero the 'retlen' parameter before calling the driver's method - do not do this again in dirvers. This removes duplicated '*retlen = 0' assignent from the following methods:

Quoted 6 lines
    'mtd_point()'
    'mtd_read()'
    'mtd_write()'
    'mtd_writev()'
    'mtd_panic_write()'

Seems that '*retlen = 0' is missing from mtd_read() in l2-mtd. Deliberately? or am I looking at the wrong repo?

Regards
Shmulik

#9 lore raw
Quoted 14 lines · Shmulik Ladkani
Quoted 6 lines · On Mon, 6 Feb 2012 14:03:07 +0200 Artem Bityutskiy <[email protected]> wrote:

From: Artem Bityutskiy <[email protected]>

The MTD API function now zero the 'retlen' parameter before calling the driver's method - do not do this again in dirvers. This removes duplicated '*retlen = 0' assignent from the following methods:

Quoted 6 lines
    'mtd_point()'
    'mtd_read()'
    'mtd_write()'
    'mtd_writev()'
    'mtd_panic_write()'
Quoted 2 lines

Seems that '*retlen = 0' is missing from mtd_read() in l2-mtd. Deliberately? or am I looking at the wrong repo?

Not, oversight, fixed in the repo.

Signature · 2 lines
Best Regards,
Artem Bityutskiy