m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2018-05-05 10:46:46 +0200
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2018-05-05 10:46:46 +0200
commit0200874bc49dcd1f0a38b938dccc9c49a80b8daf (patch)
tree19ad6ce90a66d941c562b871da7940fe4daa7624
parent66d048ece86d238c0712a0a205479ce8842f3053 (diff)
Refactor pci_init
-rw-r--r--pci.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/pci.c b/pci.c
index 95aad2e..f8626d9 100644
--- a/pci.c
+++ b/pci.c
@@ -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;