/* Local functions prototypes */
static int __devinit tpam_probe(struct pci_dev *, const struct pci_device_id *);
-static void __devexit tpam_unregister_card(tpam_card *);
+static void __devexit tpam_unregister_card(struct pci_dev *, tpam_card *);
static void __devexit tpam_remove(struct pci_dev *);
static int __init tpam_init(void);
static void __exit tpam_exit(void);
*/
static int __devinit tpam_probe(struct pci_dev *dev, const struct pci_device_id *pci_id) {
tpam_card *card, *c;
- int i;
+ int i, err;
+
+ if (pci_enable_device(dev)) {
+ printk(KERN_ERR "TurboPAM: can't enable PCI device at %s\n",
+ pci_name(dev));
+ return -ENODEV;
+ }
/* allocate memory for the board structure */
if (!(card = (tpam_card *)kmalloc(sizeof(tpam_card), GFP_KERNEL))) {
printk(KERN_ERR "TurboPAM: tpam_register_card: "
"kmalloc failed!\n");
- return -ENOMEM;
+ err = -ENOMEM;
+ goto err_out_disable_dev;
}
memset((char *)card, 0, sizeof(tpam_card));
card->interface.id, card)) {
printk(KERN_ERR "TurboPAM: tpam_register_card: "
"could not request irq %d\n", card->irq);
- kfree(card);
- return -EIO;
+ err = -EIO;
+ goto err_out_free_card;
}
/* remap board memory */
0x800000))) {
printk(KERN_ERR "TurboPAM: tpam_register_card: "
"unable to remap bar0\n");
- free_irq(card->irq, card);
- kfree(card);
- return -EIO;
+ err = -EIO;
+ goto err_out_free_irq;
}
/* reset the board */
if (!register_isdn(&card->interface)) {
printk(KERN_ERR "TurboPAM: tpam_register_card: "
"unable to register %s\n", card->interface.id);
- free_irq(card->irq, card);
- iounmap((void *)card->bar0);
- kfree(card);
- return -EIO;
+ err = -EIO;
+ goto err_out_iounmap;
}
card->id = card->interface.channels;
pci_set_drvdata(dev, card);
return 0;
+
+err_out_iounmap:
+ iounmap((void *)card->bar0);
+
+err_out_free_irq:
+ free_irq(card->irq, card);
+
+err_out_free_card:
+ kfree(card);
+
+err_out_disable_dev:
+ pci_disable_device(dev);
+ return err;
}
/*
*
* card: the board.
*/
-static void __devexit tpam_unregister_card(tpam_card *card) {
+static void __devexit tpam_unregister_card(struct pci_dev *pcidev, tpam_card *card) {
isdn_ctrl cmd;
/* prevent the ISDN link layer that the driver will be unloaded */
/* release mapped memory */
iounmap((void *)card->bar0);
+
+ pci_disable_device(pcidev);
}
/*
}
/* unregister each board */
- tpam_unregister_card(card);
+ tpam_unregister_card(pcidev, card);
/* and free the board structure itself */
kfree(card);