net: ethernet: realtek: fix pgdrv remove for r8168 driver
Martin Gao [Tue, 3 May 2016 01:03:12 +0000 (18:03 -0700)]
- in r8168 realtek ethernet driver, we added pgtool functionality, and
pgdrv_remove wasn't checking for null pointer, and thus caused null pointer
exception.

Bug 200196087

Change-Id: Ib170fc4b1d3ef496d75def62924adf119f068324
Signed-off-by: Martin Gao <marting@nvidia.com>
(cherry picked from commit fa3352ceffe25cc86cf25ebc86e6d519bb7b6316)
Reviewed-on: http://git-master/r/1146186
GVS: Gerrit_Virtual_Submit
Reviewed-by: Raymond Poudrier <rapoudrier@nvidia.com>

drivers/net/ethernet/realtek/pgdrv.c
drivers/net/ethernet/realtek/r8168_n.c [changed mode: 0755->0644]

index 9e31a73..6dc776a 100644 (file)
@@ -4,7 +4,7 @@
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
 # controllers with PCI-Express interface.
 #
-# Copyright(c) 2014 Realtek Semiconductor Corp. All rights reserved.
+# Copyright(c) 2014-2016, Realtek Semiconductor Corp. All rights reserved.
 #
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by the Free
@@ -548,15 +548,17 @@ void __devexit pgdrv_remove(struct pci_dev *pdev)
        mydev = pci_get_drvdata(pdev);
        DbgFunPrint("mydev=%p",mydev);
 
-       mydev->base_phyaddr = 0;
        pci_release_regions(pdev);
        pci_disable_device(pdev);
 
-       cdev_del(&mydev->cdev);
-       spin_lock(&module_lock);
-       dev_info[mydev->index].bUsed = FALSE;
-       spin_unlock(&module_lock);
-       kfree(mydev);
+       if (mydev) {
+               mydev->base_phyaddr = 0;
+               cdev_del(&mydev->cdev);
+               spin_lock(&module_lock);
+               dev_info[mydev->index].bUsed = FALSE;
+               spin_unlock(&module_lock);
+               kfree(mydev);
+       }
        pci_set_drvdata(pdev, NULL);
        atomic_dec(&dev_num);
 }
old mode 100755 (executable)
new mode 100644 (file)
index 56a480b..71a7f77
@@ -4,7 +4,7 @@
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
 # controllers with PCI-Express interface.
 #
-# Copyright(c) 2015 Realtek Semiconductor Corp. All rights reserved.
+# Copyright(c) 2015-2016, Realtek Semiconductor Corp. All rights reserved.
 #
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by the Free
@@ -22469,8 +22469,11 @@ rtl8168_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                        MODULENAME, RTL8168_VERSION);
 
         rc = rtl8168_init_board(pdev, &dev, &ioaddr);
-        if (rc)
-                return rc;
+       if (rc) {
+               dev_err(&pdev->dev, "%s: failed to initialize. Error: %d\n",
+                               MODULENAME, rc);
+               return rc;
+       }
 
         tp = netdev_priv(dev);
         assert(ioaddr != NULL);
@@ -22561,7 +22564,9 @@ rtl8168_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 #endif
                 rtl8168_disable_msi(pdev, tp);
                 rtl8168_release_board(pdev, dev, ioaddr);
-                return rc;
+               dev_err(&pdev->dev, "%s: failed to register netdev. Error %d\n",
+                               MODULENAME, rc);
+               return rc;
         }
 
         printk(KERN_INFO "%s: This product is covered by one or more of the following patents: US6,570,884, US6,115,776, and US6,327,625.\n", MODULENAME);
@@ -25332,14 +25337,19 @@ rtl8168_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        int ret;
 
        ret = pgdrv_prob(pdev, id);
-       if (ret)
+       if (ret) {
+               dev_err(&pdev->dev, "%s: Unable to probe pgdrv.\n",
+                               MODULENAME);
                goto exit_probe;
+       }
 
        mydev = pci_get_drvdata(pdev);
        pci_set_drvdata(pdev, NULL);
 
        ret = rtl8168_init_one(pdev, id);
        if (ret) {
+               dev_err(&pdev->dev, "%s: Unable to initialize rtl8168.\n",
+                               MODULENAME);
                pgdrv_remove(pdev);
                goto exit_probe;
        }