* [PATCH] Fix pointer arithmetic in hpt3xx driver code
@ 2008-09-05 17:48 Masoud Sharbiani
2008-09-05 18:04 ` Sergei Shtylyov
0 siblings, 1 reply; 2+ messages in thread
From: Masoud Sharbiani @ 2008-09-05 17:48 UTC (permalink / raw)
To: sshtylyov, bzolnier, akpm; +Cc: linux-kernel
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.
Signed-Off-By: Masoud Sharbiani <masouds@google.com>
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index eb107ee..f41f3fd 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)
return 0;
}
+static struct hpt_info *hpt3xx_get_info(void *host_priv, struct device *hwif_dev, struct device *host_dev)
+{
+ struct hpt_info *info = (struct hpt_info *)host_priv;
+ if (hwif_dev == host_dev)
+ info++;
+ return 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...
@@ -623,7 +631,7 @@ 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(host->host_priv, hwif->dev, host->dev[1]);
u8 mask = hwif->ultra_mask;
switch (info->chip_type) {
@@ -664,7 +672,7 @@ 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(host->host_priv, hwif->dev, host->dev[1]);
switch (info->chip_type) {
case HPT372 :
@@ -701,7 +709,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(host->host_priv, hwif->dev, host->dev[1]);
struct hpt_timings *t = info->timings;
u8 itr_addr = 0x40 + (drive->dn * 4);
u32 old_itr = 0;
@@ -745,7 +753,7 @@ 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 hpt_info *info = hpt3xx_get_info(host->host_priv, hwif->dev, host->dev[1]);
if (drive->quirk_list) {
if (info->chip_type >= HPT370) {
@@ -974,7 +982,7 @@ static 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(host->host_priv, &dev->dev, host->dev[1]);
const char *name = DRV_NAME;
u8 pci_clk, dpll_clk = 0; /* PCI and DPLL clock in MHz */
u8 chip_type;
@@ -1218,7 +1226,7 @@ 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(host->host_priv, hwif->dev, host->dev[1]);
u8 chip_type = info->chip_type;
u8 scr1 = 0, ata66 = hwif->channel ? 0x01 : 0x02;
@@ -1263,7 +1271,7 @@ 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(host->host_priv, hwif->dev, host->dev[1]);
int serialize = HPT_SERIALIZE_IO;
u8 chip_type = info->chip_type;
u8 new_mcr, old_mcr = 0;
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] Fix pointer arithmetic in hpt3xx driver code
2008-09-05 17:48 [PATCH] Fix pointer arithmetic in hpt3xx driver code Masoud Sharbiani
@ 2008-09-05 18:04 ` Sergei Shtylyov
0 siblings, 0 replies; 2+ messages in thread
From: Sergei Shtylyov @ 2008-09-05 18:04 UTC (permalink / raw)
To: Masoud Sharbiani; +Cc: bzolnier, akpm, linux-kernel
Masoud Sharbiani wrote:
> 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.
> Signed-Off-By: Masoud Sharbiani <masouds@google.com>
> diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
> index eb107ee..f41f3fd 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)
> return 0;
> }
> +static struct hpt_info *hpt3xx_get_info(void *host_priv, struct device *hwif_dev, struct device *host_dev)
Ugh, that's oversimplified and doesn't save much...
I rather meant the following prototype:
static struct hpt_info *hpt3xx_get_info(struct pci_dev *dev)
In case it'll be too complex for you, I'll do it myself later.
> +{
> + struct hpt_info *info = (struct hpt_info *)host_priv;
Newline needed after the declaration block.
> + if (hwif_dev == host_dev)
return info + 1;
else
return info;
or
return hwif_dev == host_dev ? info + 1 : info;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-09-05 18:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-05 17:48 [PATCH] Fix pointer arithmetic in hpt3xx driver code Masoud Sharbiani
2008-09-05 18:04 ` Sergei Shtylyov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox