Skip to contentSkip to conversation

fddi: Fixup potential uninitialized bars

PATCH NAK Hannes Reinecke 2 participants 2 messages Jan 26, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fddi: Fixup potential uninitialized bars

dfx_get_bars() allocates the various bars, depending on the bus type. But as the function itself returns void and there is no default selection there is a risk of the function returning without allocating any bars.
This patch moves the entries around so that PCI is assumed to the the default bus, and adds a WARN_ON check if that should no be the case.
And I've made some minor code reshuffles to keep checkpatch happy.

---
 drivers/net/fddi/defxx.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)
drivers/net/fddi/defxx.c +16 -13
index 7f975a2..5fcaf03 100644
@@ -434,19 +434,10 @@ static void dfx_port_read_long(DFX_board_t *bp, int offset, u32 *data)
 static void dfx_get_bars(struct device *bdev,
 			 resource_size_t *bar_start, resource_size_t *bar_len)
 {
-	int dfx_bus_pci = dev_is_pci(bdev);
 	int dfx_bus_eisa = DFX_BUS_EISA(bdev);
 	int dfx_bus_tc = DFX_BUS_TC(bdev);
 	int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
 
-	if (dfx_bus_pci) {
-		int num = dfx_use_mmio ? 0 : 1;
-
-		bar_start[0] = pci_resource_start(to_pci_dev(bdev), num);
-		bar_len[0] = pci_resource_len(to_pci_dev(bdev), num);
-		bar_start[2] = bar_start[1] = 0;
-		bar_len[2] = bar_len[1] = 0;
-	}
 	if (dfx_bus_eisa) {
 		unsigned long base_addr = to_eisa_device(bdev)->base_addr;
 		resource_size_t bar_lo;
@@ -476,13 +467,25 @@ static void dfx_get_bars(struct device *bdev,
 		bar_len[1] = PI_ESIC_K_BURST_HOLDOFF_LEN;
 		bar_start[2] = base_addr + PI_ESIC_K_ESIC_CSR;
 		bar_len[2] = PI_ESIC_K_ESIC_CSR_LEN;
-	}
-	if (dfx_bus_tc) {
+	} else if (dfx_bus_tc) {
 		bar_start[0] = to_tc_dev(bdev)->resource.start +
 			       PI_TC_K_CSR_OFFSET;
 		bar_len[0] = PI_TC_K_CSR_LEN;
-		bar_start[2] = bar_start[1] = 0;
-		bar_len[2] = bar_len[1] = 0;
+		bar_start[1] = 0;
+		bar_len[1] = 0;
+		bar_start[2] = 0;
+		bar_len[2] = 0;
+	} else {
+		/* Assume PCI */
+		int num = dfx_use_mmio ? 0 : 1;
+
+		WARN_ON(!dev_is_pci(bdev));
+		bar_start[0] = pci_resource_start(to_pci_dev(bdev), num);
+		bar_len[0] = pci_resource_len(to_pci_dev(bdev), num);
+		bar_start[1] = 0;
+		bar_len[1] = 0;
+		bar_start[2] = 0;
+		bar_len[2] = 0;
 	}
 }
 
Signature · 1 line
1.8.5.6
#1 lore raw
Quoted 10 lines · Hannes Reinecke

dfx_get_bars() allocates the various bars, depending on the bus type. But as the function itself returns void and there is no default selection there is a risk of the function returning without allocating any bars.
This patch moves the entries around so that PCI is assumed to the the default bus, and adds a WARN_ON check if that should no be the case.
And I've made some minor code reshuffles to keep checkpatch happy.

Quoted 4 lines
---
 drivers/net/fddi/defxx.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

NAK, this has been fixed already with a much simpler change, commit
62f2aaabcf41 ("defxx: fix build warning"). Exactly one of dfx_bus_pci', dfx_bus_eisa' or dfx_bus_tc' will always be true or dfx_register' will not have been called in the first place, so it's not even worth a BUG_ON IMHO.

Thanks for looking into this problem though, always welcome!

Maciej