From patchwork Mon Aug 3 02:17:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia-Ju Bai X-Patchwork-Id: 502974 X-Patchwork-Delegate: jeffrey.t.kirsher@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ozlabs.org (Postfix) with ESMTP id D75DF1402A6 for ; Mon, 3 Aug 2015 12:17:32 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=163.com header.i=@163.com header.b=dxEqfgSA; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 10F4D32BC4; Mon, 3 Aug 2015 02:17:32 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id atf4i7tEOxZF; Mon, 3 Aug 2015 02:17:31 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id F1B3332AC1; Mon, 3 Aug 2015 02:17:30 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 9AEFE1C1323 for ; Mon, 3 Aug 2015 02:17:29 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 953D48B8A2 for ; Mon, 3 Aug 2015 02:17:29 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QAW4RANA3llA for ; Mon, 3 Aug 2015 02:17:28 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from m50-133.163.com (m50-133.163.com [123.125.50.133]) by whitealder.osuosl.org (Postfix) with ESMTP id 357838B89E for ; Mon, 3 Aug 2015 02:17:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=ks89pKxbDgSAkDyB6n Ff2Bc7v3Igm9sEHnUsQNEZK70=; b=dxEqfgSAeoN4hka5IRULQ5iq/4H6KsfrJh RoA/3VRtjY1KcfKguBlc6g7Gss9p6lYXsHl7zYNur+66y5o06/W3ZZ2UiZPG5VFL zDJ8CUVv4YfBHSvckQ/6toJm1nQbjVfqS5d39j2FuHbeRlN5FWaXqKJ1QCnPvpe5 XTLsHkbIE= Received: from bai-oslab.tsinghua.edu.cn (unknown [173.252.200.40]) by smtp3 (Coremail) with SMTP id DdGowED57EQnz75VM4icAA--.119S2; Mon, 03 Aug 2015 10:17:21 +0800 (CST) From: Jia-Ju Bai To: jeffrey.t.kirsher@intel.com, jesse.brandeburg@intel.com Date: Mon, 3 Aug 2015 10:17:08 +0800 Message-Id: <1438568228-13288-1-git-send-email-baijiaju1990@163.com> X-Mailer: git-send-email 1.7.9.5 X-CM-TRANSID: DdGowED57EQnz75VM4icAA--.119S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxJr17Zr1xGr1UGry8Kw47XFb_yoW8Jw4xpa nIva43Cr48X343Ww18JF18ZF90va1jqas8WFy7Awn5ua97Jry8tFWrKFW0kryUurWDGa43 tF1jyry7CFs8tw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jzeHDUUUUU= X-Originating-IP: [173.252.200.40] X-CM-SenderInfo: xedlyx5dmximizq6il2tof0z/1tbiYxJLelD+dxzYFQAAsI Cc: netdev@vger.kernel.org, Jia-Ju Bai , intel-wired-lan@lists.osuosl.org, linux-kernel@vger.kernel.org Subject: [Intel-wired-lan] [PATCH] e100: Add a check after pci_pool_create to avoid null pointer dereference X-BeenThere: intel-wired-lan@lists.osuosl.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-wired-lan-bounces@lists.osuosl.org Sender: "Intel-wired-lan" The driver lacks the check of nic->cbs_pool after pci_pool_create in e100_probe. When this function is failed, a null pointer dereference occurs when pci_pool_alloc uses nic->cbs_pool in e100_alloc_cbs. This patch adds a check and related error handling code to fix it. Signed-off-by: Jia-Ju Bai Tested-by: Aaron Brown --- drivers/net/ethernet/intel/e100.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c index d2657a4..767c161 100644 --- a/drivers/net/ethernet/intel/e100.c +++ b/drivers/net/ethernet/intel/e100.c @@ -2967,6 +2967,11 @@ static int e100_probe(struct pci_dev *pdev, const struct pci_device_id *ent) nic->params.cbs.max * sizeof(struct cb), sizeof(u32), 0); + if (!nic->cbs_pool) { + netif_err(nic, probe, nic->netdev, "Cannot create DMA pool, aborting\n"); + err = -ENOMEM; + goto err_out_pool; + } netif_info(nic, probe, nic->netdev, "addr 0x%llx, irq %d, MAC addr %pM\n", (unsigned long long)pci_resource_start(pdev, use_io ? 1 : 0), @@ -2974,6 +2979,8 @@ static int e100_probe(struct pci_dev *pdev, const struct pci_device_id *ent) return 0; +err_out_pool: + unregister_netdev(netdev); err_out_free: e100_free(nic); err_out_iounmap: