Fix pointer arithmetic in hpt3xx driver code (2nd attempt)
PATCH 1/1 Fix pointer arithmetic in hpt3xx driver code (2nd attempt)
Hi there,
git commit 74811f355f4f69a187fa74892dcf2a684b84ce99 causes crash at module load (or boot) time on my machine with a hpt374 controller. Sergei says this is due to the pointer arithmatic. This patch fixes that and makes my machine boot again.
cheers,
Masoud
drivers/ide/pci/hpt366.c +16 -17
@@ -613,6 +613,14 @@ static int check_in_drive_list(ide_drive_t *drive, const char **list)return 0 ; } +static struct hpt_info *hpt3xx_get_info (struct device *dev) +{ +struct pci_dev *pci_dev =to_pci_dev (dev); +struct ide_host *host =pci_get_drvdata (pci_dev); +struct hpt_info *info = (struct hpt_info *)host->host_priv; +return dev == host->dev[1 ] ? info +1 : info; +} +/* * The Marvell bridge chips used on the HighPoint SATA cards do not seem * 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)static u8 hpt3xx_udma_filter (ide_drive_t *drive) {ide_hwif_t *hwif =HWIF (drive); -struct pci_dev *dev =to_pci_dev (hwif->dev); -struct ide_host *host =pci_get_drvdata (dev); -struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1 ]); +struct hpt_info *info =hpt3xx_get_info (hwif->dev);u8 mask = hwif->ultra_mask;switch (info->chip_type) {
@@ -662,9 +668,7 @@ static u8 hpt3xx_udma_filter(ide_drive_t *drive)static u8 hpt3xx_mdma_filter (ide_drive_t *drive) {ide_hwif_t *hwif =HWIF (drive); -struct pci_dev *dev =to_pci_dev (hwif->dev); -struct ide_host *host =pci_get_drvdata (dev); -struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1 ]); +struct hpt_info *info =hpt3xx_get_info (hwif->dev);switch (info->chip_type) {case HPT372 :
@@ -700,8 +704,7 @@ static void hpt3xx_set_mode(ide_drive_t *drive, const u8 speed) {ide_hwif_t *hwif = drive->hwif;struct pci_dev *dev =to_pci_dev (hwif->dev); -struct ide_host *host =pci_get_drvdata (dev); -struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1 ]); +struct hpt_info *info =hpt3xx_get_info (hwif->dev);struct hpt_timings *t = info->timings;u8 itr_addr =0x40 + (drive->dn *4 );u32 old_itr =0 ;
@@ -743,9 +746,8 @@ static void hpt3xx_quirkproc(ide_drive_t *drive)static void hpt3xx_maskproc (ide_drive_t *drive,int mask) {ide_hwif_t *hwif =HWIF (drive); -struct pci_dev *dev =to_pci_dev (hwif->dev); -struct ide_host *host =pci_get_drvdata (dev); -struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1 ]); +struct pci_dev *dev =to_pci_dev (hwif->dev); +struct hpt_info *info =hpt3xx_get_info (hwif->dev);if (drive->quirk_list) {if (info->chip_type >=HPT370 ) {
@@ -973,8 +975,7 @@ static int __devinit hpt37x_calibrate_dpll(struct pci_dev *dev, u16 f_low, u16 fstatic unsigned int __devinit init_chipset_hpt366 (struct pci_dev *dev) {unsigned long io_base =pci_resource_start (dev,4 ); -struct ide_host *host =pci_get_drvdata (dev); -struct hpt_info *info = host->host_priv + (&dev->dev == host->dev[1 ]); +struct hpt_info *info =hpt3xx_get_info (&dev->dev);const char *name =DRV_NAME ;u8 pci_clk, dpll_clk =0 ;/* PCI and DPLL clock in MHz */ u8 chip_type;
@@ -1217,8 +1218,7 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev)static u8 hpt3xx_cable_detect (ide_hwif_t *hwif) {struct pci_dev *dev =to_pci_dev (hwif->dev); -struct ide_host *host =pci_get_drvdata (dev); -struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1 ]); +struct hpt_info *info =hpt3xx_get_info (hwif->dev);u8 chip_type = info->chip_type;u8 scr1 =0 , ata66 = hwif->channel ?0x01 :0x02 ;
@@ -1262,8 +1262,7 @@ static u8 hpt3xx_cable_detect(ide_hwif_t *hwif)static void __devinit init_hwif_hpt366 (ide_hwif_t *hwif) {struct pci_dev *dev =to_pci_dev (hwif->dev); -struct ide_host *host =pci_get_drvdata (dev); -struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1 ]); +struct hpt_info *info =hpt3xx_get_info (hwif->dev);int serialize =HPT_SERIALIZE_IO ;u8 chip_type = info->chip_type;u8 new_mcr, old_mcr =0 ;
Hello.
Quoted 2 lines · Masoud Sharbiani
Hi there,
Er... I think the maintainer will have to remove this... :-)
Quoted 6 lines
git commit
74811f355f4f69a187fa74892dcf2a684b84ce99causes crash at module load (or boot) time on my machine with a hpt374 controller. Sergei says this is due to the pointer arithmatic. This patch fixes that and makes my machine boot again.
cheers, Masoud
And "cheers" too...
Quoted 2 lines
Signed-off-by Masoud Sharbiani <[email protected]>
drivers/ide/pci/hpt366.c static int check_in_drive_list(ide_drive_t *drive, const char **list) · line 617
Quoted 10 lines
drivers/ide/pci/hpt366.c +1
-0@@ -613,6 +613,14 @@ static int check_in_drive_list(ide_drive_t *drive, const char **list)return 0 ; } +static struct hpt_info *hpt3xx_get_info (struct device *dev)
That also will do. Though 'struct pci_dev' seems preferrable as it's
always pre-calculated by the callers and otherwise needed in them in 4 cases out of 7.
drivers/ide/pci/hpt366.c static int check_in_drive_list(ide_drive_t *drive, const char **list)
Quoted 4 lines
drivers/ide/pci/hpt366.c +3
-0+{ +struct pci_dev *pci_dev =to_pci_dev (dev); +struct ide_host *host =pci_get_drvdata (pci_dev);
Could be just:
struct ide_host *host = pci_get_drvdata(to_pci_dev(dev));
drivers/ide/pci/hpt366.c static int check_in_drive_list(ide_drive_t *drive, const char **list) · line 623
Quoted 2 lines
drivers/ide/pci/hpt366.c +1
-0+struct hpt_info *info = (struct hpt_info *)host->host_priv;
No epmty line after declaration block again. :-)
Quoted 72 lines
drivers/ide/pci/hpt366.c +3
-0+return dev == host->dev[1 ] ? info +1 : info; +} +/*
* The Marvell bridge chips used on the HighPoint SATA cards do not seem
* to support the UltraDMA modes 1, 2, and 3 as well as any MWDMA modes...drivers/ide/pci/hpt366.c +7
-15@@ -621,9 +629,7 @@ static int check_in_drive_list(ide_drive_t *drive, const char **list)static u8 hpt3xx_udma_filter (ide_drive_t *drive) {ide_hwif_t *hwif =HWIF (drive); -struct pci_dev *dev =to_pci_dev (hwif->dev); -struct ide_host *host =pci_get_drvdata (dev); -struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1 ]); +struct hpt_info *info =hpt3xx_get_info (hwif->dev);u8 mask = hwif->ultra_mask;switch (info->chip_type) {@@ -662,9 +668,7 @@ static u8 hpt3xx_udma_filter(ide_drive_t *drive)static u8 hpt3xx_mdma_filter (ide_drive_t *drive) {ide_hwif_t *hwif =HWIF (drive); -struct pci_dev *dev =to_pci_dev (hwif->dev); -struct ide_host *host =pci_get_drvdata (dev); -struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1 ]); +struct hpt_info *info =hpt3xx_get_info (hwif->dev);switch (info->chip_type) {case HPT372 :@@ -700,8 +704,7 @@ static void hpt3xx_set_mode(ide_drive_t *drive, const u8 speed) {ide_hwif_t *hwif = drive->hwif;struct pci_dev *dev =to_pci_dev (hwif->dev); -struct ide_host *host =pci_get_drvdata (dev); -struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1 ]); +struct hpt_info *info =hpt3xx_get_info (hwif->dev);struct hpt_timings *t = info->timings;u8 itr_addr =0x40 + (drive->dn *4 );u32 old_itr =0 ;@@ -743,9 +746,8 @@ static void hpt3xx_quirkproc(ide_drive_t *drive)static void hpt3xx_maskproc (ide_drive_t *drive,int mask) {ide_hwif_t *hwif =HWIF (drive); -struct pci_dev *dev =to_pci_dev (hwif->dev); -struct ide_host *host =pci_get_drvdata (dev); -struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1 ]); +struct pci_dev *dev =to_pci_dev (hwif->dev); +struct hpt_info *info =hpt3xx_get_info (hwif->dev);if (drive->quirk_list) {if (info->chip_type >=HPT370 ) {@@ -973,8 +975,7 @@ static int __devinit hpt37x_calibrate_dpll(struct pci_dev *dev, u16 f_low, u16 fstatic unsigned int __devinit init_chipset_hpt366 (struct pci_dev *dev) {unsigned long io_base =pci_resource_start (dev,4 ); -struct ide_host *host =pci_get_drvdata (dev); -struct hpt_info *info = host->host_priv + (&dev->dev == host->dev[1 ]); +struct hpt_info *info =hpt3xx_get_info (&dev->dev);const char *name =DRV_NAME ;u8 pci_clk, dpll_clk =0 ;/* PCI and DPLL clock in MHz */ u8 chip_type;@@ -1217,8 +1218,7 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev)static u8 hpt3xx_cable_detect (ide_hwif_t *hwif) {struct pci_dev *dev =to_pci_dev (hwif->dev); -struct ide_host *host =pci_get_drvdata (dev); -struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1 ]); +struct hpt_info *info =hpt3xx_get_info (hwif->dev);u8 chip_type = info->chip_type;u8 scr1 =0 , ata66 = hwif->channel ?0x01 :0x02 ;
drivers/ide/pci/hpt366.c static u8 hpt3xx_cable_detect(ide_hwif_t *hwif) · line 1268
Quoted 9 lines
drivers/ide/pci/hpt366.c +1
-2@@ -1262,8 +1262,7 @@ static u8 hpt3xx_cable_detect(ide_hwif_t *hwif)static void __devinit init_hwif_hpt366 (ide_hwif_t *hwif) {struct pci_dev *dev =to_pci_dev (hwif->dev); -struct ide_host *host =pci_get_drvdata (dev); -struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1 ]); +struct hpt_info *info =hpt3xx_get_info (hwif->dev);int serialize =HPT_SERIALIZE_IO ;u8 chip_type = info->chip_type;u8 new_mcr, old_mcr =0 ;
MBR, Sergei