Merge tag 'spi-nor/for-5.1' of git://git.infradead.org/linux-mtd into mtd/next
authorBoris Brezillon <boris.brezillon@collabora.com>
Mon, 25 Feb 2019 08:28:25 +0000 (09:28 +0100)
committerBoris Brezillon <boris.brezillon@collabora.com>
Mon, 25 Feb 2019 08:28:25 +0000 (09:28 +0100)
SPI NOR Changes
  Core changes:
  - Add support of octal mode I/O transfer
  - Add a bunch of SPI NOR entries to the flash_info table

  SPI NOR controller driver changes:
  - cadence-quadspi:
    * Add support for Octal SPI controller
    * write upto 8-bytes data in STIG mode
  - mtk-quadspi:
    * rename config to a common one
    * add SNOR_HWCAPS_READ to spi_nor_hwcaps mask

MAINTAINERS:
- Add Tudor as SPI-NOR co-maintainer

drivers/mtd/chips/cfi_cmdset_0001.c
drivers/mtd/chips/gen_probe.c
drivers/mtd/devices/docg3.c
drivers/mtd/devices/mtdram.c
drivers/mtd/lpddr/qinfo_probe.c
drivers/mtd/mtdcore.c

index 6e8e7b1..79a53cb 100644 (file)
@@ -756,7 +756,8 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
                }
 
                numvirtchips = cfi->numchips * numparts;
-               newcfi = kmalloc(sizeof(struct cfi_private) + numvirtchips * sizeof(struct flchip), GFP_KERNEL);
+               newcfi = kmalloc(struct_size(newcfi, chips, numvirtchips),
+                                GFP_KERNEL);
                if (!newcfi)
                        return -ENOMEM;
                shared = kmalloc_array(cfi->numchips,
index 837b04a..839ed40 100644 (file)
@@ -135,7 +135,7 @@ static struct cfi_private *genprobe_ident_chips(struct map_info *map, struct chi
         * our caller, and copy the appropriate data into them.
         */
 
-       retcfi = kmalloc(sizeof(struct cfi_private) + cfi.numchips * sizeof(struct flchip), GFP_KERNEL);
+       retcfi = kmalloc(struct_size(retcfi, chips, cfi.numchips), GFP_KERNEL);
 
        if (!retcfi) {
                kfree(cfi.cfiq);
index 4c94fc0..7754803 100644 (file)
@@ -1767,8 +1767,8 @@ static int __init doc_set_driver_info(int chip_id, struct mtd_info *mtd)
 
        switch (chip_id) {
        case DOC_CHIPID_G3:
-               mtd->name = kasprintf(GFP_KERNEL, "docg3.%d",
-                                     docg3->device_id);
+               mtd->name = devm_kasprintf(docg3->dev, GFP_KERNEL, "docg3.%d",
+                                          docg3->device_id);
                if (!mtd->name)
                        return -ENOMEM;
                docg3->max_block = 2047;
@@ -1872,7 +1872,7 @@ nomem3:
 nomem2:
        kfree(docg3);
 nomem1:
-       return ERR_PTR(ret);
+       return ret ? ERR_PTR(ret) : NULL;
 }
 
 /**
@@ -1886,7 +1886,6 @@ static void doc_release_device(struct mtd_info *mtd)
        mtd_device_unregister(mtd);
        kfree(docg3->bbt);
        kfree(docg3);
-       kfree(mtd->name);
        kfree(mtd);
 }
 
index 4623879..1c97fab 100644 (file)
@@ -24,14 +24,12 @@ static unsigned long writebuf_size = 64;
 #define MTDRAM_TOTAL_SIZE (total_size * 1024)
 #define MTDRAM_ERASE_SIZE (erase_size * 1024)
 
-#ifdef MODULE
 module_param(total_size, ulong, 0);
 MODULE_PARM_DESC(total_size, "Total device size in KiB");
 module_param(erase_size, ulong, 0);
 MODULE_PARM_DESC(erase_size, "Device erase block size in KiB");
 module_param(writebuf_size, ulong, 0);
 MODULE_PARM_DESC(writebuf_size, "Device write buf size in Bytes (Default: 64)");
-#endif
 
 // We could store these in the mtd structure, but we only support 1 device..
 static struct mtd_info *mtd_info;
index 69f2112..175bdc3 100644 (file)
@@ -181,8 +181,8 @@ static struct lpddr_private *lpddr_probe_chip(struct map_info *map)
        lpddr.numchips = 1;
 
        numvirtchips = lpddr.numchips * lpddr.qinfo->HWPartsNum;
-       retlpddr = kzalloc(sizeof(struct lpddr_private) +
-                       numvirtchips * sizeof(struct flchip), GFP_KERNEL);
+       retlpddr = kzalloc(struct_size(retlpddr, chips, numvirtchips),
+                          GFP_KERNEL);
        if (!retlpddr)
                return NULL;
 
index 21e3cdc..c69b33c 100644 (file)
@@ -155,7 +155,6 @@ static ssize_t mtd_flags_show(struct device *dev,
        struct mtd_info *mtd = dev_get_drvdata(dev);
 
        return snprintf(buf, PAGE_SIZE, "0x%lx\n", (unsigned long)mtd->flags);
-
 }
 static DEVICE_ATTR(flags, S_IRUGO, mtd_flags_show, NULL);
 
@@ -166,7 +165,6 @@ static ssize_t mtd_size_show(struct device *dev,
 
        return snprintf(buf, PAGE_SIZE, "%llu\n",
                (unsigned long long)mtd->size);
-
 }
 static DEVICE_ATTR(size, S_IRUGO, mtd_size_show, NULL);
 
@@ -176,7 +174,6 @@ static ssize_t mtd_erasesize_show(struct device *dev,
        struct mtd_info *mtd = dev_get_drvdata(dev);
 
        return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->erasesize);
-
 }
 static DEVICE_ATTR(erasesize, S_IRUGO, mtd_erasesize_show, NULL);
 
@@ -186,7 +183,6 @@ static ssize_t mtd_writesize_show(struct device *dev,
        struct mtd_info *mtd = dev_get_drvdata(dev);
 
        return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->writesize);
-
 }
 static DEVICE_ATTR(writesize, S_IRUGO, mtd_writesize_show, NULL);
 
@@ -197,7 +193,6 @@ static ssize_t mtd_subpagesize_show(struct device *dev,
        unsigned int subpagesize = mtd->writesize >> mtd->subpage_sft;
 
        return snprintf(buf, PAGE_SIZE, "%u\n", subpagesize);
-
 }
 static DEVICE_ATTR(subpagesize, S_IRUGO, mtd_subpagesize_show, NULL);
 
@@ -207,7 +202,6 @@ static ssize_t mtd_oobsize_show(struct device *dev,
        struct mtd_info *mtd = dev_get_drvdata(dev);
 
        return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->oobsize);
-
 }
 static DEVICE_ATTR(oobsize, S_IRUGO, mtd_oobsize_show, NULL);
 
@@ -226,7 +220,6 @@ static ssize_t mtd_numeraseregions_show(struct device *dev,
        struct mtd_info *mtd = dev_get_drvdata(dev);
 
        return snprintf(buf, PAGE_SIZE, "%u\n", mtd->numeraseregions);
-
 }
 static DEVICE_ATTR(numeraseregions, S_IRUGO, mtd_numeraseregions_show,
        NULL);
@@ -237,7 +230,6 @@ static ssize_t mtd_name_show(struct device *dev,
        struct mtd_info *mtd = dev_get_drvdata(dev);
 
        return snprintf(buf, PAGE_SIZE, "%s\n", mtd->name);
-
 }
 static DEVICE_ATTR(name, S_IRUGO, mtd_name_show, NULL);
 
@@ -559,6 +551,14 @@ int add_mtd_device(struct mtd_info *mtd)
 
        BUG_ON(mtd->writesize == 0);
 
+       /*
+        * MTD drivers should implement ->_{write,read}() or
+        * ->_{write,read}_oob(), but not both.
+        */
+       if (WARN_ON((mtd->_write && mtd->_write_oob) ||
+                   (mtd->_read && mtd->_read_oob)))
+               return -EINVAL;
+
        if (WARN_ON((!mtd->erasesize || !mtd->_erase) &&
                    !(mtd->flags & MTD_NO_ERASE)))
                return -EINVAL;
@@ -1089,67 +1089,32 @@ EXPORT_SYMBOL_GPL(mtd_get_unmapped_area);
 int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
             u_char *buf)
 {
-       int ret_code;
-       *retlen = 0;
-       if (from < 0 || from >= mtd->size || len > mtd->size - from)
-               return -EINVAL;
-       if (!len)
-               return 0;
+       struct mtd_oob_ops ops = {
+               .len = len,
+               .datbuf = buf,
+       };
+       int ret;
 
-       ledtrig_mtd_activity();
-       /*
-        * In the absence of an error, drivers return a non-negative integer
-        * representing the maximum number of bitflips that were corrected on
-        * any one ecc region (if applicable; zero otherwise).
-        */
-       if (mtd->_read) {
-               ret_code = mtd->_read(mtd, from, len, retlen, buf);
-       } else if (mtd->_read_oob) {
-               struct mtd_oob_ops ops = {
-                       .len = len,
-                       .datbuf = buf,
-               };
-
-               ret_code = mtd->_read_oob(mtd, from, &ops);
-               *retlen = ops.retlen;
-       } else {
-               return -ENOTSUPP;
-       }
+       ret = mtd_read_oob(mtd, from, &ops);
+       *retlen = ops.retlen;
 
-       if (unlikely(ret_code < 0))
-               return ret_code;
-       if (mtd->ecc_strength == 0)
-               return 0;       /* device lacks ecc */
-       return ret_code >= mtd->bitflip_threshold ? -EUCLEAN : 0;
+       return ret;
 }
 EXPORT_SYMBOL_GPL(mtd_read);
 
 int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
              const u_char *buf)
 {
-       *retlen = 0;
-       if (to < 0 || to >= mtd->size || len > mtd->size - to)
-               return -EINVAL;
-       if ((!mtd->_write && !mtd->_write_oob) ||
-           !(mtd->flags & MTD_WRITEABLE))
-               return -EROFS;
-       if (!len)
-               return 0;
-       ledtrig_mtd_activity();
+       struct mtd_oob_ops ops = {
+               .len = len,
+               .datbuf = (u8 *)buf,
+       };
+       int ret;
 
-       if (!mtd->_write) {
-               struct mtd_oob_ops ops = {
-                       .len = len,
-                       .datbuf = (u8 *)buf,
-               };
-               int ret;
+       ret = mtd_write_oob(mtd, to, &ops);
+       *retlen = ops.retlen;
 
-               ret = mtd->_write_oob(mtd, to, &ops);
-               *retlen = ops.retlen;
-               return ret;
-       }
-
-       return mtd->_write(mtd, to, len, retlen, buf);
+       return ret;
 }
 EXPORT_SYMBOL_GPL(mtd_write);