Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753592AbcKTIqh (ORCPT ); Sun, 20 Nov 2016 03:46:37 -0500 Received: from mail-wm0-f47.google.com ([74.125.82.47]:36394 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753543AbcKTIqd (ORCPT ); Sun, 20 Nov 2016 03:46:33 -0500 From: Netanel Belgazal To: linux-kernel@vger.kernel.org, davem@davemloft.net, netdev@vger.kernel.org Cc: Netanel Belgazal , dwmw@amazon.com, zorik@annapurnalabs.com, alex@annapurnalabs.com, saeed@annapurnalabs.com, msw@amazon.com, aliguori@amazon.com, nafea@annapurnalabs.com Subject: [PATCH net 17/18] net/ena: fix NULL dereference when removing the driver after device reset faild Date: Sun, 20 Nov 2016 10:45:46 +0200 Message-Id: <1479631547-29354-18-git-send-email-netanel@annapurnalabs.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1479631547-29354-1-git-send-email-netanel@annapurnalabs.com> References: <1479631547-29354-1-git-send-email-netanel@annapurnalabs.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1366 Lines: 40 If for some reason the device stop responding and the device reset failed to recover the device, the mmio register read datastructure will not be reinitialized. On driver removal, the driver will also tries to reset the device but this time the mmio data structure will be NULL. To solve this issue perform the device reset in the remove function only if the device is runnig. Signed-off-by: Netanel Belgazal --- drivers/net/ethernet/amazon/ena/ena_netdev.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c index ba395aa..12d1dca 100644 --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c @@ -2591,6 +2591,8 @@ static void ena_fw_reset_device(struct work_struct *work) err: rtnl_unlock(); + clear_bit(ENA_FLAG_DEVICE_RUNNING, &adapter->flags); + dev_err(&pdev->dev, "Reset attempt failed. Can not reset the device\n"); } @@ -3251,7 +3253,9 @@ static void ena_remove(struct pci_dev *pdev) cancel_work_sync(&adapter->resume_io_task); - ena_com_dev_reset(ena_dev); + /* Reset the device only if the device is running. */ + if (test_bit(ENA_FLAG_DEVICE_RUNNING, &adapter->flags)) + ena_com_dev_reset(ena_dev); ena_free_mgmnt_irq(adapter); -- 1.9.1