Skip to content

Commit 7993e65

Browse files
committed
Merge tag 'mtd/fixes-for-5.17-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux
Pull MTD fixes from Miquel Raynal: "MTD changes: - Qcom: - Don't print error message on -EPROBE_DEFER - Fix kernel panic on skipped partition - Fix missing free for pparts in cleanup - phram: Prevent divide by zero bug in phram_setup() Raw NAND controller changes: - ingenic: Fix missing put_device in ingenic_ecc_get - qcom: Fix clock sequencing in qcom_nandc_probe() - omap2: Prevent invalid configuration and build error - gpmi: Don't leak PM reference in error path - brcmnand: Fix incorrect sub-page ECC status" * tag 'mtd/fixes-for-5.17-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux: mtd: rawnand: brcmnand: Fixed incorrect sub-page ECC status mtd: rawnand: gpmi: don't leak PM reference in error path mtd: phram: Prevent divide by zero bug in phram_setup() mtd: rawnand: omap2: Prevent invalid configuration and build error mtd: parsers: qcom: Fix missing free for pparts in cleanup mtd: parsers: qcom: Fix kernel panic on skipped partition mtd: parsers: qcom: Don't print error message on -EPROBE_DEFER mtd: rawnand: qcom: Fix clock sequencing in qcom_nandc_probe() mtd: rawnand: ingenic: Fix missing put_device in ingenic_ecc_get
2 parents b988976 + 36415a7 commit 7993e65

7 files changed

Lines changed: 48 additions & 29 deletions

File tree

drivers/mtd/devices/phram.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,20 @@ static int phram_setup(const char *val)
264264
}
265265
}
266266

267-
if (erasesize)
268-
div_u64_rem(len, (uint32_t)erasesize, &rem);
269-
270267
if (len == 0 || erasesize == 0 || erasesize > len
271-
|| erasesize > UINT_MAX || rem) {
268+
|| erasesize > UINT_MAX) {
272269
parse_err("illegal erasesize or len\n");
273270
ret = -EINVAL;
274271
goto error;
275272
}
276273

274+
div_u64_rem(len, (uint32_t)erasesize, &rem);
275+
if (rem) {
276+
parse_err("len is not multiple of erasesize\n");
277+
ret = -EINVAL;
278+
goto error;
279+
}
280+
277281
ret = register_device(name, start, len, (uint32_t)erasesize);
278282
if (ret)
279283
goto error;

drivers/mtd/nand/raw/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ config MTD_NAND_OMAP2
4242
tristate "OMAP2, OMAP3, OMAP4 and Keystone NAND controller"
4343
depends on ARCH_OMAP2PLUS || ARCH_KEYSTONE || ARCH_K3 || COMPILE_TEST
4444
depends on HAS_IOMEM
45-
select OMAP_GPMC if ARCH_K3
45+
select MEMORY
46+
select OMAP_GPMC
4647
help
4748
Support for NAND flash on Texas Instruments OMAP2, OMAP3, OMAP4
4849
and Keystone platforms.

drivers/mtd/nand/raw/brcmnand/brcmnand.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2106,7 +2106,7 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip,
21062106
mtd->oobsize / trans,
21072107
host->hwcfg.sector_size_1k);
21082108

2109-
if (!ret) {
2109+
if (ret != -EBADMSG) {
21102110
*err_addr = brcmnand_get_uncorrecc_addr(ctrl);
21112111

21122112
if (*err_addr)

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2285,7 +2285,7 @@ static int gpmi_nfc_exec_op(struct nand_chip *chip,
22852285
this->hw.must_apply_timings = false;
22862286
ret = gpmi_nfc_apply_timings(this);
22872287
if (ret)
2288-
return ret;
2288+
goto out_pm;
22892289
}
22902290

22912291
dev_dbg(this->dev, "%s: %d instructions\n", __func__, op->ninstrs);
@@ -2414,6 +2414,7 @@ static int gpmi_nfc_exec_op(struct nand_chip *chip,
24142414

24152415
this->bch = false;
24162416

2417+
out_pm:
24172418
pm_runtime_mark_last_busy(this->dev);
24182419
pm_runtime_put_autosuspend(this->dev);
24192420

drivers/mtd/nand/raw/ingenic/ingenic_ecc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,14 @@ static struct ingenic_ecc *ingenic_ecc_get(struct device_node *np)
6868
struct ingenic_ecc *ecc;
6969

7070
pdev = of_find_device_by_node(np);
71-
if (!pdev || !platform_get_drvdata(pdev))
71+
if (!pdev)
7272
return ERR_PTR(-EPROBE_DEFER);
7373

74+
if (!platform_get_drvdata(pdev)) {
75+
put_device(&pdev->dev);
76+
return ERR_PTR(-EPROBE_DEFER);
77+
}
78+
7479
ecc = platform_get_drvdata(pdev);
7580
clk_prepare_enable(ecc->clk);
7681

drivers/mtd/nand/raw/qcom_nandc.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/*
33
* Copyright (c) 2016, The Linux Foundation. All rights reserved.
44
*/
5-
65
#include <linux/clk.h>
76
#include <linux/slab.h>
87
#include <linux/bitops.h>
@@ -3073,10 +3072,6 @@ static int qcom_nandc_probe(struct platform_device *pdev)
30733072
if (dma_mapping_error(dev, nandc->base_dma))
30743073
return -ENXIO;
30753074

3076-
ret = qcom_nandc_alloc(nandc);
3077-
if (ret)
3078-
goto err_nandc_alloc;
3079-
30803075
ret = clk_prepare_enable(nandc->core_clk);
30813076
if (ret)
30823077
goto err_core_clk;
@@ -3085,6 +3080,10 @@ static int qcom_nandc_probe(struct platform_device *pdev)
30853080
if (ret)
30863081
goto err_aon_clk;
30873082

3083+
ret = qcom_nandc_alloc(nandc);
3084+
if (ret)
3085+
goto err_nandc_alloc;
3086+
30883087
ret = qcom_nandc_setup(nandc);
30893088
if (ret)
30903089
goto err_setup;
@@ -3096,15 +3095,14 @@ static int qcom_nandc_probe(struct platform_device *pdev)
30963095
return 0;
30973096

30983097
err_setup:
3098+
qcom_nandc_unalloc(nandc);
3099+
err_nandc_alloc:
30993100
clk_disable_unprepare(nandc->aon_clk);
31003101
err_aon_clk:
31013102
clk_disable_unprepare(nandc->core_clk);
31023103
err_core_clk:
3103-
qcom_nandc_unalloc(nandc);
3104-
err_nandc_alloc:
31053104
dma_unmap_resource(dev, res->start, resource_size(res),
31063105
DMA_BIDIRECTIONAL, 0);
3107-
31083106
return ret;
31093107
}
31103108

drivers/mtd/parsers/qcomsmempart.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ static int parse_qcomsmem_part(struct mtd_info *mtd,
5858
const struct mtd_partition **pparts,
5959
struct mtd_part_parser_data *data)
6060
{
61+
size_t len = SMEM_FLASH_PTABLE_HDR_LEN;
62+
int ret, i, j, tmpparts, numparts = 0;
6163
struct smem_flash_pentry *pentry;
6264
struct smem_flash_ptable *ptable;
63-
size_t len = SMEM_FLASH_PTABLE_HDR_LEN;
6465
struct mtd_partition *parts;
65-
int ret, i, numparts;
6666
char *name, *c;
6767

6868
if (IS_ENABLED(CONFIG_MTD_SPI_NOR_USE_4K_SECTORS)
@@ -75,7 +75,8 @@ static int parse_qcomsmem_part(struct mtd_info *mtd,
7575
pr_debug("Parsing partition table info from SMEM\n");
7676
ptable = qcom_smem_get(SMEM_APPS, SMEM_AARM_PARTITION_TABLE, &len);
7777
if (IS_ERR(ptable)) {
78-
pr_err("Error reading partition table header\n");
78+
if (PTR_ERR(ptable) != -EPROBE_DEFER)
79+
pr_err("Error reading partition table header\n");
7980
return PTR_ERR(ptable);
8081
}
8182

@@ -87,8 +88,8 @@ static int parse_qcomsmem_part(struct mtd_info *mtd,
8788
}
8889

8990
/* Ensure that # of partitions is less than the max we have allocated */
90-
numparts = le32_to_cpu(ptable->numparts);
91-
if (numparts > SMEM_FLASH_PTABLE_MAX_PARTS_V4) {
91+
tmpparts = le32_to_cpu(ptable->numparts);
92+
if (tmpparts > SMEM_FLASH_PTABLE_MAX_PARTS_V4) {
9293
pr_err("Partition numbers exceed the max limit\n");
9394
return -EINVAL;
9495
}
@@ -116,11 +117,17 @@ static int parse_qcomsmem_part(struct mtd_info *mtd,
116117
return PTR_ERR(ptable);
117118
}
118119

120+
for (i = 0; i < tmpparts; i++) {
121+
pentry = &ptable->pentry[i];
122+
if (pentry->name[0] != '\0')
123+
numparts++;
124+
}
125+
119126
parts = kcalloc(numparts, sizeof(*parts), GFP_KERNEL);
120127
if (!parts)
121128
return -ENOMEM;
122129

123-
for (i = 0; i < numparts; i++) {
130+
for (i = 0, j = 0; i < tmpparts; i++) {
124131
pentry = &ptable->pentry[i];
125132
if (pentry->name[0] == '\0')
126133
continue;
@@ -135,24 +142,25 @@ static int parse_qcomsmem_part(struct mtd_info *mtd,
135142
for (c = name; *c != '\0'; c++)
136143
*c = tolower(*c);
137144

138-
parts[i].name = name;
139-
parts[i].offset = le32_to_cpu(pentry->offset) * mtd->erasesize;
140-
parts[i].mask_flags = pentry->attr;
141-
parts[i].size = le32_to_cpu(pentry->length) * mtd->erasesize;
145+
parts[j].name = name;
146+
parts[j].offset = le32_to_cpu(pentry->offset) * mtd->erasesize;
147+
parts[j].mask_flags = pentry->attr;
148+
parts[j].size = le32_to_cpu(pentry->length) * mtd->erasesize;
142149
pr_debug("%d: %s offs=0x%08x size=0x%08x attr:0x%08x\n",
143150
i, pentry->name, le32_to_cpu(pentry->offset),
144151
le32_to_cpu(pentry->length), pentry->attr);
152+
j++;
145153
}
146154

147155
pr_debug("SMEM partition table found: ver: %d len: %d\n",
148-
le32_to_cpu(ptable->version), numparts);
156+
le32_to_cpu(ptable->version), tmpparts);
149157
*pparts = parts;
150158

151159
return numparts;
152160

153161
out_free_parts:
154-
while (--i >= 0)
155-
kfree(parts[i].name);
162+
while (--j >= 0)
163+
kfree(parts[j].name);
156164
kfree(parts);
157165
*pparts = NULL;
158166

@@ -166,6 +174,8 @@ static void parse_qcomsmem_cleanup(const struct mtd_partition *pparts,
166174

167175
for (i = 0; i < nr_parts; i++)
168176
kfree(pparts[i].name);
177+
178+
kfree(pparts);
169179
}
170180

171181
static const struct of_device_id qcomsmem_of_match_table[] = {

0 commit comments

Comments
 (0)