aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/devices
diff options
context:
space:
mode:
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-02-06 06:27:43 -0500
committerDavid Woodhouse <David.Woodhouse@intel.com>2012-03-26 19:32:19 -0400
commitbcb1d238716d138c9e16347fc32b3c1ae006339e (patch)
treeccb7a9aea7b77481fa3474124218521e0c32de82 /drivers/mtd/devices
parent0dd5235f51fb0eb0b8cef3fed35be39b8a06d7bd (diff)
mtd: move zero length verification to MTD API functions
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. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Reviewed-by: Shmulik Ladkani <shmulik.ladkani@gmail.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd/devices')
-rw-r--r--drivers/mtd/devices/block2mtd.c3
-rw-r--r--drivers/mtd/devices/lart.c3
-rw-r--r--drivers/mtd/devices/m25p80.c12
-rw-r--r--drivers/mtd/devices/mtd_dataflash.c10
-rw-r--r--drivers/mtd/devices/spear_smi.c6
-rw-r--r--drivers/mtd/devices/sst25l.c8
6 files changed, 0 insertions, 42 deletions
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index ba2d74b01c7e..a4a80b742e65 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -178,9 +178,6 @@ static int block2mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
178 struct block2mtd_dev *dev = mtd->priv; 178 struct block2mtd_dev *dev = mtd->priv;
179 int err; 179 int err;
180 180
181 if (!len)
182 return 0;
183
184 mutex_lock(&dev->write_mutex); 181 mutex_lock(&dev->write_mutex);
185 err = _block2mtd_write(dev, buf, to, len, retlen); 182 err = _block2mtd_write(dev, buf, to, len, retlen);
186 mutex_unlock(&dev->write_mutex); 183 mutex_unlock(&dev->write_mutex);
diff --git a/drivers/mtd/devices/lart.c b/drivers/mtd/devices/lart.c
index 6fb8dba76959..82bd00af5cc3 100644
--- a/drivers/mtd/devices/lart.c
+++ b/drivers/mtd/devices/lart.c
@@ -437,9 +437,6 @@ static int flash_read (struct mtd_info *mtd,loff_t from,size_t len,size_t *retle
437 printk (KERN_DEBUG "%s(from = 0x%.8x, len = %d)\n", __func__, (__u32)from, len); 437 printk (KERN_DEBUG "%s(from = 0x%.8x, len = %d)\n", __func__, (__u32)from, len);
438#endif 438#endif
439 439
440 /* sanity checks */
441 if (!len) return (0);
442
443 /* we always read len bytes */ 440 /* we always read len bytes */
444 *retlen = len; 441 *retlen = len;
445 442
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 45cc4a1ae5b0..1924d247c1cb 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -346,10 +346,6 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
346 pr_debug("%s: %s from 0x%08x, len %zd\n", dev_name(&flash->spi->dev), 346 pr_debug("%s: %s from 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
347 __func__, (u32)from, len); 347 __func__, (u32)from, len);
348 348
349 /* sanity checks */
350 if (!len)
351 return 0;
352
353 spi_message_init(&m); 349 spi_message_init(&m);
354 memset(t, 0, (sizeof t)); 350 memset(t, 0, (sizeof t));
355 351
@@ -408,10 +404,6 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
408 pr_debug("%s: %s to 0x%08x, len %zd\n", dev_name(&flash->spi->dev), 404 pr_debug("%s: %s to 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
409 __func__, (u32)to, len); 405 __func__, (u32)to, len);
410 406
411 /* sanity checks */
412 if (!len)
413 return(0);
414
415 spi_message_init(&m); 407 spi_message_init(&m);
416 memset(t, 0, (sizeof t)); 408 memset(t, 0, (sizeof t));
417 409
@@ -495,10 +487,6 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
495 pr_debug("%s: %s to 0x%08x, len %zd\n", dev_name(&flash->spi->dev), 487 pr_debug("%s: %s to 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
496 __func__, (u32)to, len); 488 __func__, (u32)to, len);
497 489
498 /* sanity checks */
499 if (!len)
500 return 0;
501
502 spi_message_init(&m); 490 spi_message_init(&m);
503 memset(t, 0, (sizeof t)); 491 memset(t, 0, (sizeof t));
504 492
diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c
index c76b4464e8b9..928fb0e6d73a 100644
--- a/drivers/mtd/devices/mtd_dataflash.c
+++ b/drivers/mtd/devices/mtd_dataflash.c
@@ -249,10 +249,6 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,
249 pr_debug("%s: read 0x%x..0x%x\n", dev_name(&priv->spi->dev), 249 pr_debug("%s: read 0x%x..0x%x\n", dev_name(&priv->spi->dev),
250 (unsigned)from, (unsigned)(from + len)); 250 (unsigned)from, (unsigned)(from + len));
251 251
252 /* Sanity checks */
253 if (!len)
254 return 0;
255
256 /* Calculate flash page/byte address */ 252 /* Calculate flash page/byte address */
257 addr = (((unsigned)from / priv->page_size) << priv->page_offset) 253 addr = (((unsigned)from / priv->page_size) << priv->page_offset)
258 + ((unsigned)from % priv->page_size); 254 + ((unsigned)from % priv->page_size);
@@ -321,10 +317,6 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
321 pr_debug("%s: write 0x%x..0x%x\n", 317 pr_debug("%s: write 0x%x..0x%x\n",
322 dev_name(&spi->dev), (unsigned)to, (unsigned)(to + len)); 318 dev_name(&spi->dev), (unsigned)to, (unsigned)(to + len));
323 319
324 /* Sanity checks */
325 if (!len)
326 return 0;
327
328 spi_message_init(&msg); 320 spi_message_init(&msg);
329 321
330 x[0].tx_buf = command = priv->command; 322 x[0].tx_buf = command = priv->command;
@@ -479,8 +471,6 @@ static ssize_t otp_read(struct spi_device *spi, unsigned base,
479 471
480 if ((off + len) > 64) 472 if ((off + len) > 64)
481 len = 64 - off; 473 len = 64 - off;
482 if (len == 0)
483 return len;
484 474
485 spi_message_init(&m); 475 spi_message_init(&m);
486 476
diff --git a/drivers/mtd/devices/spear_smi.c b/drivers/mtd/devices/spear_smi.c
index 2cdbcc65b39f..f45dd37b771e 100644
--- a/drivers/mtd/devices/spear_smi.c
+++ b/drivers/mtd/devices/spear_smi.c
@@ -563,9 +563,6 @@ static int spear_mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
563 u32 ctrlreg1, val; 563 u32 ctrlreg1, val;
564 int ret; 564 int ret;
565 565
566 if (!len)
567 return 0;
568
569 if (!flash || !dev) 566 if (!flash || !dev)
570 return -ENODEV; 567 return -ENODEV;
571 568
@@ -662,9 +659,6 @@ static int spear_mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
662 if (!flash || !dev) 659 if (!flash || !dev)
663 return -ENODEV; 660 return -ENODEV;
664 661
665 if (!len)
666 return 0;
667
668 if (flash->bank > dev->num_flashes - 1) { 662 if (flash->bank > dev->num_flashes - 1) {
669 dev_err(&dev->pdev->dev, "Invalid Bank Num"); 663 dev_err(&dev->pdev->dev, "Invalid Bank Num");
670 return -EINVAL; 664 return -EINVAL;
diff --git a/drivers/mtd/devices/sst25l.c b/drivers/mtd/devices/sst25l.c
index 5c2613c99e4a..51b2df33b8e9 100644
--- a/drivers/mtd/devices/sst25l.c
+++ b/drivers/mtd/devices/sst25l.c
@@ -220,10 +220,6 @@ static int sst25l_read(struct mtd_info *mtd, loff_t from, size_t len,
220 unsigned char command[4]; 220 unsigned char command[4];
221 int ret; 221 int ret;
222 222
223 /* Sanity checking */
224 if (len == 0)
225 return 0;
226
227 spi_message_init(&message); 223 spi_message_init(&message);
228 memset(&transfer, 0, sizeof(transfer)); 224 memset(&transfer, 0, sizeof(transfer));
229 225
@@ -265,10 +261,6 @@ static int sst25l_write(struct mtd_info *mtd, loff_t to, size_t len,
265 int i, j, ret, bytes, copied = 0; 261 int i, j, ret, bytes, copied = 0;
266 unsigned char command[5]; 262 unsigned char command[5];
267 263
268 /* Sanity checks */
269 if (!len)
270 return 0;
271
272 if ((uint32_t)to % mtd->writesize) 264 if ((uint32_t)to % mtd->writesize)
273 return -EINVAL; 265 return -EINVAL;
274 266