netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fddi: Fixup potential uninitialized bars
@ 2016-01-26  7:27 Hannes Reinecke
  2016-01-26  8:55 ` Maciej W. Rozycki
  0 siblings, 1 reply; 2+ messages in thread
From: Hannes Reinecke @ 2016-01-26  7:27 UTC (permalink / raw)
  To: Maciej W. Rozycki
  Cc: netdev, Michal Kubecek, Hannes Reinecke, 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.

Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 drivers/net/fddi/defxx.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/net/fddi/defxx.c b/drivers/net/fddi/defxx.c
index 7f975a2..5fcaf03 100644
--- a/drivers/net/fddi/defxx.c
+++ b/drivers/net/fddi/defxx.c
@@ -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;
 	}
 }
 
-- 
1.8.5.6

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-01-26  9:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-26  7:27 [PATCH] fddi: Fixup potential uninitialized bars Hannes Reinecke
2016-01-26  8:55 ` Maciej W. Rozycki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).