diff mbox

fddi: Fixup potential uninitialized bars

Message ID 1453793251-101247-1-git-send-email-hare@suse.de
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Hannes Reinecke Jan. 26, 2016, 7:27 a.m. UTC
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(-)

Comments

Maciej W. Rozycki Jan. 26, 2016, 8:55 a.m. UTC | #1
On Tue, 26 Jan 2016, Hannes Reinecke wrote:

> 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(-)

 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
diff mbox

Patch

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;
 	}
 }