CRIS v32: Clean up nandflash.c for ARTPEC-3 and ETRAX FS.

Clean up issues noticed by Andrew Morton:

- Use a combined struct for allocating the mtd_info and nand_chip structs
instead of using anonymous memory as the example in
Documentation/DocBook/mtdnand.tmpl
- Use kzalloc instead of using kmalloc/memset(0)
- Make crisv32_device_ready static.

+24 -20
+12 -10
arch/cris/arch-v32/drivers/mach-a3/nandflash.c
··· 35 35 #define ALE_BIT 11 36 36 #define CE_BIT 12 37 37 38 + struct mtd_info_wrapper { 39 + struct mtd_info info; 40 + struct nand_chip chip; 41 + }; 42 + 38 43 /* Bitmask for control pins */ 39 44 #define PIN_BITMASK ((1 << CE_BIT) | (1 << CLE_BIT) | (1 << ALE_BIT)) 40 45 ··· 93 88 /* 94 89 * read device ready pin 95 90 */ 96 - int crisv32_device_ready(struct mtd_info *mtd) 91 + static int crisv32_device_ready(struct mtd_info *mtd) 97 92 { 98 93 reg_pio_r_din din = REG_RD(pio, regi_pio, r_din); 99 94 return din.rdy; ··· 107 102 void __iomem *read_cs; 108 103 void __iomem *write_cs; 109 104 105 + struct mtd_info_wrapper *wrapper; 110 106 struct nand_chip *this; 111 107 int err = 0; 112 108 ··· 135 129 REG_WR(pio, regi_pio, rw_oe, oe); 136 130 137 131 /* Allocate memory for MTD device structure and private data */ 138 - crisv32_mtd = kmalloc(sizeof(struct mtd_info) + 139 - sizeof(struct nand_chip), GFP_KERNEL); 140 - if (!crisv32_mtd) { 132 + wrapper = kzalloc(sizeof(struct mtd_info_wrapper), GFP_KERNEL); 133 + if (!wrapper) { 141 134 printk(KERN_ERR "Unable to allocate CRISv32 NAND MTD " 142 135 "device structure.\n"); 143 136 err = -ENOMEM; ··· 147 142 rw_io_access0); 148 143 149 144 /* Get pointer to private data */ 150 - this = (struct nand_chip *) (&crisv32_mtd[1]); 151 - 152 - /* Initialize structures */ 153 - memset((char *) crisv32_mtd, 0, sizeof(struct mtd_info)); 154 - memset((char *) this, 0, sizeof(struct nand_chip)); 145 + this = &wrapper->chip; 146 + crisv32_mtd = &wrapper->info; 155 147 156 148 /* Link the private data with the MTD structure */ 157 149 crisv32_mtd->priv = this; ··· 174 172 return crisv32_mtd; 175 173 176 174 out_mtd: 177 - kfree(crisv32_mtd); 175 + kfree(wrapper); 178 176 return NULL; 179 177 } 180 178
+12 -10
arch/cris/arch-v32/drivers/mach-fs/nandflash.c
··· 30 30 #define ALE_BIT 6 31 31 #define BY_BIT 7 32 32 33 + struct mtd_info_wrapper { 34 + struct mtd_info info; 35 + struct nand_chip chip; 36 + }; 37 + 33 38 /* Bitmask for control pins */ 34 39 #define PIN_BITMASK ((1 << CE_BIT) | (1 << CLE_BIT) | (1 << ALE_BIT)) 35 40 ··· 88 83 /* 89 84 * read device ready pin 90 85 */ 91 - int crisv32_device_ready(struct mtd_info *mtd) 86 + static int crisv32_device_ready(struct mtd_info *mtd) 92 87 { 93 88 reg_gio_r_pa_din din = REG_RD(gio, regi_gio, r_pa_din); 94 89 return ((din.data & (1 << BY_BIT)) >> BY_BIT); ··· 105 100 reg_bif_core_rw_grp3_cfg bif_cfg = REG_RD(bif_core, regi_bif_core, 106 101 rw_grp3_cfg); 107 102 reg_gio_rw_pa_oe pa_oe = REG_RD(gio, regi_gio, rw_pa_oe); 103 + struct mtd_info_wrapper *wrapper; 108 104 struct nand_chip *this; 109 105 int err = 0; 110 106 111 107 /* Allocate memory for MTD device structure and private data */ 112 - crisv32_mtd = kmalloc(sizeof(struct mtd_info) + 113 - sizeof(struct nand_chip), GFP_KERNEL); 114 - if (!crisv32_mtd) { 108 + wrapper = kzalloc(sizeof(struct mtd_info_wrapper), GFP_KERNEL); 109 + if (!wrapper) { 115 110 printk(KERN_ERR "Unable to allocate CRISv32 NAND MTD " 116 111 "device structure.\n"); 117 112 err = -ENOMEM; ··· 128 123 } 129 124 130 125 /* Get pointer to private data */ 131 - this = (struct nand_chip *) (&crisv32_mtd[1]); 126 + this = &wrapper->chip; 127 + crisv32_mtd = &wrapper->info; 132 128 133 129 pa_oe.oe |= 1 << CE_BIT; 134 130 pa_oe.oe |= 1 << ALE_BIT; ··· 140 134 bif_cfg.gated_csp0 = regk_bif_core_rd; 141 135 bif_cfg.gated_csp1 = regk_bif_core_wr; 142 136 REG_WR(bif_core, regi_bif_core, rw_grp3_cfg, bif_cfg); 143 - 144 - /* Initialize structures */ 145 - memset((char *) crisv32_mtd, 0, sizeof(struct mtd_info)); 146 - memset((char *) this, 0, sizeof(struct nand_chip)); 147 137 148 138 /* Link the private data with the MTD structure */ 149 139 crisv32_mtd->priv = this; ··· 168 166 iounmap((void *)read_cs); 169 167 iounmap((void *)write_cs); 170 168 out_mtd: 171 - kfree(crisv32_mtd); 169 + kfree(wrapper); 172 170 return NULL; 173 171 } 174 172