From patchwork Sat Dec 20 13:27:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia-Ju Bai X-Patchwork-Id: 423063 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 19C6C140082 for ; Sun, 21 Dec 2014 00:28:09 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752932AbaLTN2F (ORCPT ); Sat, 20 Dec 2014 08:28:05 -0500 Received: from m12-14.163.com ([220.181.12.14]:52174 "EHLO m12-14.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752892AbaLTN2C (ORCPT ); Sat, 20 Dec 2014 08:28:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=6HXee gyFPq2cwsaxwSV5Eu4UKzD++Yuum8rYG7I6NKI=; b=IyHq8byd9rbqWkVu28yCC +WVfTcQy74xTza0oYHu/smNYcNNjhl8eyo4Ub+cVxKc0fC66NrKdbYuldnOPheNX BT2tU/wwDHfuSk6va9cnOzuJcbxl8Mqz+mPId1A0iLl0JZ7A+V9gtXyxiiOK2ICo ob985+lt3VEYZrDJZRr0Ac= Received: from BaijiajuPC (unknown [166.111.70.4]) by smtp10 (Coremail) with SMTP id DsCowEA5zHleeZVUAdbOAw--.3490S2; Sat, 20 Dec 2014 21:27:58 +0800 (CST) From: "Jia-Ju Bai" To: Subject: [PATCH] ne2k+8390 in linux-3.18.0: some potential bugs Date: Sat, 20 Dec 2014 21:27:57 +0800 Message-ID: <001801d01c58$c4c1f650$4e45e2f0$@163.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AdAcWGRRm+bK3CjkSDWJNMcOB+jVew== Content-Language: zh-cn X-CM-TRANSID: DsCowEA5zHleeZVUAdbOAw--.3490S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zw4rXFyruF18KF1kur4kJFb_yoW8uFy3pF W7Ja4Y9ry8KFWfZ3WDJw1kXF93A3yUt3y5GF4rCwn09w4YkF9YyFZ5tay5XFyUCrWkGF1x tw1DAw1kZa95XaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jI6wtUUUUU= X-Originating-IP: [166.111.70.4] X-CM-SenderInfo: xedlyx5dmximizq6il2tof0z/xtbBRQBoelO-rlToswAAsa Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org I have actually tested ne2k+8390 driver on the real hardware(Realtek RTL8029 PCI Ethernet Controller), and find some potential bugs: The target file is drivers/net/ethernet/8390/ne2k-pci.c, which is used to build ne2k-pci.ko. (1) The function request_region is called by ne2k_pci_init_one when initializing the ethernet card driver. But when request_region is failed, which means that it returns the error value, ne2k_pci_init_one returns immediately to halt the process. However, because pci_enable_device has been called before request_region in ne2k_pci_init_one, pci_disable_device should be called before exiting. When the driver works normally, pci_enable_device and pci_disable_device are called in pairs in ne2k_pci_init_one and ne2k_pci_remove_one. Moreover, other ethernet card drivers call pci_enable_device and pci_disable_device in pairs in error handling paths, such as r8169 and sky2. (2) The similar problem occurs when alloc_ei_netdev is failed in ne2k_pci_init_one. (3) The similar problem occurs when register_netdev is failed in ne2k_pci_init_one. Meanwhile, I also write the patch to fix the bugs. I have run the patch on the hardware, it can work normally and fix the above bugs. reg0 = inb(ioaddr); @@ -392,6 +392,8 @@ err_out_free_netdev: free_netdev (dev); err_out_free_res: release_region (ioaddr, NE_IO_EXTENT); +err_out: + pci_disable_device (pdev); return -ENODEV; } Thanks! --- 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/ethernet/8390/ne2k-pci.c b/drivers/net/ethernet/8390/ne2k-pci.c index 89c8d9f..f241c6b 100644 --- a/drivers/net/ethernet/8390/ne2k-pci.c +++ b/drivers/net/ethernet/8390/ne2k-pci.c @@ -246,13 +246,13 @@ static int ne2k_pci_init_one(struct pci_dev *pdev, if (!ioaddr || ((pci_resource_flags (pdev, 0) & IORESOURCE_IO) == 0)) { dev_err(&pdev->dev, "no I/O resource at PCI BAR #0\n"); - return -ENODEV; + goto err_out; } if (request_region (ioaddr, NE_IO_EXTENT, DRV_NAME) == NULL) { dev_err(&pdev->dev, "I/O resource 0x%x @ 0x%lx busy\n", NE_IO_EXTENT, ioaddr); - return -EBUSY; + goto err_out; }