Skip to contentSkip to conversation

hpt366 ptr use before NULL check.

PATCH Dave Jones 2 participants 4 messages Sep 3, 2004

lore
Share & tools
lore

Dave Jones

author
#0 lore raw

Another picked up with the coverity checker.

drivers/ide/pci/hpt366.c renamed from drivers/ide/pci/hpt366.c~ +7 -3
@@ -773,13 +773,17 @@
 static int hpt3xx_tristate (ide_drive_t * drive, int state)
 {
 	ide_hwif_t *hwif	= HWIF(drive);
-	struct pci_dev *dev	= hwif->pci_dev;
-	u8 reg59h = 0, reset	= (hwif->channel) ? 0x80 : 0x40;
-	u8 regXXh = 0, state_reg= (hwif->channel) ? 0x57 : 0x53;
+	struct pci_dev *dev;
+	u8 reg59h = 0, reset;
+	u8 regXXh = 0, state_reg;
 
 	if (!hwif)
 		return -EINVAL;
 
+	dev = hwif->pci_dev;
+	reset = (hwif->channel) ? 0x80 : 0x40;
+	state_reg = (hwif->channel) ? 0x57 : 0x53;
+
 //	hwif->bus_state = state;
 
 	pci_read_config_byte(dev, 0x59, &reg59h);
author
#1 lore raw
Quoted 17 lines · Dave Jones

Another picked up with the coverity checker.

drivers/ide/pci/hpt366.c renamed from drivers/ide/pci/hpt366.c~ +3 -3
@@ -773,13 +773,17 @@
 static int hpt3xx_tristate (ide_drive_t * drive, int state)
 {
 	ide_hwif_t *hwif	= HWIF(drive);
-	struct pci_dev *dev	= hwif->pci_dev;
-	u8 reg59h = 0, reset	= (hwif->channel) ? 0x80 : 0x40;
-	u8 regXXh = 0, state_reg= (hwif->channel) ? 0x57 : 0x53;
+	struct pci_dev *dev;
+	u8 reg59h = 0, reset;
+	u8 regXXh = 0, state_reg;
 

drivers/ide/pci/hpt366.c line 789

Quoted 10 lines
drivers/ide/pci/hpt366.c renamed from drivers/ide/pci/hpt366.c~ +4 -0
 	if (!hwif)
 		return -EINVAL;
 
+	dev = hwif->pci_dev;
+	reset = (hwif->channel) ? 0x80 : 0x40;
+	state_reg = (hwif->channel) ? 0x57 : 0x53;
+
 //	hwif->bus_state = state;
 
 	pci_read_config_byte(dev, 0x59, &reg59h);

Oops, missed one.

Dave

drivers/ide/pci/hpt366.c renamed from drivers/ide/pci/hpt366.c~ +2 -1
@@ -813,13 +813,14 @@
 static int hpt370_busproc(ide_drive_t * drive, int state)
 {
 	ide_hwif_t *hwif	= HWIF(drive);
-	struct pci_dev *dev	= hwif->pci_dev;
+	struct pci_dev *dev;
 	u8 tristate = 0, resetmask = 0, bus_reg = 0;
 	u16 tri_reg;
 
 	if (!hwif)
 		return -EINVAL;
 
+	dev = hwif->pci_dev;
 	hwif->bus_state = state;
 
 	if (hwif->channel) { 
#2 lore raw

bogus, hwif can't be NULL
please remove checks instead

Quoted 52 lines · Dave Jones
Quoted 17 lines · Dave Jones

Another picked up with the coverity checker.

drivers/ide/pci/hpt366.c renamed from drivers/ide/pci/hpt366.c~ +3 -3
@@ -773,13 +773,17 @@
 static int hpt3xx_tristate (ide_drive_t * drive, int state)
 {
 	ide_hwif_t *hwif	= HWIF(drive);
-	struct pci_dev *dev	= hwif->pci_dev;
-	u8 reg59h = 0, reset	= (hwif->channel) ? 0x80 : 0x40;
-	u8 regXXh = 0, state_reg= (hwif->channel) ? 0x57 : 0x53;
+	struct pci_dev *dev;
+	u8 reg59h = 0, reset;
+	u8 regXXh = 0, state_reg;
 

drivers/ide/pci/hpt366.c line 789

Quoted 10 lines
drivers/ide/pci/hpt366.c renamed from drivers/ide/pci/hpt366.c~ +4 -0
 	if (!hwif)
 		return -EINVAL;
 
+	dev = hwif->pci_dev;
+	reset = (hwif->channel) ? 0x80 : 0x40;
+	state_reg = (hwif->channel) ? 0x57 : 0x53;
+
 //	hwif->bus_state = state;
 
 	pci_read_config_byte(dev, 0x59, &reg59h);

Oops, missed one.

Dave

drivers/ide/pci/hpt366.c renamed from drivers/ide/pci/hpt366.c~ +2 -1
@@ -813,13 +813,14 @@
 static int hpt370_busproc(ide_drive_t * drive, int state)
 {
 	ide_hwif_t *hwif	= HWIF(drive);
-	struct pci_dev *dev	= hwif->pci_dev;
+	struct pci_dev *dev;
 	u8 tristate = 0, resetmask = 0, bus_reg = 0;
 	u16 tri_reg;
 
 	if (!hwif)
 		return -EINVAL;
 
+	dev = hwif->pci_dev;
 	hwif->bus_state = state;
 
 	if (hwif->channel) { 
author
#3 lore raw
Quoted 3 lines · Bartlomiej Zolnierkiewicz

bogus, hwif can't be NULL
please remove checks instead

As you wish.

drivers/ide/pci/hpt366.c renamed from drivers/ide/pci/hpt366.c~ +0 -6
@@ -777,9 +777,6 @@
 	u8 reg59h = 0, reset	= (hwif->channel) ? 0x80 : 0x40;
 	u8 regXXh = 0, state_reg= (hwif->channel) ? 0x57 : 0x53;
 
-	if (!hwif)
-		return -EINVAL;
-
 //	hwif->bus_state = state;
 
 	pci_read_config_byte(dev, 0x59, &reg59h);
@@ -813,9 +810,6 @@
 	u8 tristate = 0, resetmask = 0, bus_reg = 0;
 	u16 tri_reg;
 
-	if (!hwif)
-		return -EINVAL;
-
 	hwif->bus_state = state;
 
 	if (hwif->channel) {