Merge tag 'for-linus-20150216' of git://git.infradead.org/linux-mtd
[firefly-linux-kernel-4.4.55.git] / drivers / staging / dgnc / dgnc_driver.c
index ba98ff348112032314a6124c5d8d2f300388ef1d..f177d3a258c2cf8bce2c2f18182b19167e6155f7 100644 (file)
@@ -97,12 +97,12 @@ static uint         dgnc_poll_stop;                         /* Used to tell poller to stop */
 static struct timer_list dgnc_poll_timer;
 
 
-static struct pci_device_id dgnc_pci_tbl[] = {
-       {       DIGI_VID, PCI_DEVICE_CLASSIC_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,       0 },
-       {       DIGI_VID, PCI_DEVICE_CLASSIC_4_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,   1 },
-       {       DIGI_VID, PCI_DEVICE_CLASSIC_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,       2 },
-       {       DIGI_VID, PCI_DEVICE_CLASSIC_8_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,   3 },
-       {0,}                                            /* 0 terminated list. */
+static const struct pci_device_id dgnc_pci_tbl[] = {
+       {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_DID),     .driver_data = 0},
+       {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_422_DID), .driver_data = 1},
+       {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_8_DID),     .driver_data = 2},
+       {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_8_422_DID), .driver_data = 3},
+       {0,}
 };
 MODULE_DEVICE_TABLE(pci, dgnc_pci_tbl);
 
@@ -238,6 +238,7 @@ static int dgnc_start(void)
 {
        int rc = 0;
        unsigned long flags;
+       struct device *dev;
 
        /* make sure that the globals are init'd before we do anything else */
        dgnc_init_globals();
@@ -257,9 +258,20 @@ static int dgnc_start(void)
        dgnc_Major = rc;
 
        dgnc_class = class_create(THIS_MODULE, "dgnc_mgmt");
-       device_create(dgnc_class, NULL,
-               MKDEV(dgnc_Major, 0),
-               NULL, "dgnc_mgmt");
+       if (IS_ERR(dgnc_class)) {
+               rc = PTR_ERR(dgnc_class);
+               pr_err(DRVSTR ": Can't create dgnc_mgmt class (%d)\n", rc);
+               goto failed_class;
+       }
+
+       dev = device_create(dgnc_class, NULL,
+                       MKDEV(dgnc_Major, 0),
+                       NULL, "dgnc_mgmt");
+       if (IS_ERR(dev)) {
+               rc = PTR_ERR(dev);
+               pr_err(DRVSTR ": Can't create device (%d)\n", rc);
+               goto failed_device;
+       }
 
        /*
         * Init any global tty stuff.
@@ -268,7 +280,7 @@ static int dgnc_start(void)
 
        if (rc < 0) {
                pr_err(DRVSTR ": tty preinit - not enough memory (%d)\n", rc);
-               return rc;
+               goto failed_tty;
        }
 
        /* Start the poller */
@@ -282,6 +294,14 @@ static int dgnc_start(void)
 
        add_timer(&dgnc_poll_timer);
 
+       return 0;
+
+failed_tty:
+       device_destroy(dgnc_class, MKDEV(dgnc_Major, 0));
+failed_device:
+       class_destroy(dgnc_class);
+failed_class:
+       unregister_chrdev(dgnc_Major, "dgnc");
        return rc;
 }