libata: update libata LLDs to use devres
[powerpc.git] / drivers / ata / sata_svw.c
index 5f4e82a..9c48b41 100644 (file)
@@ -359,8 +359,6 @@ static const struct ata_port_operations k2_sata_ops = {
        .scr_read               = k2_sata_scr_read,
        .scr_write              = k2_sata_scr_write,
        .port_start             = ata_port_start,
-       .port_stop              = ata_port_stop,
-       .host_stop              = ata_pci_host_stop,
 };
 
 static void k2_sata_setup_port(struct ata_ioports *port, unsigned long base)
@@ -386,12 +384,12 @@ static void k2_sata_setup_port(struct ata_ioports *port, unsigned long base)
 static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
 {
        static int printed_version;
-       struct ata_probe_ent *probe_ent = NULL;
+       struct device *dev = &pdev->dev;
+       struct ata_probe_ent *probe_ent;
        unsigned long base;
        void __iomem *mmio_base;
        const struct k2_board_info *board_info =
                        &k2_board_info[ent->driver_data];
-       int pci_dev_busy = 0;
        int rc;
        int i;
 
@@ -402,7 +400,7 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
         * If this driver happens to only be useful on Apple's K2, then
         * we should check that here as it has a normal Serverworks ID
         */
-       rc = pci_enable_device(pdev);
+       rc = pcim_enable_device(pdev);
        if (rc)
                return rc;
        /*
@@ -415,32 +413,27 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
        /* Request PCI regions */
        rc = pci_request_regions(pdev, DRV_NAME);
        if (rc) {
-               pci_dev_busy = 1;
-               goto err_out;
+               pcim_pin_device(pdev);
+               return rc;
        }
 
        rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
        if (rc)
-               goto err_out_regions;
+               return rc;
        rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
        if (rc)
-               goto err_out_regions;
+               return rc;
 
-       probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL);
-       if (probe_ent == NULL) {
-               rc = -ENOMEM;
-               goto err_out_regions;
-       }
+       probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
+       if (probe_ent == NULL)
+               return -ENOMEM;
 
-       memset(probe_ent, 0, sizeof(*probe_ent));
        probe_ent->dev = pci_dev_to_dev(pdev);
        INIT_LIST_HEAD(&probe_ent->node);
 
-       mmio_base = pci_iomap(pdev, 5, 0);
-       if (mmio_base == NULL) {
-               rc = -ENOMEM;
-               goto err_out_free_ent;
-       }
+       mmio_base = pcim_iomap(pdev, 5, 0);
+       if (mmio_base == NULL)
+               return -ENOMEM;
        base = (unsigned long) mmio_base;
 
        /* Clear a magic bit in SCR1 according to Darwin, those help
@@ -478,20 +471,11 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
 
        pci_set_master(pdev);
 
-       /* FIXME: check ata_device_add return value */
-       ata_device_add(probe_ent);
-       kfree(probe_ent);
+       if (!ata_device_add(probe_ent))
+               return -ENODEV;
 
+       devm_kfree(dev, probe_ent);
        return 0;
-
-err_out_free_ent:
-       kfree(probe_ent);
-err_out_regions:
-       pci_release_regions(pdev);
-err_out:
-       if (!pci_dev_busy)
-               pci_disable_device(pdev);
-       return rc;
 }
 
 /* 0x240 is device ID for Apple K2 device