Skip to content

Commit 2dd087b

Browse files
hramrachcomputersforpeace
authored andcommitted
mtd: spi-nor: stop passing around retlen
Do not pass retlen to hardware driver read/write functions. Update it in spi-nor generic driver instead. Signed-off-by: Michal Suchanek <hramrach@gmail.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com> Tested-by Cyrille Pitchen <cyrille.pitchen@atmel.com> Acked-by: Michal Suchanek <hramrach@gmail.com> Tested-by: Michal Suchanek <hramrach@gmail.com>
1 parent 0bad7b9 commit 2dd087b

6 files changed

Lines changed: 28 additions & 35 deletions

File tree

‎drivers/mtd/devices/m25p80.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static int m25p80_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
7474
}
7575

7676
static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
77-
size_t *retlen, const u_char *buf)
77+
const u_char *buf)
7878
{
7979
struct m25p *flash = nor->priv;
8080
struct spi_device *spi = flash->spi;
@@ -106,7 +106,6 @@ static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
106106
ret = m.actual_length - cmd_sz;
107107
if (ret < 0)
108108
return -EIO;
109-
*retlen += ret;
110109
return ret;
111110
}
112111

@@ -127,7 +126,7 @@ static inline unsigned int m25p80_rx_nbits(struct spi_nor *nor)
127126
* may be any size provided it is within the physical boundaries.
128127
*/
129128
static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
130-
size_t *retlen, u_char *buf)
129+
u_char *buf)
131130
{
132131
struct m25p *flash = nor->priv;
133132
struct spi_device *spi = flash->spi;
@@ -156,7 +155,6 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
156155
msg.data_nbits = m25p80_rx_nbits(nor);
157156

158157
ret = spi_flash_read(spi, &msg);
159-
*retlen = msg.retlen;
160158
if (ret < 0)
161159
return ret;
162160
return msg.retlen;
@@ -184,7 +182,6 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
184182
ret = m.actual_length - m25p_cmdsz(nor) - dummy;
185183
if (ret < 0)
186184
return -EIO;
187-
*retlen += ret;
188185
return ret;
189186
}
190187

‎drivers/mtd/spi-nor/fsl-quadspi.c‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ static inline void fsl_qspi_invalid(struct fsl_qspi *q)
620620

621621
static ssize_t fsl_qspi_nor_write(struct fsl_qspi *q, struct spi_nor *nor,
622622
u8 opcode, unsigned int to, u32 *txbuf,
623-
unsigned count, size_t *retlen)
623+
unsigned count)
624624
{
625625
int ret, i, j;
626626
u32 tmp;
@@ -647,11 +647,8 @@ static ssize_t fsl_qspi_nor_write(struct fsl_qspi *q, struct spi_nor *nor,
647647
/* Trigger it */
648648
ret = fsl_qspi_runcmd(q, opcode, to, count);
649649

650-
if (ret == 0) {
651-
if (retlen)
652-
*retlen += count;
650+
if (ret == 0)
653651
return count;
654-
}
655652

656653
return ret;
657654
}
@@ -862,7 +859,7 @@ static int fsl_qspi_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
862859

863860
} else if (len > 0) {
864861
ret = fsl_qspi_nor_write(q, nor, opcode, 0,
865-
(u32 *)buf, len, NULL);
862+
(u32 *)buf, len);
866863
if (ret > 0)
867864
return 0;
868865
} else {
@@ -874,20 +871,19 @@ static int fsl_qspi_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
874871
}
875872

876873
static ssize_t fsl_qspi_write(struct spi_nor *nor, loff_t to,
877-
size_t len, size_t *retlen, const u_char *buf)
874+
size_t len, const u_char *buf)
878875
{
879876
struct fsl_qspi *q = nor->priv;
880-
881877
ssize_t ret = fsl_qspi_nor_write(q, nor, nor->program_opcode, to,
882-
(u32 *)buf, len, retlen);
878+
(u32 *)buf, len);
883879

884880
/* invalid the data in the AHB buffer. */
885881
fsl_qspi_invalid(q);
886882
return ret;
887883
}
888884

889885
static ssize_t fsl_qspi_read(struct spi_nor *nor, loff_t from,
890-
size_t len, size_t *retlen, u_char *buf)
886+
size_t len, u_char *buf)
891887
{
892888
struct fsl_qspi *q = nor->priv;
893889
u8 cmd = nor->read_opcode;
@@ -929,7 +925,6 @@ static ssize_t fsl_qspi_read(struct spi_nor *nor, loff_t from,
929925
memcpy(buf, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
930926
len);
931927

932-
*retlen += len;
933928
return len;
934929
}
935930

‎drivers/mtd/spi-nor/mtk-quadspi.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ static void mt8173_nor_set_addr(struct mt8173_nor *mt8173_nor, u32 addr)
244244
}
245245

246246
static ssize_t mt8173_nor_read(struct spi_nor *nor, loff_t from, size_t length,
247-
size_t *retlen, u_char *buffer)
247+
u_char *buffer)
248248
{
249249
int i, ret;
250250
int addr = (int)from;
@@ -255,7 +255,7 @@ static ssize_t mt8173_nor_read(struct spi_nor *nor, loff_t from, size_t length,
255255
mt8173_nor_set_read_mode(mt8173_nor);
256256
mt8173_nor_set_addr(mt8173_nor, addr);
257257

258-
for (i = 0; i < length; i++, (*retlen)++) {
258+
for (i = 0; i < length; i++) {
259259
ret = mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_PIO_READ_CMD);
260260
if (ret < 0)
261261
return ret;
@@ -298,7 +298,7 @@ static int mt8173_nor_write_buffer(struct mt8173_nor *mt8173_nor, int addr,
298298
}
299299

300300
static ssize_t mt8173_nor_write(struct spi_nor *nor, loff_t to, size_t len,
301-
size_t *retlen, const u_char *buf)
301+
const u_char *buf)
302302
{
303303
int ret;
304304
struct mt8173_nor *mt8173_nor = nor->priv;
@@ -318,7 +318,6 @@ static ssize_t mt8173_nor_write(struct spi_nor *nor, loff_t to, size_t len,
318318
}
319319
to += SFLASH_WRBUF_SIZE;
320320
buf += SFLASH_WRBUF_SIZE;
321-
(*retlen) += SFLASH_WRBUF_SIZE;
322321
}
323322
ret = mt8173_nor_write_buffer_disable(mt8173_nor);
324323
if (ret < 0) {
@@ -333,7 +332,6 @@ static ssize_t mt8173_nor_write(struct spi_nor *nor, loff_t to, size_t len,
333332
dev_err(mt8173_nor->dev, "write single byte failed!\n");
334333
return ret;
335334
}
336-
(*retlen) += len;
337335
}
338336

339337
return len;

‎drivers/mtd/spi-nor/nxp-spifi.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static int nxp_spifi_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
173173
}
174174

175175
static ssize_t nxp_spifi_read(struct spi_nor *nor, loff_t from, size_t len,
176-
size_t *retlen, u_char *buf)
176+
u_char *buf)
177177
{
178178
struct nxp_spifi *spifi = nor->priv;
179179
int ret;
@@ -183,13 +183,12 @@ static ssize_t nxp_spifi_read(struct spi_nor *nor, loff_t from, size_t len,
183183
return ret;
184184

185185
memcpy_fromio(buf, spifi->flash_base + from, len);
186-
*retlen += len;
187186

188187
return len;
189188
}
190189

191190
static ssize_t nxp_spifi_write(struct spi_nor *nor, loff_t to, size_t len,
192-
size_t *retlen, const u_char *buf)
191+
const u_char *buf)
193192
{
194193
struct nxp_spifi *spifi = nor->priv;
195194
u32 cmd;
@@ -201,7 +200,6 @@ static ssize_t nxp_spifi_write(struct spi_nor *nor, loff_t to, size_t len,
201200
return ret;
202201

203202
writel(to, spifi->io_base + SPIFI_ADDR);
204-
*retlen += len;
205203

206204
cmd = SPIFI_CMD_DOUT |
207205
SPIFI_CMD_DATALEN(len) |

‎drivers/mtd/spi-nor/spi-nor.c‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,12 +1031,13 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
10311031
if (ret)
10321032
return ret;
10331033

1034-
ret = nor->read(nor, from, len, retlen, buf);
1034+
ret = nor->read(nor, from, len, buf);
10351035

10361036
spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_READ);
10371037
if (ret < 0)
10381038
return ret;
10391039

1040+
*retlen += ret;
10401041
return 0;
10411042
}
10421043

@@ -1063,7 +1064,7 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
10631064
nor->program_opcode = SPINOR_OP_BP;
10641065

10651066
/* write one byte. */
1066-
ret = nor->write(nor, to, 1, retlen, buf);
1067+
ret = nor->write(nor, to, 1, buf);
10671068
if (ret < 0)
10681069
goto sst_write_err;
10691070
WARN(ret != 1, "While writing 1 byte written %i bytes\n",
@@ -1079,7 +1080,7 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
10791080
nor->program_opcode = SPINOR_OP_AAI_WP;
10801081

10811082
/* write two bytes. */
1082-
ret = nor->write(nor, to, 2, retlen, buf + actual);
1083+
ret = nor->write(nor, to, 2, buf + actual);
10831084
if (ret < 0)
10841085
goto sst_write_err;
10851086
WARN(ret != 2, "While writing 2 bytes written %i bytes\n",
@@ -1102,7 +1103,7 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
11021103
write_enable(nor);
11031104

11041105
nor->program_opcode = SPINOR_OP_BP;
1105-
ret = nor->write(nor, to, 1, retlen, buf + actual);
1106+
ret = nor->write(nor, to, 1, buf + actual);
11061107
if (ret < 0)
11071108
goto sst_write_err;
11081109
WARN(ret != 1, "While writing 1 byte written %i bytes\n",
@@ -1111,8 +1112,10 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
11111112
if (ret)
11121113
goto sst_write_err;
11131114
write_disable(nor);
1115+
actual += 1;
11141116
}
11151117
sst_write_err:
1118+
*retlen += actual;
11161119
spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_WRITE);
11171120
return ret;
11181121
}
@@ -1141,15 +1144,17 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
11411144

11421145
/* do all the bytes fit onto one page? */
11431146
if (page_offset + len <= nor->page_size) {
1144-
ret = nor->write(nor, to, len, retlen, buf);
1147+
ret = nor->write(nor, to, len, buf);
11451148
if (ret < 0)
11461149
goto write_err;
1150+
*retlen += ret;
11471151
} else {
11481152
/* the size of data remaining on the first page */
11491153
page_size = nor->page_size - page_offset;
1150-
ret = nor->write(nor, to, page_size, retlen, buf);
1154+
ret = nor->write(nor, to, page_size, buf);
11511155
if (ret < 0)
11521156
goto write_err;
1157+
*retlen += ret;
11531158

11541159
/* write everything in nor->page_size chunks */
11551160
for (i = ret; i < len; ) {
@@ -1163,10 +1168,10 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
11631168

11641169
write_enable(nor);
11651170

1166-
ret = nor->write(nor, to + i, page_size, retlen,
1167-
buf + i);
1171+
ret = nor->write(nor, to + i, page_size, buf + i);
11681172
if (ret < 0)
11691173
goto write_err;
1174+
*retlen += ret;
11701175
i += ret;
11711176
}
11721177
}

‎include/linux/mtd/spi-nor.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ struct spi_nor {
174174
int (*write_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, int len);
175175

176176
ssize_t (*read)(struct spi_nor *nor, loff_t from,
177-
size_t len, size_t *retlen, u_char *read_buf);
177+
size_t len, u_char *read_buf);
178178
ssize_t (*write)(struct spi_nor *nor, loff_t to,
179-
size_t len, size_t *retlen, const u_char *write_buf);
179+
size_t len, const u_char *write_buf);
180180
int (*erase)(struct spi_nor *nor, loff_t offs);
181181

182182
int (*flash_lock)(struct spi_nor *nor, loff_t ofs, uint64_t len);

0 commit comments

Comments
 (0)