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

ide: do not access ide_drive_t 'drive_data' field directly

Change ide_drive_t 'drive_data' field from 'unsigned int' type to 'void *'
type, allowing a wider range of values/types to be stored in this field.

Added 'ide_get_drivedata' and 'ide_set_drivedata' helpers to get and set
the 'drive_data' field.

Fixed all host drivers to maintain coherency with the change in the
'drive_data' field type.

Signed-off-by: Joao Ramos <joao.ramos@inov.pt>
[bart: fix qd65xx build, cast to 'unsigned long', minor Coding Style fixups]
Acked-by: Sergei Shtylyov <sshtylyov@ru.montavista.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>

authored by

Joao Ramos and committed by
Bartlomiej Zolnierkiewicz
5bfb151f 3779f818

+94 -40
+5 -3
drivers/ide/cmd64x.c
··· 118 118 ide_hwif_t *hwif = drive->hwif; 119 119 struct pci_dev *dev = to_pci_dev(hwif->dev); 120 120 struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio); 121 + unsigned long setup_count; 121 122 unsigned int cycle_time; 122 - u8 setup_count, arttim = 0; 123 + u8 arttim = 0; 123 124 124 125 static const u8 setup_values[] = {0x40, 0x40, 0x40, 0x80, 0, 0xc0}; 125 126 static const u8 arttim_regs[4] = {ARTTIM0, ARTTIM1, ARTTIM23, ARTTIM23}; ··· 141 140 if (hwif->channel) { 142 141 ide_drive_t *pair = ide_get_pair_dev(drive); 143 142 144 - drive->drive_data = setup_count; 143 + ide_set_drivedata(drive, (void *)setup_count); 145 144 146 145 if (pair) 147 - setup_count = max_t(u8, setup_count, pair->drive_data); 146 + setup_count = max_t(u8, setup_count, 147 + (unsigned long)ide_get_drivedata(pair)); 148 148 } 149 149 150 150 if (setup_count > 5) /* shouldn't actually happen... */
+15 -8
drivers/ide/cs5536.c
··· 146 146 struct pci_dev *pdev = to_pci_dev(drive->hwif->dev); 147 147 ide_drive_t *pair = ide_get_pair_dev(drive); 148 148 int cshift = (drive->dn & 1) ? IDE_CAST_D1_SHIFT : IDE_CAST_D0_SHIFT; 149 + unsigned long timings = (unsigned long)ide_get_drivedata(drive); 149 150 u32 cast; 150 151 u8 cmd_pio = pio; 151 152 152 153 if (pair) 153 154 cmd_pio = min(pio, ide_get_best_pio_mode(pair, 255, 4)); 154 155 155 - drive->drive_data &= (IDE_DRV_MASK << 8); 156 - drive->drive_data |= drv_timings[pio]; 156 + timings &= (IDE_DRV_MASK << 8); 157 + timings |= drv_timings[pio]; 158 + ide_set_drivedata(drive, (void *)timings); 157 159 158 160 cs5536_program_dtc(drive, drv_timings[pio]); 159 161 ··· 188 186 189 187 struct pci_dev *pdev = to_pci_dev(drive->hwif->dev); 190 188 int dshift = (drive->dn & 1) ? IDE_D1_SHIFT : IDE_D0_SHIFT; 189 + unsigned long timings = (unsigned long)ide_get_drivedata(drive); 191 190 u32 etc; 192 191 193 192 cs5536_read(pdev, ETC, &etc); ··· 198 195 etc |= udma_timings[mode - XFER_UDMA_0] << dshift; 199 196 } else { /* MWDMA */ 200 197 etc &= ~(IDE_ETC_UDMA_MASK << dshift); 201 - drive->drive_data &= IDE_DRV_MASK; 202 - drive->drive_data |= mwdma_timings[mode - XFER_MW_DMA_0] << 8; 198 + timings &= IDE_DRV_MASK; 199 + timings |= mwdma_timings[mode - XFER_MW_DMA_0] << 8; 200 + ide_set_drivedata(drive, (void *)timings); 203 201 } 204 202 205 203 cs5536_write(pdev, ETC, etc); ··· 208 204 209 205 static void cs5536_dma_start(ide_drive_t *drive) 210 206 { 207 + unsigned long timings = (unsigned long)ide_get_drivedata(drive); 208 + 211 209 if (drive->current_speed < XFER_UDMA_0 && 212 - (drive->drive_data >> 8) != (drive->drive_data & IDE_DRV_MASK)) 213 - cs5536_program_dtc(drive, drive->drive_data >> 8); 210 + (timings >> 8) != (timings & IDE_DRV_MASK)) 211 + cs5536_program_dtc(drive, timings >> 8); 214 212 215 213 ide_dma_start(drive); 216 214 } ··· 220 214 static int cs5536_dma_end(ide_drive_t *drive) 221 215 { 222 216 int ret = ide_dma_end(drive); 217 + unsigned long timings = (unsigned long)ide_get_drivedata(drive); 223 218 224 219 if (drive->current_speed < XFER_UDMA_0 && 225 - (drive->drive_data >> 8) != (drive->drive_data & IDE_DRV_MASK)) 226 - cs5536_program_dtc(drive, drive->drive_data & IDE_DRV_MASK); 220 + (timings >> 8) != (timings & IDE_DRV_MASK)) 221 + cs5536_program_dtc(drive, timings & IDE_DRV_MASK); 227 222 228 223 return ret; 229 224 }
+24 -9
drivers/ide/ht6560b.c
··· 44 44 * bit3 (0x08): "1" 3 cycle time, "0" 2 cycle time (?) 45 45 */ 46 46 #define HT_CONFIG_PORT 0x3e6 47 - #define HT_CONFIG(drivea) (u8)(((drivea)->drive_data & 0xff00) >> 8) 47 + 48 + static inline u8 HT_CONFIG(ide_drive_t *drive) 49 + { 50 + return ((unsigned long)ide_get_drivedata(drive) & 0xff00) >> 8; 51 + } 52 + 48 53 /* 49 54 * FIFO + PREFETCH (both a/b-model) 50 55 */ ··· 95 90 * Active Time for each drive. Smaller value gives higher speed. 96 91 * In case of failures you should probably fall back to a higher value. 97 92 */ 98 - #define HT_TIMING(drivea) (u8)((drivea)->drive_data & 0x00ff) 93 + static inline u8 HT_TIMING(ide_drive_t *drive) 94 + { 95 + return (unsigned long)ide_get_drivedata(drive) & 0x00ff; 96 + } 97 + 99 98 #define HT_TIMING_DEFAULT 0xff 100 99 101 100 /* ··· 251 242 */ 252 243 static void ht_set_prefetch(ide_drive_t *drive, u8 state) 253 244 { 254 - unsigned long flags; 245 + unsigned long flags, config; 255 246 int t = HT_PREFETCH_MODE << 8; 256 247 257 248 spin_lock_irqsave(&ht6560b_lock, flags); 249 + 250 + config = (unsigned long)ide_get_drivedata(drive); 258 251 259 252 /* 260 253 * Prefetch mode and unmask irq seems to conflict 261 254 */ 262 255 if (state) { 263 - drive->drive_data |= t; /* enable prefetch mode */ 256 + config |= t; /* enable prefetch mode */ 264 257 drive->dev_flags |= IDE_DFLAG_NO_UNMASK; 265 258 drive->dev_flags &= ~IDE_DFLAG_UNMASK; 266 259 } else { 267 - drive->drive_data &= ~t; /* disable prefetch mode */ 260 + config &= ~t; /* disable prefetch mode */ 268 261 drive->dev_flags &= ~IDE_DFLAG_NO_UNMASK; 269 262 } 263 + 264 + ide_set_drivedata(drive, (void *)config); 270 265 271 266 spin_unlock_irqrestore(&ht6560b_lock, flags); 272 267 ··· 281 268 282 269 static void ht6560b_set_pio_mode(ide_drive_t *drive, const u8 pio) 283 270 { 284 - unsigned long flags; 271 + unsigned long flags, config; 285 272 u8 timing; 286 273 287 274 switch (pio) { ··· 294 281 timing = ht_pio2timings(drive, pio); 295 282 296 283 spin_lock_irqsave(&ht6560b_lock, flags); 297 - drive->drive_data &= 0xff00; 298 - drive->drive_data |= timing; 284 + config = (unsigned long)ide_get_drivedata(drive); 285 + config &= 0xff00; 286 + config |= timing; 287 + ide_set_drivedata(drive, (void *)config); 299 288 spin_unlock_irqrestore(&ht6560b_lock, flags); 300 289 301 290 #ifdef DEBUG ··· 314 299 if (hwif->channel) 315 300 t |= (HT_SECONDARY_IF << 8); 316 301 317 - drive->drive_data = t; 302 + ide_set_drivedata(drive, (void *)t); 318 303 } 319 304 320 305 static int probe_ht6560b;
+6 -4
drivers/ide/icside.c
··· 187 187 */ 188 188 static void icside_set_dma_mode(ide_drive_t *drive, const u8 xfer_mode) 189 189 { 190 - int cycle_time, use_dma_info = 0; 190 + unsigned long cycle_time; 191 + int use_dma_info = 0; 191 192 192 193 switch (xfer_mode) { 193 194 case XFER_MW_DMA_2: ··· 219 218 if (use_dma_info && drive->id[ATA_ID_EIDE_DMA_TIME] > cycle_time) 220 219 cycle_time = drive->id[ATA_ID_EIDE_DMA_TIME]; 221 220 222 - drive->drive_data = cycle_time; 221 + ide_set_drivedata(drive, (void *)cycle_time); 223 222 224 223 printk("%s: %s selected (peak %dMB/s)\n", drive->name, 225 - ide_xfer_verbose(xfer_mode), 2000 / drive->drive_data); 224 + ide_xfer_verbose(xfer_mode), 225 + 2000 / (unsigned long)ide_get_drivedata(drive)); 226 226 } 227 227 228 228 static const struct ide_port_ops icside_v6_port_ops = { ··· 279 277 /* 280 278 * Select the correct timing for this drive. 281 279 */ 282 - set_dma_speed(ec->dma, drive->drive_data); 280 + set_dma_speed(ec->dma, (unsigned long)ide_get_drivedata(drive)); 283 281 284 282 /* 285 283 * Tell the DMA engine about the SG table and
+5 -3
drivers/ide/opti621.c
··· 138 138 ide_hwif_t *hwif = drive->hwif; 139 139 ide_drive_t *pair = ide_get_pair_dev(drive); 140 140 unsigned long flags; 141 + unsigned long mode = XFER_PIO_0 + pio, pair_mode; 141 142 u8 tim, misc, addr_pio = pio, clk; 142 143 143 144 /* DRDY is default 2 (by OPTi Databook) */ ··· 151 150 { 0x48, 0x34, 0x21, 0x10, 0x10 } /* 25 MHz */ 152 151 }; 153 152 154 - drive->drive_data = XFER_PIO_0 + pio; 153 + ide_set_drivedata(drive, (void *)mode); 155 154 156 155 if (pair) { 157 - if (pair->drive_data && pair->drive_data < drive->drive_data) 158 - addr_pio = pair->drive_data - XFER_PIO_0; 156 + pair_mode = (unsigned long)ide_get_drivedata(pair); 157 + if (pair_mode && pair_mode < mode) 158 + addr_pio = pair_mode - XFER_PIO_0; 159 159 } 160 160 161 161 spin_lock_irqsave(&opti621_lock, flags);
+7 -4
drivers/ide/qd65xx.c
··· 180 180 181 181 static void qd_set_timing (ide_drive_t *drive, u8 timing) 182 182 { 183 - drive->drive_data &= 0xff00; 184 - drive->drive_data |= timing; 183 + unsigned long data = (unsigned long)ide_get_drivedata(drive); 184 + 185 + data &= 0xff00; 186 + data |= timing; 187 + ide_set_drivedata(drive, (void *)data); 185 188 186 189 printk(KERN_DEBUG "%s: %#x\n", drive->name, timing); 187 190 } ··· 295 292 u8 base = (hwif->config_data & 0xff00) >> 8; 296 293 u8 config = QD_CONFIG(hwif); 297 294 298 - drive->drive_data = QD6500_DEF_DATA; 295 + ide_set_drivedata(drive, (void *)QD6500_DEF_DATA); 299 296 } 300 297 301 298 static void __init qd6580_init_dev(ide_drive_t *drive) ··· 311 308 } else 312 309 t2 = t1 = hwif->channel ? QD6580_DEF_DATA2 : QD6580_DEF_DATA; 313 310 314 - drive->drive_data = (drive->dn & 1) ? t2 : t1; 311 + ide_set_drivedata(drive, (void *)((drive->dn & 1) ? t2 : t1)); 315 312 } 316 313 317 314 static const struct ide_tp_ops qd65xx_tp_ops = {
+9 -2
drivers/ide/qd65xx.h
··· 31 31 32 32 #define QD_CONFIG(hwif) ((hwif)->config_data & 0x00ff) 33 33 34 - #define QD_TIMING(drive) (u8)(((drive)->drive_data) & 0x00ff) 35 - #define QD_TIMREG(drive) (u8)((((drive)->drive_data) & 0xff00) >> 8) 34 + static inline u8 QD_TIMING(ide_drive_t *drive) 35 + { 36 + return (unsigned long)ide_get_drivedata(drive) & 0x00ff; 37 + } 38 + 39 + static inline u8 QD_TIMREG(ide_drive_t *drive) 40 + { 41 + return ((unsigned long)ide_get_drivedata(drive) & 0xff00) >> 8; 42 + } 36 43 37 44 #define QD6500_DEF_DATA ((QD_TIM1_PORT<<8) | (QD_ID3 ? 0x0c : 0x08)) 38 45 #define QD6580_DEF_DATA ((QD_TIM1_PORT<<8) | (QD_ID3 ? 0x0a : 0x00))
+12 -6
drivers/ide/sl82c105.c
··· 73 73 static void sl82c105_set_pio_mode(ide_drive_t *drive, const u8 pio) 74 74 { 75 75 struct pci_dev *dev = to_pci_dev(drive->hwif->dev); 76 + unsigned long timings = (unsigned long)ide_get_drivedata(drive); 76 77 int reg = 0x44 + drive->dn * 4; 77 78 u16 drv_ctrl; 78 79 ··· 83 82 * Store the PIO timings so that we can restore them 84 83 * in case DMA will be turned off... 85 84 */ 86 - drive->drive_data &= 0xffff0000; 87 - drive->drive_data |= drv_ctrl; 85 + timings &= 0xffff0000; 86 + timings |= drv_ctrl; 87 + ide_set_drivedata(drive, (void *)timings); 88 88 89 89 pci_write_config_word(dev, reg, drv_ctrl); 90 90 pci_read_config_word (dev, reg, &drv_ctrl); ··· 101 99 static void sl82c105_set_dma_mode(ide_drive_t *drive, const u8 speed) 102 100 { 103 101 static u16 mwdma_timings[] = {0x0707, 0x0201, 0x0200}; 102 + unsigned long timings = (unsigned long)ide_get_drivedata(drive); 104 103 u16 drv_ctrl; 105 104 106 105 DBG(("sl82c105_tune_chipset(drive:%s, speed:%s)\n", ··· 113 110 * Store the DMA timings so that we can actually program 114 111 * them when DMA will be turned on... 115 112 */ 116 - drive->drive_data &= 0x0000ffff; 117 - drive->drive_data |= (unsigned long)drv_ctrl << 16; 113 + timings &= 0x0000ffff; 114 + timings |= (unsigned long)drv_ctrl << 16; 115 + ide_set_drivedata(drive, (void *)timings); 118 116 } 119 117 120 118 static int sl82c105_test_irq(ide_hwif_t *hwif) ··· 198 194 199 195 DBG(("%s(drive:%s)\n", __func__, drive->name)); 200 196 201 - pci_write_config_word(dev, reg, drive->drive_data >> 16); 197 + pci_write_config_word(dev, reg, 198 + (unsigned long)ide_get_drivedata(drive) >> 16); 202 199 203 200 sl82c105_reset_host(dev); 204 201 ide_dma_start(drive); ··· 224 219 225 220 ret = ide_dma_end(drive); 226 221 227 - pci_write_config_word(dev, reg, drive->drive_data); 222 + pci_write_config_word(dev, reg, 223 + (unsigned long)ide_get_drivedata(drive)); 228 224 229 225 return ret; 230 226 }
+11 -1
include/linux/ide.h
··· 532 532 533 533 unsigned int bios_cyl; /* BIOS/fdisk/LILO number of cyls */ 534 534 unsigned int cyl; /* "real" number of cyls */ 535 - unsigned int drive_data; /* used by set_pio_mode/dev_select() */ 535 + void *drive_data; /* used by set_pio_mode/dev_select() */ 536 536 unsigned int failures; /* current failure count */ 537 537 unsigned int max_failures; /* maximum allowed failure count */ 538 538 u64 probed_capacity;/* initial/native media capacity */ ··· 1548 1548 ide_drive_t *peer = drive->hwif->devices[(drive->dn ^ 1) & 1]; 1549 1549 1550 1550 return (peer->dev_flags & IDE_DFLAG_PRESENT) ? peer : NULL; 1551 + } 1552 + 1553 + static inline void *ide_get_drivedata(ide_drive_t *drive) 1554 + { 1555 + return drive->drive_data; 1556 + } 1557 + 1558 + static inline void ide_set_drivedata(ide_drive_t *drive, void *data) 1559 + { 1560 + drive->drive_data = data; 1551 1561 } 1552 1562 1553 1563 #define ide_port_for_each_dev(i, dev, port) \