From patchwork Tue Jan 26 07:27:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 573098 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 7E1031402A8 for ; Tue, 26 Jan 2016 18:28:29 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753561AbcAZH1g (ORCPT ); Tue, 26 Jan 2016 02:27:36 -0500 Received: from mx2.suse.de ([195.135.220.15]:50622 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752015AbcAZH1f (ORCPT ); Tue, 26 Jan 2016 02:27:35 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 33417ABB5; Tue, 26 Jan 2016 07:27:32 +0000 (UTC) From: Hannes Reinecke To: "Maciej W. Rozycki" Cc: netdev@vger.kernel.org, Michal Kubecek , Hannes Reinecke , Hannes Reinecke Subject: [PATCH] fddi: Fixup potential uninitialized bars Date: Tue, 26 Jan 2016 08:27:31 +0100 Message-Id: <1453793251-101247-1-git-send-email-hare@suse.de> X-Mailer: git-send-email 1.8.5.6 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- 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; } }