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

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>

authored by

Ian Munsie and committed by
David Woodhouse
766f271a d86fbdb8

+20 -20
+7 -7
drivers/mtd/maps/physmap_of.c
··· 50 50 { 51 51 int i, plen, nr_parts; 52 52 const struct { 53 - u32 offset, len; 53 + __be32 offset, len; 54 54 } *part; 55 55 const char *names; 56 56 ··· 69 69 names = of_get_property(dp, "partition-names", &plen); 70 70 71 71 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 */ 75 75 info->parts[i].mask_flags = MTD_WRITEABLE; 76 76 77 77 if (names && (plen > 0)) { ··· 226 226 struct resource res; 227 227 struct of_flash *info; 228 228 const char *probe_type = match->data; 229 - const u32 *width; 229 + const __be32 *width; 230 230 int err; 231 231 int i; 232 232 int count; 233 - const u32 *p; 233 + const __be32 *p; 234 234 int reg_tuple_size; 235 235 struct mtd_info **mtd_list = NULL; 236 236 resource_size_t res_size; ··· 294 294 info->list[i].map.name = dev_name(&dev->dev); 295 295 info->list[i].map.phys = res.start; 296 296 info->list[i].map.size = res_size; 297 - info->list[i].map.bankwidth = *width; 297 + info->list[i].map.bankwidth = be32_to_cpup(width); 298 298 299 299 err = -ENOMEM; 300 300 info->list[i].map.virt = ioremap(info->list[i].map.phys,
+4 -4
drivers/mtd/nand/fsl_upm.c
··· 222 222 { 223 223 struct fsl_upm_nand *fun; 224 224 struct resource io_res; 225 - const uint32_t *prop; 225 + const __be32 *prop; 226 226 int rnb_gpio; 227 227 int ret; 228 228 int size; ··· 270 270 goto err1; 271 271 } 272 272 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]); 274 274 } else { 275 275 fun->mchip_count = 1; 276 276 } ··· 295 295 296 296 prop = of_get_property(ofdev->dev.of_node, "chip-delay", NULL); 297 297 if (prop) 298 - fun->chip_delay = *prop; 298 + fun->chip_delay = be32_to_cpup(prop); 299 299 else 300 300 fun->chip_delay = 50; 301 301 302 302 prop = of_get_property(ofdev->dev.of_node, "fsl,upm-wait-flags", &size); 303 303 if (prop && size == sizeof(uint32_t)) 304 - fun->wait_flags = *prop; 304 + fun->wait_flags = be32_to_cpup(prop); 305 305 else 306 306 fun->wait_flags = FSL_UPM_WAIT_RUN_PATTERN | 307 307 FSL_UPM_WAIT_WRITE_BYTE;
+2 -2
drivers/mtd/nand/mpc5121_nfc.c
··· 663 663 #endif 664 664 struct nand_chip *chip; 665 665 unsigned long regs_paddr, regs_size; 666 - const uint *chips_no; 666 + const __be32 *chips_no; 667 667 int resettime = 0; 668 668 int retval = 0; 669 669 int rev, len; ··· 806 806 } 807 807 808 808 /* Detect NAND chips */ 809 - if (nand_scan(mtd, *chips_no)) { 809 + if (nand_scan(mtd, be32_to_cpup(chips_no))) { 810 810 dev_err(dev, "NAND Flash not found !\n"); 811 811 devm_free_irq(dev, prv->irq, mtd); 812 812 retval = -ENXIO;
+4 -4
drivers/mtd/nand/ndfc.c
··· 229 229 const struct of_device_id *match) 230 230 { 231 231 struct ndfc_controller *ndfc = &ndfc_ctrl; 232 - const u32 *reg; 232 + const __be32 *reg; 233 233 u32 ccr; 234 234 int err, len; 235 235 ··· 244 244 dev_err(&ofdev->dev, "unable read reg property (%d)\n", len); 245 245 return -ENOENT; 246 246 } 247 - ndfc->chip_select = reg[0]; 247 + ndfc->chip_select = be32_to_cpu(reg[0]); 248 248 249 249 ndfc->ndfcbase = of_iomap(ofdev->dev.of_node, 0); 250 250 if (!ndfc->ndfcbase) { ··· 257 257 /* It is ok if ccr does not exist - just default to 0 */ 258 258 reg = of_get_property(ofdev->dev.of_node, "ccr", NULL); 259 259 if (reg) 260 - ccr |= *reg; 260 + ccr |= be32_to_cpup(reg); 261 261 262 262 out_be32(ndfc->ndfcbase + NDFC_CCR, ccr); 263 263 ··· 265 265 reg = of_get_property(ofdev->dev.of_node, "bank-settings", NULL); 266 266 if (reg) { 267 267 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)); 269 269 } 270 270 271 271 err = ndfc_chip_init(ndfc, ofdev->dev.of_node);
+3 -3
drivers/mtd/ofpart.c
··· 44 44 pp = NULL; 45 45 i = 0; 46 46 while ((pp = of_get_next_child(node, pp))) { 47 - const u32 *reg; 47 + const __be32 *reg; 48 48 int len; 49 49 50 50 reg = of_get_property(pp, "reg", &len); ··· 53 53 continue; 54 54 } 55 55 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]); 58 58 59 59 partname = of_get_property(pp, "label", &len); 60 60 if (!partname)