mtd: core: Constify buf in mtd_write_user_prot_reg()
authorTudor Ambarus <tudor.ambarus@microchip.com>
Sat, 3 Apr 2021 06:09:31 +0000 (09:09 +0300)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Fri, 16 Apr 2021 18:30:54 +0000 (20:30 +0200)
The write buffer comes from user and should be const.
Constify write buffer in mtd core and across all _write_user_prot_reg()
users. cfi_cmdset_{0001, 0002} and onenand_base will pay the cost of an
explicit cast to discard the const qualifier since the beginning, since
they are using an otp_op_t function prototype that is used for both reads
and writes. mtd_dataflash and SPI NOR will benefit of the const buffer
because they are using different paths for writes and reads.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20210403060931.7119-1-tudor.ambarus@microchip.com
drivers/mtd/chips/cfi_cmdset_0001.c
drivers/mtd/chips/cfi_cmdset_0002.c
drivers/mtd/devices/mtd_dataflash.c
drivers/mtd/mtdcore.c
drivers/mtd/nand/onenand/onenand_base.c
drivers/mtd/spi-nor/core.h
drivers/mtd/spi-nor/otp.c
include/linux/mtd/mtd.h

index b7f5e7977dcd66f5da78023c887da10a9d748904..54f92d09d9cf430c3bd3a63f3dd4634cbbab0400 100644 (file)
@@ -72,7 +72,8 @@ static int cfi_intelext_is_locked(struct mtd_info *mtd, loff_t ofs,
 #ifdef CONFIG_MTD_OTP
 static int cfi_intelext_read_fact_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
 static int cfi_intelext_read_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
-static int cfi_intelext_write_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
+static int cfi_intelext_write_user_prot_reg(struct mtd_info *, loff_t, size_t,
+                                           size_t *, const u_char *);
 static int cfi_intelext_lock_user_prot_reg (struct mtd_info *, loff_t, size_t);
 static int cfi_intelext_get_fact_prot_info(struct mtd_info *, size_t,
                                           size_t *, struct otp_info *);
@@ -2447,10 +2448,10 @@ static int cfi_intelext_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
 
 static int cfi_intelext_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
                                            size_t len, size_t *retlen,
-                                            u_char *buf)
+                                           const u_char *buf)
 {
        return cfi_intelext_otp_walk(mtd, from, len, retlen,
-                                    buf, do_otp_write, 1);
+                                    (u_char *)buf, do_otp_write, 1);
 }
 
 static int cfi_intelext_lock_user_prot_reg(struct mtd_info *mtd,
index c5c9a4c3b02754fb70c790d9271dfcac67fd23e5..3097e93787f72625dfc4a22888aec35c68141f1e 100644 (file)
@@ -80,7 +80,7 @@ static int cfi_amdstd_read_fact_prot_reg(struct mtd_info *, loff_t, size_t,
 static int cfi_amdstd_read_user_prot_reg(struct mtd_info *, loff_t, size_t,
                                         size_t *, u_char *);
 static int cfi_amdstd_write_user_prot_reg(struct mtd_info *, loff_t, size_t,
-                                         size_t *, u_char *);
+                                         size_t *, const u_char *);
 static int cfi_amdstd_lock_user_prot_reg(struct mtd_info *, loff_t, size_t);
 
 static int cfi_amdstd_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
@@ -1635,9 +1635,9 @@ static int cfi_amdstd_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
 
 static int cfi_amdstd_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
                                          size_t len, size_t *retlen,
-                                         u_char *buf)
+                                         const u_char *buf)
 {
-       return cfi_amdstd_otp_walk(mtd, from, len, retlen, buf,
+       return cfi_amdstd_otp_walk(mtd, from, len, retlen, (u_char *)buf,
                                   do_otp_write, 1);
 }
 
index 6d1eefe941069f1eebe89210aa4c3df6cf9d6a8e..9802e265fca80a56cd7be99488713dc22dc55246 100644 (file)
@@ -527,7 +527,7 @@ static int dataflash_read_user_otp(struct mtd_info *mtd,
 }
 
 static int dataflash_write_user_otp(struct mtd_info *mtd,
-               loff_t from, size_t len, size_t *retlen, u_char *buf)
+               loff_t from, size_t len, size_t *retlen, const u_char *buf)
 {
        struct spi_message      m;
        const size_t            l = 4 + 64;
index 0bc6871c3863a8b80c218906b85b7443939d7ba4..9aaeadd53eb4f77c19112b22b34d73c8e385aa58 100644 (file)
@@ -1889,7 +1889,7 @@ int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
 EXPORT_SYMBOL_GPL(mtd_read_user_prot_reg);
 
 int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
-                           size_t *retlen, u_char *buf)
+                           size_t *retlen, const u_char *buf)
 {
        struct mtd_info *master = mtd_get_master(mtd);
        int ret;
index a9fdea26ea464be8acf0d773a592c5a9b2a17a7b..958bac54b19078554a06c08019ddcd7abe02c41a 100644 (file)
@@ -3167,9 +3167,10 @@ static int onenand_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
  * Write user OTP area.
  */
 static int onenand_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
-                       size_t len, size_t *retlen, u_char *buf)
+                       size_t len, size_t *retlen, const u_char *buf)
 {
-       return onenand_otp_walk(mtd, from, len, retlen, buf, do_otp_write, MTD_OTP_USER);
+       return onenand_otp_walk(mtd, from, len, retlen, (u_char *)buf,
+                               do_otp_write, MTD_OTP_USER);
 }
 
 /**
index e9b6b2e76cdb80c1bd3bd794b616c86a3e0bdf62..28a2e0be97a3b6405cafc6dd4a0eca700574f1be 100644 (file)
@@ -211,7 +211,8 @@ struct spi_nor_otp_organization {
  */
 struct spi_nor_otp_ops {
        int (*read)(struct spi_nor *nor, loff_t addr, size_t len, u8 *buf);
-       int (*write)(struct spi_nor *nor, loff_t addr, size_t len, u8 *buf);
+       int (*write)(struct spi_nor *nor, loff_t addr, size_t len,
+                    const u8 *buf);
        int (*lock)(struct spi_nor *nor, unsigned int region);
        int (*is_locked)(struct spi_nor *nor, unsigned int region);
 };
@@ -504,7 +505,8 @@ ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len,
                           const u8 *buf);
 
 int spi_nor_otp_read_secr(struct spi_nor *nor, loff_t addr, size_t len, u8 *buf);
-int spi_nor_otp_write_secr(struct spi_nor *nor, loff_t addr, size_t len, u8 *buf);
+int spi_nor_otp_write_secr(struct spi_nor *nor, loff_t addr, size_t len,
+                          const u8 *buf);
 int spi_nor_otp_lock_sr2(struct spi_nor *nor, unsigned int region);
 int spi_nor_otp_is_locked_sr2(struct spi_nor *nor, unsigned int region);
 
index 5021d40dffbff1cd905ecce2846b0792649c9d66..fcf38d26034500e6d3eb7b401d90ce1b74f3fa63 100644 (file)
@@ -70,7 +70,8 @@ int spi_nor_otp_read_secr(struct spi_nor *nor, loff_t addr, size_t len, u8 *buf)
  *
  * Return: number of bytes written successfully, -errno otherwise
  */
-int spi_nor_otp_write_secr(struct spi_nor *nor, loff_t addr, size_t len, u8 *buf)
+int spi_nor_otp_write_secr(struct spi_nor *nor, loff_t addr, size_t len,
+                          const u8 *buf)
 {
        enum spi_nor_protocol write_proto;
        struct spi_mem_dirmap_desc *wdesc;
@@ -241,7 +242,7 @@ out:
 
 static int spi_nor_mtd_otp_read_write(struct mtd_info *mtd, loff_t ofs,
                                      size_t total_len, size_t *retlen,
-                                     u8 *buf, bool is_write)
+                                     const u8 *buf, bool is_write)
 {
        struct spi_nor *nor = mtd_to_spi_nor(mtd);
        const struct spi_nor_otp_ops *ops = nor->params->otp.ops;
@@ -285,7 +286,7 @@ static int spi_nor_mtd_otp_read_write(struct mtd_info *mtd, loff_t ofs,
                if (is_write)
                        ret = ops->write(nor, rstart + rofs, len, buf);
                else
-                       ret = ops->read(nor, rstart + rofs, len, buf);
+                       ret = ops->read(nor, rstart + rofs, len, (u8 *)buf);
                if (ret == 0)
                        ret = -EIO;
                if (ret < 0)
@@ -310,7 +311,7 @@ static int spi_nor_mtd_otp_read(struct mtd_info *mtd, loff_t from, size_t len,
 }
 
 static int spi_nor_mtd_otp_write(struct mtd_info *mtd, loff_t to, size_t len,
-                                size_t *retlen, u8 *buf)
+                                size_t *retlen, const u8 *buf)
 {
        return spi_nor_mtd_otp_read_write(mtd, to, len, retlen, buf, true);
 }
index 4aac200ca8b5d7a47cf150033469a0865325600d..a89955f3cbc88187b8812cd46ba864789f3a582e 100644 (file)
@@ -334,7 +334,8 @@ struct mtd_info {
        int (*_read_user_prot_reg) (struct mtd_info *mtd, loff_t from,
                                    size_t len, size_t *retlen, u_char *buf);
        int (*_write_user_prot_reg) (struct mtd_info *mtd, loff_t to,
-                                    size_t len, size_t *retlen, u_char *buf);
+                                    size_t len, size_t *retlen,
+                                    const u_char *buf);
        int (*_lock_user_prot_reg) (struct mtd_info *mtd, loff_t from,
                                    size_t len);
        int (*_erase_user_prot_reg) (struct mtd_info *mtd, loff_t from,
@@ -518,7 +519,7 @@ int mtd_get_user_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
 int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
                           size_t *retlen, u_char *buf);
 int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
-                           size_t *retlen, u_char *buf);
+                           size_t *retlen, const u_char *buf);
 int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len);
 int mtd_erase_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len);