diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2018-05-05 10:46:46 +0200 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2018-05-05 10:46:46 +0200 |
commit | 0200874bc49dcd1f0a38b938dccc9c49a80b8daf (patch) | |
tree | 19ad6ce90a66d941c562b871da7940fe4daa7624 | |
parent | 66d048ece86d238c0712a0a205479ce8842f3053 (diff) |
Refactor pci_init
-rw-r--r-- | pci.c | 39 |
1 files changed, 27 insertions, 12 deletions
@@ -5,11 +5,9 @@ #include "char.h" #include "harddoom.h" -#include "pci.h" #include "util.h" -int doom_probe(struct pci_dev *dev, const struct pci_device_id *id) -{ +int init_pci(struct pci_dev *dev) { struct doom_data *doom_data; int err = 0; @@ -28,14 +26,8 @@ int doom_probe(struct pci_dev *dev, const struct pci_device_id *id) pci_set_dma_mask(dev, DMA_BIT_MASK(32)); pci_set_consistent_dma_mask(dev, DMA_BIT_MASK(32)); - ORFAIL(new_doomdev(dev), error_doomdev); - return 0; -error_doomdev: - pci_clear_master(dev); - pci_iounmap(dev, doom_data->iomem); - kfree(doom_data); error_kmalloc: pci_release_regions(dev); error_regions: @@ -44,13 +36,11 @@ error_enable: return err; } -void doom_remove (struct pci_dev *dev) -{ +void cleanup_pci(struct pci_dev *dev) { struct doom_data *doom_data; doom_data = pci_get_drvdata(dev); - destroy_doomdev(doom_data); pci_clear_master(dev); pci_iounmap(dev, doom_data->iomem); kfree(doom_data); @@ -58,6 +48,31 @@ void doom_remove (struct pci_dev *dev) pci_disable_device(dev); } +int doom_probe(struct pci_dev *dev, const struct pci_device_id *id) +{ + int err = 0; + + ORFAIL(init_pci(dev), error_pci); + ORFAIL(new_doomdev(dev), error_doomdev); + + return 0; + +error_doomdev: + cleanup_pci(dev); +error_pci: + return err; +} + +void doom_remove (struct pci_dev *dev) +{ + struct doom_data *doom_data; + + doom_data = pci_get_drvdata(dev); + + destroy_doomdev(doom_data); + cleanup_pci(dev); +} + int doom_suspend (struct pci_dev *dev, pm_message_t state) { return 0; |