From patchwork Tue Aug 10 07:47:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 61341 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 71F02B7106 for ; Tue, 10 Aug 2010 17:48:54 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754818Ab0HJHsm (ORCPT ); Tue, 10 Aug 2010 03:48:42 -0400 Received: from mail-ew0-f46.google.com ([209.85.215.46]:33163 "EHLO mail-ew0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753416Ab0HJHsk (ORCPT ); Tue, 10 Aug 2010 03:48:40 -0400 Received: by ewy23 with SMTP id 23so3722125ewy.19 for ; Tue, 10 Aug 2010 00:48:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:mime-version:content-type:content-disposition:user-agent; bh=jg+3GeyhdjmK6yoBycfWgEa6SsB+UIEfnrIUqrVjSc8=; b=xDJ9pN3fBxWoIDpxpwWRCDNM2If6JwgMwfJusqaSHYkMaTQ/BYnwMJjWlvEpnrYmbg +En5CBzfFQdj45XsRynYGewa+QS9bdifn4pLr1ONeuj2aIbdgnBCdIudPgLzvuFPhury P83Gd3gb8uDMtWX3EuuQuSUiYuJD7dSsDPiqA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=u6BTfjYIyIyUzBwivkHYEwHoHwMR8Gza1QcUNf1rZhFF58rmYK2oYjV4Ky6vNFy0Mi MsUCea8vKzgnz8wpfD19d/fw3yMx+b0zP9KU+Gf0aZk0Z7IcOLUTbNALt7zPVegytvv6 EB8PrrO2gHMGhbOOjXuKvScTI7mSvXllbc/8g= Received: by 10.213.20.142 with SMTP id f14mr13236338ebb.30.1281426518896; Tue, 10 Aug 2010 00:48:38 -0700 (PDT) Received: from bicker ([205.177.176.130]) by mx.google.com with ESMTPS id a48sm9293498eei.6.2010.08.10.00.48.22 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 10 Aug 2010 00:48:38 -0700 (PDT) Date: Tue, 10 Aug 2010 09:47:56 +0200 From: Dan Carpenter To: Amit Kumar Salecha Cc: Anirban Chakraborty , linux-driver@qlogic.com, "David S. Miller" , Sucheta Chakraborty , netdev@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch 1/2 v2] qlcnic: clean up qlcnic_init_pci_info() Message-ID: <20100810074756.GF18431@bicker> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In the original code we allocated memory conditionally and freed it in the error handling unconditionally. It turns out that this function is only called during initialization and "adapter->npars" and "adapter->eswitch" are always NULL at the start of the function. I removed those checks. Also since I was cleaning things, I changed the error handling for qlcnic_get_pci_info() and pulled everything in an indent level. Signed-off-by: Dan Carpenter --- V2: fixed a typo. I set eswitch to NULL twice instead of npars by mistake. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/qlcnic/qlcnic_main.c b/drivers/net/qlcnic/qlcnic_main.c index b9615bd..6b8df55 100644 --- a/drivers/net/qlcnic/qlcnic_main.c +++ b/drivers/net/qlcnic/qlcnic_main.c @@ -477,44 +477,45 @@ qlcnic_init_pci_info(struct qlcnic_adapter *adapter) int i, ret = 0, err; u8 pfn; - if (!adapter->npars) - adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) * + adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) * QLCNIC_MAX_PCI_FUNC, GFP_KERNEL); if (!adapter->npars) return -ENOMEM; - if (!adapter->eswitch) - adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) * + adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) * QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL); if (!adapter->eswitch) { err = -ENOMEM; - goto err_eswitch; + goto err_npars; } ret = qlcnic_get_pci_info(adapter, pci_info); - if (!ret) { - for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { - pfn = pci_info[i].id; - if (pfn > QLCNIC_MAX_PCI_FUNC) - return QL_STATUS_INVALID_PARAM; - adapter->npars[pfn].active = pci_info[i].active; - adapter->npars[pfn].type = pci_info[i].type; - adapter->npars[pfn].phy_port = pci_info[i].default_port; - adapter->npars[pfn].mac_learning = DEFAULT_MAC_LEARN; - adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw; - adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw; - } - - for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++) - adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE; + if (ret) + goto err_eswitch; - return ret; + for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { + pfn = pci_info[i].id; + if (pfn > QLCNIC_MAX_PCI_FUNC) + return QL_STATUS_INVALID_PARAM; + adapter->npars[pfn].active = pci_info[i].active; + adapter->npars[pfn].type = pci_info[i].type; + adapter->npars[pfn].phy_port = pci_info[i].default_port; + adapter->npars[pfn].mac_learning = DEFAULT_MAC_LEARN; + adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw; + adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw; } + for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++) + adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE; + + return 0; + +err_eswitch: kfree(adapter->eswitch); adapter->eswitch = NULL; -err_eswitch: +err_npars: kfree(adapter->npars); + adapter->npars = NULL; return ret; }