diff options
author | Masoud Sharbiani <masouds@google.com> | 2008-09-10 16:22:34 -0400 |
---|---|---|
committer | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-09-10 16:22:34 -0400 |
commit | 62ff2ecf7a4e69f7271b7f7a57aaee76ffe610f2 (patch) | |
tree | 253db0a828c4deef4add471fc9ddba047b1383d7 /drivers/ide/pci/hpt366.c | |
parent | adee14b2e1557d0a8559f29681732d05a89dfc35 (diff) |
ide: Fix pointer arithmetic in hpt3xx driver code (3rd try)
git commit 74811f355f4f69a187fa74892dcf2a684b84ce99 causes crash at
module load (or boot) time on my machine with a hpt374 controller.
The reason for this is that for initializing second controller which sets
(hwif->dev == host->dev[1]) to true (1), adds 1 to a void ptr, which
advances it by one byte instead of advancing it by sizeof(hpt_info) bytes.
Because of this, all initialization functions get corrupted data in info
variable which causes a crash at boot time.
This patch fixes that and makes my machine boot again.
The card itself is a HPT374 raid conroller: Here is the lspci -v output:
03:06.0 RAID bus controller: HighPoint Technologies, Inc. HPT374 (rev
07)
Subsystem: HighPoint Technologies, Inc. Unknown device 0001
Flags: bus master, 66MHz, medium devsel, latency 120, IRQ 28
I/O ports at 8000 [size=8]
I/O ports at 7800 [size=4]
I/O ports at 7400 [size=8]
I/O ports at 7000 [size=4]
I/O ports at 6800 [size=256]
Expansion ROM at fe8e0000 [disabled] [size=128K]
Capabilities: [60] Power Management version 2
03:06.1 RAID bus controller: HighPoint Technologies, Inc. HPT374 (rev
07)
Subsystem: HighPoint Technologies, Inc. Unknown device 0001
Flags: bus master, 66MHz, medium devsel, latency 120, IRQ 28
I/O ports at 9800 [size=8]
I/O ports at 9400 [size=4]
I/O ports at 9000 [size=8]
I/O ports at 8800 [size=4]
I/O ports at 8400 [size=256]
Capabilities: [60] Power Management version 2
Signed-off-by: Masoud Sharbiani <masouds@google.com>
Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
[bart: use dev_get_drvdata() per Sergei's suggestion]
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/pci/hpt366.c')
-rw-r--r-- | drivers/ide/pci/hpt366.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c index eb107eef0dbc..c37ab1743819 100644 --- a/drivers/ide/pci/hpt366.c +++ b/drivers/ide/pci/hpt366.c | |||
@@ -613,6 +613,14 @@ static int check_in_drive_list(ide_drive_t *drive, const char **list) | |||
613 | return 0; | 613 | return 0; |
614 | } | 614 | } |
615 | 615 | ||
616 | static struct hpt_info *hpt3xx_get_info(struct device *dev) | ||
617 | { | ||
618 | struct ide_host *host = dev_get_drvdata(dev); | ||
619 | struct hpt_info *info = (struct hpt_info *)host->host_priv; | ||
620 | |||
621 | return dev == host->dev[1] ? info + 1 : info; | ||
622 | } | ||
623 | |||
616 | /* | 624 | /* |
617 | * The Marvell bridge chips used on the HighPoint SATA cards do not seem | 625 | * The Marvell bridge chips used on the HighPoint SATA cards do not seem |
618 | * to support the UltraDMA modes 1, 2, and 3 as well as any MWDMA modes... | 626 | * to support the UltraDMA modes 1, 2, and 3 as well as any MWDMA modes... |
@@ -621,9 +629,7 @@ static int check_in_drive_list(ide_drive_t *drive, const char **list) | |||
621 | static u8 hpt3xx_udma_filter(ide_drive_t *drive) | 629 | static u8 hpt3xx_udma_filter(ide_drive_t *drive) |
622 | { | 630 | { |
623 | ide_hwif_t *hwif = HWIF(drive); | 631 | ide_hwif_t *hwif = HWIF(drive); |
624 | struct pci_dev *dev = to_pci_dev(hwif->dev); | 632 | struct hpt_info *info = hpt3xx_get_info(hwif->dev); |
625 | struct ide_host *host = pci_get_drvdata(dev); | ||
626 | struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]); | ||
627 | u8 mask = hwif->ultra_mask; | 633 | u8 mask = hwif->ultra_mask; |
628 | 634 | ||
629 | switch (info->chip_type) { | 635 | switch (info->chip_type) { |
@@ -662,9 +668,7 @@ static u8 hpt3xx_udma_filter(ide_drive_t *drive) | |||
662 | static u8 hpt3xx_mdma_filter(ide_drive_t *drive) | 668 | static u8 hpt3xx_mdma_filter(ide_drive_t *drive) |
663 | { | 669 | { |
664 | ide_hwif_t *hwif = HWIF(drive); | 670 | ide_hwif_t *hwif = HWIF(drive); |
665 | struct pci_dev *dev = to_pci_dev(hwif->dev); | 671 | struct hpt_info *info = hpt3xx_get_info(hwif->dev); |
666 | struct ide_host *host = pci_get_drvdata(dev); | ||
667 | struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]); | ||
668 | 672 | ||
669 | switch (info->chip_type) { | 673 | switch (info->chip_type) { |
670 | case HPT372 : | 674 | case HPT372 : |
@@ -700,8 +704,7 @@ static void hpt3xx_set_mode(ide_drive_t *drive, const u8 speed) | |||
700 | { | 704 | { |
701 | ide_hwif_t *hwif = drive->hwif; | 705 | ide_hwif_t *hwif = drive->hwif; |
702 | struct pci_dev *dev = to_pci_dev(hwif->dev); | 706 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
703 | struct ide_host *host = pci_get_drvdata(dev); | 707 | struct hpt_info *info = hpt3xx_get_info(hwif->dev); |
704 | struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]); | ||
705 | struct hpt_timings *t = info->timings; | 708 | struct hpt_timings *t = info->timings; |
706 | u8 itr_addr = 0x40 + (drive->dn * 4); | 709 | u8 itr_addr = 0x40 + (drive->dn * 4); |
707 | u32 old_itr = 0; | 710 | u32 old_itr = 0; |
@@ -744,8 +747,7 @@ static void hpt3xx_maskproc(ide_drive_t *drive, int mask) | |||
744 | { | 747 | { |
745 | ide_hwif_t *hwif = HWIF(drive); | 748 | ide_hwif_t *hwif = HWIF(drive); |
746 | struct pci_dev *dev = to_pci_dev(hwif->dev); | 749 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
747 | struct ide_host *host = pci_get_drvdata(dev); | 750 | struct hpt_info *info = hpt3xx_get_info(hwif->dev); |
748 | struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]); | ||
749 | 751 | ||
750 | if (drive->quirk_list) { | 752 | if (drive->quirk_list) { |
751 | if (info->chip_type >= HPT370) { | 753 | if (info->chip_type >= HPT370) { |
@@ -973,8 +975,7 @@ static int __devinit hpt37x_calibrate_dpll(struct pci_dev *dev, u16 f_low, u16 f | |||
973 | static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev) | 975 | static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev) |
974 | { | 976 | { |
975 | unsigned long io_base = pci_resource_start(dev, 4); | 977 | unsigned long io_base = pci_resource_start(dev, 4); |
976 | struct ide_host *host = pci_get_drvdata(dev); | 978 | struct hpt_info *info = hpt3xx_get_info(&dev->dev); |
977 | struct hpt_info *info = host->host_priv + (&dev->dev == host->dev[1]); | ||
978 | const char *name = DRV_NAME; | 979 | const char *name = DRV_NAME; |
979 | u8 pci_clk, dpll_clk = 0; /* PCI and DPLL clock in MHz */ | 980 | u8 pci_clk, dpll_clk = 0; /* PCI and DPLL clock in MHz */ |
980 | u8 chip_type; | 981 | u8 chip_type; |
@@ -1217,8 +1218,7 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev) | |||
1217 | static u8 hpt3xx_cable_detect(ide_hwif_t *hwif) | 1218 | static u8 hpt3xx_cable_detect(ide_hwif_t *hwif) |
1218 | { | 1219 | { |
1219 | struct pci_dev *dev = to_pci_dev(hwif->dev); | 1220 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
1220 | struct ide_host *host = pci_get_drvdata(dev); | 1221 | struct hpt_info *info = hpt3xx_get_info(hwif->dev); |
1221 | struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]); | ||
1222 | u8 chip_type = info->chip_type; | 1222 | u8 chip_type = info->chip_type; |
1223 | u8 scr1 = 0, ata66 = hwif->channel ? 0x01 : 0x02; | 1223 | u8 scr1 = 0, ata66 = hwif->channel ? 0x01 : 0x02; |
1224 | 1224 | ||
@@ -1262,8 +1262,7 @@ static u8 hpt3xx_cable_detect(ide_hwif_t *hwif) | |||
1262 | static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) | 1262 | static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) |
1263 | { | 1263 | { |
1264 | struct pci_dev *dev = to_pci_dev(hwif->dev); | 1264 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
1265 | struct ide_host *host = pci_get_drvdata(dev); | 1265 | struct hpt_info *info = hpt3xx_get_info(hwif->dev); |
1266 | struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]); | ||
1267 | int serialize = HPT_SERIALIZE_IO; | 1266 | int serialize = HPT_SERIALIZE_IO; |
1268 | u8 chip_type = info->chip_type; | 1267 | u8 chip_type = info->chip_type; |
1269 | u8 new_mcr, old_mcr = 0; | 1268 | u8 new_mcr, old_mcr = 0; |