Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Michal Suchanek and committed by
Brian Norris
2dd087b1 0bad7b93

+28 -35
+2 -5
drivers/mtd/devices/m25p80.c
··· 74 74 } 75 75 76 76 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) 78 78 { 79 79 struct m25p *flash = nor->priv; 80 80 struct spi_device *spi = flash->spi; ··· 106 106 ret = m.actual_length - cmd_sz; 107 107 if (ret < 0) 108 108 return -EIO; 109 - *retlen += ret; 110 109 return ret; 111 110 } 112 111 ··· 126 127 * may be any size provided it is within the physical boundaries. 127 128 */ 128 129 static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len, 129 - size_t *retlen, u_char *buf) 130 + u_char *buf) 130 131 { 131 132 struct m25p *flash = nor->priv; 132 133 struct spi_device *spi = flash->spi; ··· 155 156 msg.data_nbits = m25p80_rx_nbits(nor); 156 157 157 158 ret = spi_flash_read(spi, &msg); 158 - *retlen = msg.retlen; 159 159 if (ret < 0) 160 160 return ret; 161 161 return msg.retlen; ··· 182 184 ret = m.actual_length - m25p_cmdsz(nor) - dummy; 183 185 if (ret < 0) 184 186 return -EIO; 185 - *retlen += ret; 186 187 return ret; 187 188 } 188 189
+6 -11
drivers/mtd/spi-nor/fsl-quadspi.c
··· 620 620 621 621 static ssize_t fsl_qspi_nor_write(struct fsl_qspi *q, struct spi_nor *nor, 622 622 u8 opcode, unsigned int to, u32 *txbuf, 623 - unsigned count, size_t *retlen) 623 + unsigned count) 624 624 { 625 625 int ret, i, j; 626 626 u32 tmp; ··· 647 647 /* Trigger it */ 648 648 ret = fsl_qspi_runcmd(q, opcode, to, count); 649 649 650 - if (ret == 0) { 651 - if (retlen) 652 - *retlen += count; 650 + if (ret == 0) 653 651 return count; 654 - } 655 652 656 653 return ret; 657 654 } ··· 859 862 860 863 } else if (len > 0) { 861 864 ret = fsl_qspi_nor_write(q, nor, opcode, 0, 862 - (u32 *)buf, len, NULL); 865 + (u32 *)buf, len); 863 866 if (ret > 0) 864 867 return 0; 865 868 } else { ··· 871 874 } 872 875 873 876 static ssize_t fsl_qspi_write(struct spi_nor *nor, loff_t to, 874 - size_t len, size_t *retlen, const u_char *buf) 877 + size_t len, const u_char *buf) 875 878 { 876 879 struct fsl_qspi *q = nor->priv; 877 - 878 880 ssize_t ret = fsl_qspi_nor_write(q, nor, nor->program_opcode, to, 879 - (u32 *)buf, len, retlen); 881 + (u32 *)buf, len); 880 882 881 883 /* invalid the data in the AHB buffer. */ 882 884 fsl_qspi_invalid(q); ··· 883 887 } 884 888 885 889 static ssize_t fsl_qspi_read(struct spi_nor *nor, loff_t from, 886 - size_t len, size_t *retlen, u_char *buf) 890 + size_t len, u_char *buf) 887 891 { 888 892 struct fsl_qspi *q = nor->priv; 889 893 u8 cmd = nor->read_opcode; ··· 925 929 memcpy(buf, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs, 926 930 len); 927 931 928 - *retlen += len; 929 932 return len; 930 933 } 931 934
+3 -5
drivers/mtd/spi-nor/mtk-quadspi.c
··· 244 244 } 245 245 246 246 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) 248 248 { 249 249 int i, ret; 250 250 int addr = (int)from; ··· 255 255 mt8173_nor_set_read_mode(mt8173_nor); 256 256 mt8173_nor_set_addr(mt8173_nor, addr); 257 257 258 - for (i = 0; i < length; i++, (*retlen)++) { 258 + for (i = 0; i < length; i++) { 259 259 ret = mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_PIO_READ_CMD); 260 260 if (ret < 0) 261 261 return ret; ··· 298 298 } 299 299 300 300 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) 302 302 { 303 303 int ret; 304 304 struct mt8173_nor *mt8173_nor = nor->priv; ··· 318 318 } 319 319 to += SFLASH_WRBUF_SIZE; 320 320 buf += SFLASH_WRBUF_SIZE; 321 - (*retlen) += SFLASH_WRBUF_SIZE; 322 321 } 323 322 ret = mt8173_nor_write_buffer_disable(mt8173_nor); 324 323 if (ret < 0) { ··· 332 333 dev_err(mt8173_nor->dev, "write single byte failed!\n"); 333 334 return ret; 334 335 } 335 - (*retlen) += len; 336 336 } 337 337 338 338 return len;
+2 -4
drivers/mtd/spi-nor/nxp-spifi.c
··· 173 173 } 174 174 175 175 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) 177 177 { 178 178 struct nxp_spifi *spifi = nor->priv; 179 179 int ret; ··· 183 183 return ret; 184 184 185 185 memcpy_fromio(buf, spifi->flash_base + from, len); 186 - *retlen += len; 187 186 188 187 return len; 189 188 } 190 189 191 190 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) 193 192 { 194 193 struct nxp_spifi *spifi = nor->priv; 195 194 u32 cmd; ··· 200 201 return ret; 201 202 202 203 writel(to, spifi->io_base + SPIFI_ADDR); 203 - *retlen += len; 204 204 205 205 cmd = SPIFI_CMD_DOUT | 206 206 SPIFI_CMD_DATALEN(len) |
+13 -8
drivers/mtd/spi-nor/spi-nor.c
··· 1031 1031 if (ret) 1032 1032 return ret; 1033 1033 1034 - ret = nor->read(nor, from, len, retlen, buf); 1034 + ret = nor->read(nor, from, len, buf); 1035 1035 1036 1036 spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_READ); 1037 1037 if (ret < 0) 1038 1038 return ret; 1039 1039 1040 + *retlen += ret; 1040 1041 return 0; 1041 1042 } 1042 1043 ··· 1064 1063 nor->program_opcode = SPINOR_OP_BP; 1065 1064 1066 1065 /* write one byte. */ 1067 - ret = nor->write(nor, to, 1, retlen, buf); 1066 + ret = nor->write(nor, to, 1, buf); 1068 1067 if (ret < 0) 1069 1068 goto sst_write_err; 1070 1069 WARN(ret != 1, "While writing 1 byte written %i bytes\n", ··· 1080 1079 nor->program_opcode = SPINOR_OP_AAI_WP; 1081 1080 1082 1081 /* write two bytes. */ 1083 - ret = nor->write(nor, to, 2, retlen, buf + actual); 1082 + ret = nor->write(nor, to, 2, buf + actual); 1084 1083 if (ret < 0) 1085 1084 goto sst_write_err; 1086 1085 WARN(ret != 2, "While writing 2 bytes written %i bytes\n", ··· 1103 1102 write_enable(nor); 1104 1103 1105 1104 nor->program_opcode = SPINOR_OP_BP; 1106 - ret = nor->write(nor, to, 1, retlen, buf + actual); 1105 + ret = nor->write(nor, to, 1, buf + actual); 1107 1106 if (ret < 0) 1108 1107 goto sst_write_err; 1109 1108 WARN(ret != 1, "While writing 1 byte written %i bytes\n", ··· 1112 1111 if (ret) 1113 1112 goto sst_write_err; 1114 1113 write_disable(nor); 1114 + actual += 1; 1115 1115 } 1116 1116 sst_write_err: 1117 + *retlen += actual; 1117 1118 spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_WRITE); 1118 1119 return ret; 1119 1120 } ··· 1144 1141 1145 1142 /* do all the bytes fit onto one page? */ 1146 1143 if (page_offset + len <= nor->page_size) { 1147 - ret = nor->write(nor, to, len, retlen, buf); 1144 + ret = nor->write(nor, to, len, buf); 1148 1145 if (ret < 0) 1149 1146 goto write_err; 1147 + *retlen += ret; 1150 1148 } else { 1151 1149 /* the size of data remaining on the first page */ 1152 1150 page_size = nor->page_size - page_offset; 1153 - ret = nor->write(nor, to, page_size, retlen, buf); 1151 + ret = nor->write(nor, to, page_size, buf); 1154 1152 if (ret < 0) 1155 1153 goto write_err; 1154 + *retlen += ret; 1156 1155 1157 1156 /* write everything in nor->page_size chunks */ 1158 1157 for (i = ret; i < len; ) { ··· 1168 1163 1169 1164 write_enable(nor); 1170 1165 1171 - ret = nor->write(nor, to + i, page_size, retlen, 1172 - buf + i); 1166 + ret = nor->write(nor, to + i, page_size, buf + i); 1173 1167 if (ret < 0) 1174 1168 goto write_err; 1169 + *retlen += ret; 1175 1170 i += ret; 1176 1171 } 1177 1172 }
+2 -2
include/linux/mtd/spi-nor.h
··· 174 174 int (*write_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, int len); 175 175 176 176 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); 178 178 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); 180 180 int (*erase)(struct spi_nor *nor, loff_t offs); 181 181 182 182 int (*flash_lock)(struct spi_nor *nor, loff_t ofs, uint64_t len);