Skip to content

Commit 766f271

Browse files
Ian MunsieDavid Woodhouse
authored andcommitted
mtd: Fix endianness issues from device tree
This patch adds the appropriate conversions to correct the endianness issues in the MTD driver whenever it accesses the device tree (which is always big endian). Signed-off-by: Ian Munsie <imunsie@au1.ibm.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent d86fbdb commit 766f271

5 files changed

Lines changed: 20 additions & 20 deletions

File tree

‎drivers/mtd/maps/physmap_of.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static int parse_obsolete_partitions(struct platform_device *dev,
5050
{
5151
int i, plen, nr_parts;
5252
const struct {
53-
u32 offset, len;
53+
__be32 offset, len;
5454
} *part;
5555
const char *names;
5656

@@ -69,9 +69,9 @@ static int parse_obsolete_partitions(struct platform_device *dev,
6969
names = of_get_property(dp, "partition-names", &plen);
7070

7171
for (i = 0; i < nr_parts; i++) {
72-
info->parts[i].offset = part->offset;
73-
info->parts[i].size = part->len & ~1;
74-
if (part->len & 1) /* bit 0 set signifies read only partition */
72+
info->parts[i].offset = be32_to_cpu(part->offset);
73+
info->parts[i].size = be32_to_cpu(part->len) & ~1;
74+
if (be32_to_cpu(part->len) & 1) /* bit 0 set signifies read only partition */
7575
info->parts[i].mask_flags = MTD_WRITEABLE;
7676

7777
if (names && (plen > 0)) {
@@ -226,11 +226,11 @@ static int __devinit of_flash_probe(struct platform_device *dev,
226226
struct resource res;
227227
struct of_flash *info;
228228
const char *probe_type = match->data;
229-
const u32 *width;
229+
const __be32 *width;
230230
int err;
231231
int i;
232232
int count;
233-
const u32 *p;
233+
const __be32 *p;
234234
int reg_tuple_size;
235235
struct mtd_info **mtd_list = NULL;
236236
resource_size_t res_size;
@@ -294,7 +294,7 @@ static int __devinit of_flash_probe(struct platform_device *dev,
294294
info->list[i].map.name = dev_name(&dev->dev);
295295
info->list[i].map.phys = res.start;
296296
info->list[i].map.size = res_size;
297-
info->list[i].map.bankwidth = *width;
297+
info->list[i].map.bankwidth = be32_to_cpup(width);
298298

299299
err = -ENOMEM;
300300
info->list[i].map.virt = ioremap(info->list[i].map.phys,

‎drivers/mtd/nand/fsl_upm.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static int __devinit fun_probe(struct platform_device *ofdev,
222222
{
223223
struct fsl_upm_nand *fun;
224224
struct resource io_res;
225-
const uint32_t *prop;
225+
const __be32 *prop;
226226
int rnb_gpio;
227227
int ret;
228228
int size;
@@ -270,7 +270,7 @@ static int __devinit fun_probe(struct platform_device *ofdev,
270270
goto err1;
271271
}
272272
for (i = 0; i < fun->mchip_count; i++)
273-
fun->mchip_offsets[i] = prop[i];
273+
fun->mchip_offsets[i] = be32_to_cpu(prop[i]);
274274
} else {
275275
fun->mchip_count = 1;
276276
}
@@ -295,13 +295,13 @@ static int __devinit fun_probe(struct platform_device *ofdev,
295295

296296
prop = of_get_property(ofdev->dev.of_node, "chip-delay", NULL);
297297
if (prop)
298-
fun->chip_delay = *prop;
298+
fun->chip_delay = be32_to_cpup(prop);
299299
else
300300
fun->chip_delay = 50;
301301

302302
prop = of_get_property(ofdev->dev.of_node, "fsl,upm-wait-flags", &size);
303303
if (prop && size == sizeof(uint32_t))
304-
fun->wait_flags = *prop;
304+
fun->wait_flags = be32_to_cpup(prop);
305305
else
306306
fun->wait_flags = FSL_UPM_WAIT_RUN_PATTERN |
307307
FSL_UPM_WAIT_WRITE_BYTE;

‎drivers/mtd/nand/mpc5121_nfc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ static int __devinit mpc5121_nfc_probe(struct platform_device *op,
663663
#endif
664664
struct nand_chip *chip;
665665
unsigned long regs_paddr, regs_size;
666-
const uint *chips_no;
666+
const __be32 *chips_no;
667667
int resettime = 0;
668668
int retval = 0;
669669
int rev, len;
@@ -806,7 +806,7 @@ static int __devinit mpc5121_nfc_probe(struct platform_device *op,
806806
}
807807

808808
/* Detect NAND chips */
809-
if (nand_scan(mtd, *chips_no)) {
809+
if (nand_scan(mtd, be32_to_cpup(chips_no))) {
810810
dev_err(dev, "NAND Flash not found !\n");
811811
devm_free_irq(dev, prv->irq, mtd);
812812
retval = -ENXIO;

‎drivers/mtd/nand/ndfc.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static int __devinit ndfc_probe(struct platform_device *ofdev,
229229
const struct of_device_id *match)
230230
{
231231
struct ndfc_controller *ndfc = &ndfc_ctrl;
232-
const u32 *reg;
232+
const __be32 *reg;
233233
u32 ccr;
234234
int err, len;
235235

@@ -244,7 +244,7 @@ static int __devinit ndfc_probe(struct platform_device *ofdev,
244244
dev_err(&ofdev->dev, "unable read reg property (%d)\n", len);
245245
return -ENOENT;
246246
}
247-
ndfc->chip_select = reg[0];
247+
ndfc->chip_select = be32_to_cpu(reg[0]);
248248

249249
ndfc->ndfcbase = of_iomap(ofdev->dev.of_node, 0);
250250
if (!ndfc->ndfcbase) {
@@ -257,15 +257,15 @@ static int __devinit ndfc_probe(struct platform_device *ofdev,
257257
/* It is ok if ccr does not exist - just default to 0 */
258258
reg = of_get_property(ofdev->dev.of_node, "ccr", NULL);
259259
if (reg)
260-
ccr |= *reg;
260+
ccr |= be32_to_cpup(reg);
261261

262262
out_be32(ndfc->ndfcbase + NDFC_CCR, ccr);
263263

264264
/* Set the bank settings if given */
265265
reg = of_get_property(ofdev->dev.of_node, "bank-settings", NULL);
266266
if (reg) {
267267
int offset = NDFC_BCFG0 + (ndfc->chip_select << 2);
268-
out_be32(ndfc->ndfcbase + offset, *reg);
268+
out_be32(ndfc->ndfcbase + offset, be32_to_cpup(reg));
269269
}
270270

271271
err = ndfc_chip_init(ndfc, ofdev->dev.of_node);

‎drivers/mtd/ofpart.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int __devinit of_mtd_parse_partitions(struct device *dev,
4444
pp = NULL;
4545
i = 0;
4646
while ((pp = of_get_next_child(node, pp))) {
47-
const u32 *reg;
47+
const __be32 *reg;
4848
int len;
4949

5050
reg = of_get_property(pp, "reg", &len);
@@ -53,8 +53,8 @@ int __devinit of_mtd_parse_partitions(struct device *dev,
5353
continue;
5454
}
5555

56-
(*pparts)[i].offset = reg[0];
57-
(*pparts)[i].size = reg[1];
56+
(*pparts)[i].offset = be32_to_cpu(reg[0]);
57+
(*pparts)[i].size = be32_to_cpu(reg[1]);
5858

5959
partname = of_get_property(pp, "label", &len);
6060
if (!partname)

0 commit comments

Comments
 (0)