Skip to content

Commit 1df1fc8

Browse files
ambarusmiquelraynal
authored andcommitted
mtd: core: Constify buf in mtd_write_user_prot_reg()
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
1 parent ef4ed78 commit 1df1fc8

8 files changed

Lines changed: 24 additions & 18 deletions

File tree

drivers/mtd/chips/cfi_cmdset_0001.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ static int cfi_intelext_is_locked(struct mtd_info *mtd, loff_t ofs,
7272
#ifdef CONFIG_MTD_OTP
7373
static int cfi_intelext_read_fact_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
7474
static int cfi_intelext_read_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
75-
static int cfi_intelext_write_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
75+
static int cfi_intelext_write_user_prot_reg(struct mtd_info *, loff_t, size_t,
76+
size_t *, const u_char *);
7677
static int cfi_intelext_lock_user_prot_reg (struct mtd_info *, loff_t, size_t);
7778
static int cfi_intelext_get_fact_prot_info(struct mtd_info *, size_t,
7879
size_t *, struct otp_info *);
@@ -2447,10 +2448,10 @@ static int cfi_intelext_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
24472448

24482449
static int cfi_intelext_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
24492450
size_t len, size_t *retlen,
2450-
u_char *buf)
2451+
const u_char *buf)
24512452
{
24522453
return cfi_intelext_otp_walk(mtd, from, len, retlen,
2453-
buf, do_otp_write, 1);
2454+
(u_char *)buf, do_otp_write, 1);
24542455
}
24552456

24562457
static int cfi_intelext_lock_user_prot_reg(struct mtd_info *mtd,

drivers/mtd/chips/cfi_cmdset_0002.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static int cfi_amdstd_read_fact_prot_reg(struct mtd_info *, loff_t, size_t,
8080
static int cfi_amdstd_read_user_prot_reg(struct mtd_info *, loff_t, size_t,
8181
size_t *, u_char *);
8282
static int cfi_amdstd_write_user_prot_reg(struct mtd_info *, loff_t, size_t,
83-
size_t *, u_char *);
83+
size_t *, const u_char *);
8484
static int cfi_amdstd_lock_user_prot_reg(struct mtd_info *, loff_t, size_t);
8585

8686
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,
16351635

16361636
static int cfi_amdstd_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
16371637
size_t len, size_t *retlen,
1638-
u_char *buf)
1638+
const u_char *buf)
16391639
{
1640-
return cfi_amdstd_otp_walk(mtd, from, len, retlen, buf,
1640+
return cfi_amdstd_otp_walk(mtd, from, len, retlen, (u_char *)buf,
16411641
do_otp_write, 1);
16421642
}
16431643

drivers/mtd/devices/mtd_dataflash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ static int dataflash_read_user_otp(struct mtd_info *mtd,
527527
}
528528

529529
static int dataflash_write_user_otp(struct mtd_info *mtd,
530-
loff_t from, size_t len, size_t *retlen, u_char *buf)
530+
loff_t from, size_t len, size_t *retlen, const u_char *buf)
531531
{
532532
struct spi_message m;
533533
const size_t l = 4 + 64;

drivers/mtd/mtdcore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
18891889
EXPORT_SYMBOL_GPL(mtd_read_user_prot_reg);
18901890

18911891
int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
1892-
size_t *retlen, u_char *buf)
1892+
size_t *retlen, const u_char *buf)
18931893
{
18941894
struct mtd_info *master = mtd_get_master(mtd);
18951895
int ret;

drivers/mtd/nand/onenand/onenand_base.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,9 +3167,10 @@ static int onenand_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
31673167
* Write user OTP area.
31683168
*/
31693169
static int onenand_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
3170-
size_t len, size_t *retlen, u_char *buf)
3170+
size_t len, size_t *retlen, const u_char *buf)
31713171
{
3172-
return onenand_otp_walk(mtd, from, len, retlen, buf, do_otp_write, MTD_OTP_USER);
3172+
return onenand_otp_walk(mtd, from, len, retlen, (u_char *)buf,
3173+
do_otp_write, MTD_OTP_USER);
31733174
}
31743175

31753176
/**

drivers/mtd/spi-nor/core.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ struct spi_nor_otp_organization {
211211
*/
212212
struct spi_nor_otp_ops {
213213
int (*read)(struct spi_nor *nor, loff_t addr, size_t len, u8 *buf);
214-
int (*write)(struct spi_nor *nor, loff_t addr, size_t len, u8 *buf);
214+
int (*write)(struct spi_nor *nor, loff_t addr, size_t len,
215+
const u8 *buf);
215216
int (*lock)(struct spi_nor *nor, unsigned int region);
216217
int (*is_locked)(struct spi_nor *nor, unsigned int region);
217218
};
@@ -504,7 +505,8 @@ ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len,
504505
const u8 *buf);
505506

506507
int spi_nor_otp_read_secr(struct spi_nor *nor, loff_t addr, size_t len, u8 *buf);
507-
int spi_nor_otp_write_secr(struct spi_nor *nor, loff_t addr, size_t len, u8 *buf);
508+
int spi_nor_otp_write_secr(struct spi_nor *nor, loff_t addr, size_t len,
509+
const u8 *buf);
508510
int spi_nor_otp_lock_sr2(struct spi_nor *nor, unsigned int region);
509511
int spi_nor_otp_is_locked_sr2(struct spi_nor *nor, unsigned int region);
510512

drivers/mtd/spi-nor/otp.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ int spi_nor_otp_read_secr(struct spi_nor *nor, loff_t addr, size_t len, u8 *buf)
7070
*
7171
* Return: number of bytes written successfully, -errno otherwise
7272
*/
73-
int spi_nor_otp_write_secr(struct spi_nor *nor, loff_t addr, size_t len, u8 *buf)
73+
int spi_nor_otp_write_secr(struct spi_nor *nor, loff_t addr, size_t len,
74+
const u8 *buf)
7475
{
7576
enum spi_nor_protocol write_proto;
7677
struct spi_mem_dirmap_desc *wdesc;
@@ -241,7 +242,7 @@ static int spi_nor_mtd_otp_info(struct mtd_info *mtd, size_t len,
241242

242243
static int spi_nor_mtd_otp_read_write(struct mtd_info *mtd, loff_t ofs,
243244
size_t total_len, size_t *retlen,
244-
u8 *buf, bool is_write)
245+
const u8 *buf, bool is_write)
245246
{
246247
struct spi_nor *nor = mtd_to_spi_nor(mtd);
247248
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,
285286
if (is_write)
286287
ret = ops->write(nor, rstart + rofs, len, buf);
287288
else
288-
ret = ops->read(nor, rstart + rofs, len, buf);
289+
ret = ops->read(nor, rstart + rofs, len, (u8 *)buf);
289290
if (ret == 0)
290291
ret = -EIO;
291292
if (ret < 0)
@@ -310,7 +311,7 @@ static int spi_nor_mtd_otp_read(struct mtd_info *mtd, loff_t from, size_t len,
310311
}
311312

312313
static int spi_nor_mtd_otp_write(struct mtd_info *mtd, loff_t to, size_t len,
313-
size_t *retlen, u8 *buf)
314+
size_t *retlen, const u8 *buf)
314315
{
315316
return spi_nor_mtd_otp_read_write(mtd, to, len, retlen, buf, true);
316317
}

include/linux/mtd/mtd.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ struct mtd_info {
334334
int (*_read_user_prot_reg) (struct mtd_info *mtd, loff_t from,
335335
size_t len, size_t *retlen, u_char *buf);
336336
int (*_write_user_prot_reg) (struct mtd_info *mtd, loff_t to,
337-
size_t len, size_t *retlen, u_char *buf);
337+
size_t len, size_t *retlen,
338+
const u_char *buf);
338339
int (*_lock_user_prot_reg) (struct mtd_info *mtd, loff_t from,
339340
size_t len);
340341
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,
518519
int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
519520
size_t *retlen, u_char *buf);
520521
int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
521-
size_t *retlen, u_char *buf);
522+
size_t *retlen, const u_char *buf);
522523
int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len);
523524
int mtd_erase_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len);
524525

0 commit comments

Comments
 (0)