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

mtd: devices: fix mchp23k256 read and write

Due to the use of sizeof(), command size set for the spi transfer
was wrong. Driver was sending and receiving always 1 byte less
and especially on write, it was hanging.

echo -n -e "\\x1\\x2\\x3\\x4" > /dev/mtd1

And read part too now works as expected.

hexdump -C -n16 /dev/mtd1
00000000 01 02 03 04 ab f3 ad c2 ab e3 f4 36 dd 38 04 15
00000010

Fixes: 4379075a870b ("mtd: mchp23k256: Add support for mchp23lcv1024")
Signed-off-by: Angelo Dureghello <angelo.dureghello@timesys.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

authored by

Angelo Dureghello and committed by
Miquel Raynal
14f89e08 c2d73ba8

+12 -8
+12 -8
drivers/mtd/devices/mchp23k256.c
··· 64 64 struct spi_transfer transfer[2] = {}; 65 65 struct spi_message message; 66 66 unsigned char command[MAX_CMD_SIZE]; 67 - int ret; 67 + int ret, cmd_len; 68 68 69 69 spi_message_init(&message); 70 + 71 + cmd_len = mchp23k256_cmdsz(flash); 70 72 71 73 command[0] = MCHP23K256_CMD_WRITE; 72 74 mchp23k256_addr2cmd(flash, to, command); 73 75 74 76 transfer[0].tx_buf = command; 75 - transfer[0].len = mchp23k256_cmdsz(flash); 77 + transfer[0].len = cmd_len; 76 78 spi_message_add_tail(&transfer[0], &message); 77 79 78 80 transfer[1].tx_buf = buf; ··· 90 88 if (ret) 91 89 return ret; 92 90 93 - if (retlen && message.actual_length > sizeof(command)) 94 - *retlen += message.actual_length - sizeof(command); 91 + if (retlen && message.actual_length > cmd_len) 92 + *retlen += message.actual_length - cmd_len; 95 93 96 94 return 0; 97 95 } ··· 103 101 struct spi_transfer transfer[2] = {}; 104 102 struct spi_message message; 105 103 unsigned char command[MAX_CMD_SIZE]; 106 - int ret; 104 + int ret, cmd_len; 107 105 108 106 spi_message_init(&message); 107 + 108 + cmd_len = mchp23k256_cmdsz(flash); 109 109 110 110 memset(&transfer, 0, sizeof(transfer)); 111 111 command[0] = MCHP23K256_CMD_READ; 112 112 mchp23k256_addr2cmd(flash, from, command); 113 113 114 114 transfer[0].tx_buf = command; 115 - transfer[0].len = mchp23k256_cmdsz(flash); 115 + transfer[0].len = cmd_len; 116 116 spi_message_add_tail(&transfer[0], &message); 117 117 118 118 transfer[1].rx_buf = buf; ··· 130 126 if (ret) 131 127 return ret; 132 128 133 - if (retlen && message.actual_length > sizeof(command)) 134 - *retlen += message.actual_length - sizeof(command); 129 + if (retlen && message.actual_length > cmd_len) 130 + *retlen += message.actual_length - cmd_len; 135 131 136 132 return 0; 137 133 }