Skip to content

Commit c8273a2

Browse files
committed
Merge tag 'mtd/fixes-for-6.5-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux
Pull mtd fixes from Miquel Raynal: "Raw NAND fixes: - fsl_upm: Fix an off-by one test in fun_exec_op() - Rockchip: - Align hwecc vs. raw page helper layouts - Fix oobfree offset and description - Meson: Fix OOB available bytes for ECC - Omap ELM: Fix incorrect type in assignment SPI-NOR fix: - Avoid holes in struct spi_mem_op Hyperbus fix: - Add Tudor as reviewer in MAINTAINERS SPI-NAND fixes: - Winbond and Toshiba: Fix ecc_get_status" * tag 'mtd/fixes-for-6.5-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux: mtd: rawnand: fsl_upm: Fix an off-by one test in fun_exec_op() mtd: spi-nor: avoid holes in struct spi_mem_op MAINTAINERS: Add myself as reviewer for HYPERBUS mtd: rawnand: rockchip: Align hwecc vs. raw page helper layouts mtd: rawnand: rockchip: fix oobfree offset and description mtd: rawnand: meson: fix OOB available bytes for ECC mtd: rawnand: omap_elm: Fix incorrect type in assignment mtd: spinand: winbond: Fix ecc_get_status mtd: spinand: toshiba: Fix ecc_get_status
2 parents 4142fc6 + c6abce6 commit c8273a2

File tree

9 files changed

+50
-41
lines changed

9 files changed

+50
-41
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9660,6 +9660,7 @@ F: tools/hv/
96609660

96619661
HYPERBUS SUPPORT
96629662
M: Vignesh Raghavendra <vigneshr@ti.com>
9663+
R: Tudor Ambarus <tudor.ambarus@linaro.org>
96639664
L: linux-mtd@lists.infradead.org
96649665
S: Supported
96659666
Q: http://patchwork.ozlabs.org/project/linux-mtd/list/

drivers/mtd/nand/raw/fsl_upm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static int fun_exec_op(struct nand_chip *chip, const struct nand_operation *op,
135135
unsigned int i;
136136
int ret;
137137

138-
if (op->cs > NAND_MAX_CHIPS)
138+
if (op->cs >= NAND_MAX_CHIPS)
139139
return -EINVAL;
140140

141141
if (check_only)

drivers/mtd/nand/raw/meson_nand.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,6 @@ static int meson_nand_attach_chip(struct nand_chip *nand)
12781278
struct meson_nfc *nfc = nand_get_controller_data(nand);
12791279
struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand);
12801280
struct mtd_info *mtd = nand_to_mtd(nand);
1281-
int nsectors = mtd->writesize / 1024;
12821281
int raw_writesize;
12831282
int ret;
12841283

@@ -1304,7 +1303,7 @@ static int meson_nand_attach_chip(struct nand_chip *nand)
13041303
nand->options |= NAND_NO_SUBPAGE_WRITE;
13051304

13061305
ret = nand_ecc_choose_conf(nand, nfc->data->ecc_caps,
1307-
mtd->oobsize - 2 * nsectors);
1306+
mtd->oobsize - 2);
13081307
if (ret) {
13091308
dev_err(nfc->dev, "failed to ECC init\n");
13101309
return -EINVAL;

drivers/mtd/nand/raw/omap_elm.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,17 @@ static void elm_load_syndrome(struct elm_info *info,
177177
switch (info->bch_type) {
178178
case BCH8_ECC:
179179
/* syndrome fragment 0 = ecc[9-12B] */
180-
val = cpu_to_be32(*(u32 *) &ecc[9]);
180+
val = (__force u32)cpu_to_be32(*(u32 *)&ecc[9]);
181181
elm_write_reg(info, offset, val);
182182

183183
/* syndrome fragment 1 = ecc[5-8B] */
184184
offset += 4;
185-
val = cpu_to_be32(*(u32 *) &ecc[5]);
185+
val = (__force u32)cpu_to_be32(*(u32 *)&ecc[5]);
186186
elm_write_reg(info, offset, val);
187187

188188
/* syndrome fragment 2 = ecc[1-4B] */
189189
offset += 4;
190-
val = cpu_to_be32(*(u32 *) &ecc[1]);
190+
val = (__force u32)cpu_to_be32(*(u32 *)&ecc[1]);
191191
elm_write_reg(info, offset, val);
192192

193193
/* syndrome fragment 3 = ecc[0B] */
@@ -197,35 +197,35 @@ static void elm_load_syndrome(struct elm_info *info,
197197
break;
198198
case BCH4_ECC:
199199
/* syndrome fragment 0 = ecc[20-52b] bits */
200-
val = (cpu_to_be32(*(u32 *) &ecc[3]) >> 4) |
200+
val = ((__force u32)cpu_to_be32(*(u32 *)&ecc[3]) >> 4) |
201201
((ecc[2] & 0xf) << 28);
202202
elm_write_reg(info, offset, val);
203203

204204
/* syndrome fragment 1 = ecc[0-20b] bits */
205205
offset += 4;
206-
val = cpu_to_be32(*(u32 *) &ecc[0]) >> 12;
206+
val = (__force u32)cpu_to_be32(*(u32 *)&ecc[0]) >> 12;
207207
elm_write_reg(info, offset, val);
208208
break;
209209
case BCH16_ECC:
210-
val = cpu_to_be32(*(u32 *) &ecc[22]);
210+
val = (__force u32)cpu_to_be32(*(u32 *)&ecc[22]);
211211
elm_write_reg(info, offset, val);
212212
offset += 4;
213-
val = cpu_to_be32(*(u32 *) &ecc[18]);
213+
val = (__force u32)cpu_to_be32(*(u32 *)&ecc[18]);
214214
elm_write_reg(info, offset, val);
215215
offset += 4;
216-
val = cpu_to_be32(*(u32 *) &ecc[14]);
216+
val = (__force u32)cpu_to_be32(*(u32 *)&ecc[14]);
217217
elm_write_reg(info, offset, val);
218218
offset += 4;
219-
val = cpu_to_be32(*(u32 *) &ecc[10]);
219+
val = (__force u32)cpu_to_be32(*(u32 *)&ecc[10]);
220220
elm_write_reg(info, offset, val);
221221
offset += 4;
222-
val = cpu_to_be32(*(u32 *) &ecc[6]);
222+
val = (__force u32)cpu_to_be32(*(u32 *)&ecc[6]);
223223
elm_write_reg(info, offset, val);
224224
offset += 4;
225-
val = cpu_to_be32(*(u32 *) &ecc[2]);
225+
val = (__force u32)cpu_to_be32(*(u32 *)&ecc[2]);
226226
elm_write_reg(info, offset, val);
227227
offset += 4;
228-
val = cpu_to_be32(*(u32 *) &ecc[0]) >> 16;
228+
val = (__force u32)cpu_to_be32(*(u32 *)&ecc[0]) >> 16;
229229
elm_write_reg(info, offset, val);
230230
break;
231231
default:

drivers/mtd/nand/raw/rockchip-nand-controller.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,10 @@ static int rk_nfc_write_page_raw(struct nand_chip *chip, const u8 *buf,
562562
* BBM OOB1 OOB2 OOB3 |......| PA0 PA1 PA2 PA3
563563
*
564564
* The rk_nfc_ooblayout_free() function already has reserved
565-
* these 4 bytes with:
565+
* these 4 bytes together with 2 bytes for BBM
566+
* by reducing it's length:
566567
*
567-
* oob_region->offset = NFC_SYS_DATA_SIZE + 2;
568+
* oob_region->length = rknand->metadata_size - NFC_SYS_DATA_SIZE - 2;
568569
*/
569570
if (!i)
570571
memcpy(rk_nfc_oob_ptr(chip, i),
@@ -597,7 +598,7 @@ static int rk_nfc_write_page_hwecc(struct nand_chip *chip, const u8 *buf,
597598
int pages_per_blk = mtd->erasesize / mtd->writesize;
598599
int ret = 0, i, boot_rom_mode = 0;
599600
dma_addr_t dma_data, dma_oob;
600-
u32 reg;
601+
u32 tmp;
601602
u8 *oob;
602603

603604
nand_prog_page_begin_op(chip, page, 0, NULL, 0);
@@ -624,6 +625,13 @@ static int rk_nfc_write_page_hwecc(struct nand_chip *chip, const u8 *buf,
624625
*
625626
* 0xFF 0xFF 0xFF 0xFF | BBM OOB1 OOB2 OOB3 | ...
626627
*
628+
* The code here just swaps the first 4 bytes with the last
629+
* 4 bytes without losing any data.
630+
*
631+
* The chip->oob_poi data layout:
632+
*
633+
* BBM OOB1 OOB2 OOB3 |......| PA0 PA1 PA2 PA3
634+
*
627635
* Configure the ECC algorithm supported by the boot ROM.
628636
*/
629637
if ((page < (pages_per_blk * rknand->boot_blks)) &&
@@ -634,21 +642,17 @@ static int rk_nfc_write_page_hwecc(struct nand_chip *chip, const u8 *buf,
634642
}
635643

636644
for (i = 0; i < ecc->steps; i++) {
637-
if (!i) {
638-
reg = 0xFFFFFFFF;
639-
} else {
645+
if (!i)
646+
oob = chip->oob_poi + (ecc->steps - 1) * NFC_SYS_DATA_SIZE;
647+
else
640648
oob = chip->oob_poi + (i - 1) * NFC_SYS_DATA_SIZE;
641-
reg = oob[0] | oob[1] << 8 | oob[2] << 16 |
642-
oob[3] << 24;
643-
}
644649

645-
if (!i && boot_rom_mode)
646-
reg = (page & (pages_per_blk - 1)) * 4;
650+
tmp = oob[0] | oob[1] << 8 | oob[2] << 16 | oob[3] << 24;
647651

648652
if (nfc->cfg->type == NFC_V9)
649-
nfc->oob_buf[i] = reg;
653+
nfc->oob_buf[i] = tmp;
650654
else
651-
nfc->oob_buf[i * (oob_step / 4)] = reg;
655+
nfc->oob_buf[i * (oob_step / 4)] = tmp;
652656
}
653657

654658
dma_data = dma_map_single(nfc->dev, (void *)nfc->page_buf,
@@ -811,12 +815,17 @@ static int rk_nfc_read_page_hwecc(struct nand_chip *chip, u8 *buf, int oob_on,
811815
goto timeout_err;
812816
}
813817

814-
for (i = 1; i < ecc->steps; i++) {
815-
oob = chip->oob_poi + (i - 1) * NFC_SYS_DATA_SIZE;
818+
for (i = 0; i < ecc->steps; i++) {
819+
if (!i)
820+
oob = chip->oob_poi + (ecc->steps - 1) * NFC_SYS_DATA_SIZE;
821+
else
822+
oob = chip->oob_poi + (i - 1) * NFC_SYS_DATA_SIZE;
823+
816824
if (nfc->cfg->type == NFC_V9)
817825
tmp = nfc->oob_buf[i];
818826
else
819827
tmp = nfc->oob_buf[i * (oob_step / 4)];
828+
820829
*oob++ = (u8)tmp;
821830
*oob++ = (u8)(tmp >> 8);
822831
*oob++ = (u8)(tmp >> 16);
@@ -933,12 +942,8 @@ static int rk_nfc_ooblayout_free(struct mtd_info *mtd, int section,
933942
if (section)
934943
return -ERANGE;
935944

936-
/*
937-
* The beginning of the OOB area stores the reserved data for the NFC,
938-
* the size of the reserved data is NFC_SYS_DATA_SIZE bytes.
939-
*/
940945
oob_region->length = rknand->metadata_size - NFC_SYS_DATA_SIZE - 2;
941-
oob_region->offset = NFC_SYS_DATA_SIZE + 2;
946+
oob_region->offset = 2;
942947

943948
return 0;
944949
}

drivers/mtd/nand/spi/toshiba.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static int tx58cxgxsxraix_ecc_get_status(struct spinand_device *spinand,
7373
{
7474
struct nand_device *nand = spinand_to_nand(spinand);
7575
u8 mbf = 0;
76-
struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, &mbf);
76+
struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, spinand->scratchbuf);
7777

7878
switch (status & STATUS_ECC_MASK) {
7979
case STATUS_ECC_NO_BITFLIPS:
@@ -92,7 +92,7 @@ static int tx58cxgxsxraix_ecc_get_status(struct spinand_device *spinand,
9292
if (spi_mem_exec_op(spinand->spimem, &op))
9393
return nanddev_get_ecc_conf(nand)->strength;
9494

95-
mbf >>= 4;
95+
mbf = *(spinand->scratchbuf) >> 4;
9696

9797
if (WARN_ON(mbf > nanddev_get_ecc_conf(nand)->strength || !mbf))
9898
return nanddev_get_ecc_conf(nand)->strength;

drivers/mtd/nand/spi/winbond.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static int w25n02kv_ecc_get_status(struct spinand_device *spinand,
108108
{
109109
struct nand_device *nand = spinand_to_nand(spinand);
110110
u8 mbf = 0;
111-
struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, &mbf);
111+
struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, spinand->scratchbuf);
112112

113113
switch (status & STATUS_ECC_MASK) {
114114
case STATUS_ECC_NO_BITFLIPS:
@@ -126,7 +126,7 @@ static int w25n02kv_ecc_get_status(struct spinand_device *spinand,
126126
if (spi_mem_exec_op(spinand->spimem, &op))
127127
return nanddev_get_ecc_conf(nand)->strength;
128128

129-
mbf >>= 4;
129+
mbf = *(spinand->scratchbuf) >> 4;
130130

131131
if (WARN_ON(mbf > nanddev_get_ecc_conf(nand)->strength || !mbf))
132132
return nanddev_get_ecc_conf(nand)->strength;

drivers/mtd/spi-nor/spansion.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ static int cypress_nor_determine_addr_mode_by_sr1(struct spi_nor *nor,
361361
*/
362362
static int cypress_nor_set_addr_mode_nbytes(struct spi_nor *nor)
363363
{
364-
struct spi_mem_op op = {};
364+
struct spi_mem_op op;
365365
u8 addr_mode;
366366
int ret;
367367

@@ -492,7 +492,7 @@ s25fs256t_post_bfpt_fixup(struct spi_nor *nor,
492492
const struct sfdp_parameter_header *bfpt_header,
493493
const struct sfdp_bfpt *bfpt)
494494
{
495-
struct spi_mem_op op = {};
495+
struct spi_mem_op op;
496496
int ret;
497497

498498
ret = cypress_nor_set_addr_mode_nbytes(nor);

include/linux/spi/spi-mem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,30 @@ struct spi_mem_op {
101101
u8 nbytes;
102102
u8 buswidth;
103103
u8 dtr : 1;
104+
u8 __pad : 7;
104105
u16 opcode;
105106
} cmd;
106107

107108
struct {
108109
u8 nbytes;
109110
u8 buswidth;
110111
u8 dtr : 1;
112+
u8 __pad : 7;
111113
u64 val;
112114
} addr;
113115

114116
struct {
115117
u8 nbytes;
116118
u8 buswidth;
117119
u8 dtr : 1;
120+
u8 __pad : 7;
118121
} dummy;
119122

120123
struct {
121124
u8 buswidth;
122125
u8 dtr : 1;
123126
u8 ecc : 1;
127+
u8 __pad : 6;
124128
enum spi_mem_data_dir dir;
125129
unsigned int nbytes;
126130
union {

0 commit comments

Comments
 (0)