From: Tejun Heo <htejun@gmail.com>
To: jgarzik@pobox.com, alan@lxorguk.ukuu.org.uk, mlord@pobox.com,
albertcc@tw.ibm.com, uchang@tw.ibm.com, forrest.zhao@intel.com,
brking@us.ibm.com, linux-ide@vger.kernel.org
Cc: Tejun Heo <htejun@gmail.com>
Subject: [PATCH 3/20] libata: implement ata_host_detach() and ata_host_free()
Date: Sat, 19 Aug 2006 17:59:31 +0900 [thread overview]
Message-ID: <1155977971165-git-send-email-htejun@gmail.com> (raw)
In-Reply-To: <11559778241753-git-send-email-htejun@gmail.com>
Implement and use ata_host_detach() and ata_host_free().
ata_host_detach() detaches all ports in the host and supercedes
ata_port_detach(). ata_host_free() makes sure all ports are stopped
(LLDs may stop ports beforehand if necessary), frees all ports and the
host itself. ata_host_free() can also be used in the error handling
path of init functions.
This patch moves several memory deallocations but doesn't introduce
any real behavior changes.
This is a part of efforts to improve [de-]init paths and simplify
LLDs.
Signed-off-by: Tejun Heo <htejun@gmail.com>
---
drivers/ata/ahci.c | 13 +++------
drivers/ata/libata-core.c | 65 +++++++++++++++++++++++++++++++++++++--------
include/linux/libata.h | 3 +-
3 files changed, 60 insertions(+), 21 deletions(-)
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index eb6ceb3..08ecc69 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -1634,30 +1634,27 @@ static void ahci_remove_one (struct pci_
struct device *dev = pci_dev_to_dev(pdev);
struct ata_host *host = dev_get_drvdata(dev);
struct ahci_host_priv *hpriv = host->private_data;
- unsigned int i;
int have_msi;
- for (i = 0; i < host->n_ports; i++)
- ata_port_detach(host->ports[i]);
+ ata_host_detach(host);
have_msi = hpriv->flags & AHCI_FLAG_MSI;
free_irq(host->irq, host);
ata_host_stop(host);
-
- for (i = 0; i < host->n_ports; i++)
- scsi_host_put(host->ports[i]->scsi_host);
- kfree(hpriv);
pci_iounmap(pdev, host->mmio_base);
- kfree(host);
if (have_msi)
pci_disable_msi(pdev);
else
pci_intx(pdev, 0);
+
pci_release_regions(pdev);
pci_disable_device(pdev);
dev_set_drvdata(dev, NULL);
+
+ ata_host_free(host);
+ kfree(hpriv);
}
static int __init ahci_init(void)
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 8472ec9..d7bf4a1 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -5621,10 +5621,7 @@ err_out_free_irq:
free_irq(ent->irq, host);
err_out:
ata_host_stop(host);
-
- for (i = 0; i < host->n_ports; i++)
- scsi_host_put(host->ports[i]->scsi_host);
- kfree(host);
+ ata_host_free(host);
VPRINTK("EXIT, returning 0\n");
return 0;
}
@@ -5640,7 +5637,7 @@ err_out:
* LOCKING:
* Kernel thread context (may sleep).
*/
-void ata_port_detach(struct ata_port *ap)
+static void ata_port_detach(struct ata_port *ap)
{
unsigned long flags;
int i;
@@ -5691,6 +5688,23 @@ void ata_port_detach(struct ata_port *ap
}
/**
+ * ata_host_detach - Detach a host from the system
+ * @host: ATA host set that was removed
+ *
+ * Detach all objects associated with this host set.
+ *
+ * LOCKING:
+ * Inherited from calling layer (may sleep).
+ */
+void ata_host_detach(struct ata_host *host)
+{
+ int i;
+
+ for (i = 0; i < host->n_ports; i++)
+ ata_port_detach(host->ports[i]);
+}
+
+/**
* ata_host_stop - stop ports of an ATA host
* @host: ATA host to stop
*
@@ -5719,6 +5733,36 @@ void ata_host_stop(struct ata_host *host
}
/**
+ * ata_host_free - Release a host
+ * @host: ATA host set to be freed
+ *
+ * Free all objects associated with this host set.
+ *
+ * LOCKING:
+ * Inherited from calling layer (may sleep).
+ */
+void ata_host_free(struct ata_host *host)
+{
+ int i;
+
+ /* free(NULL) is supported */
+ if (!host)
+ return;
+
+ /* make sure all ports are stopped */
+ ata_host_stop(host);
+
+ /* free */
+ for (i = 0; i < host->n_ports; i++) {
+ struct ata_port *ap = host->ports[i];
+ if (ap)
+ scsi_host_put(ap->scsi_host);
+ }
+
+ kfree(host);
+}
+
+/**
* ata_host_remove - PCI layer callback for device removal
* @host: ATA host set that was removed
*
@@ -5728,13 +5772,11 @@ void ata_host_stop(struct ata_host *host
* LOCKING:
* Inherited from calling layer (may sleep).
*/
-
void ata_host_remove(struct ata_host *host)
{
unsigned int i;
- for (i = 0; i < host->n_ports; i++)
- ata_port_detach(host->ports[i]);
+ ata_host_detach(host);
free_irq(host->irq, host);
if (host->irq2)
@@ -5754,14 +5796,12 @@ void ata_host_remove(struct ata_host *ho
else if (ioaddr->cmd_addr == ATA_SECONDARY_CMD)
release_region(ATA_SECONDARY_CMD, 8);
}
-
- scsi_host_put(ap->scsi_host);
}
if (host->ops->host_stop)
host->ops->host_stop(host);
- kfree(host);
+ ata_host_free(host);
}
struct ata_probe_ent *
@@ -6070,8 +6110,9 @@ EXPORT_SYMBOL_GPL(ata_std_ports);
EXPORT_SYMBOL_GPL(ata_host_init);
EXPORT_SYMBOL_GPL(ata_host_start);
EXPORT_SYMBOL_GPL(ata_device_add);
-EXPORT_SYMBOL_GPL(ata_port_detach);
+EXPORT_SYMBOL_GPL(ata_host_detach);
EXPORT_SYMBOL_GPL(ata_host_stop);
+EXPORT_SYMBOL_GPL(ata_host_free);
EXPORT_SYMBOL_GPL(ata_host_remove);
EXPORT_SYMBOL_GPL(ata_sg_init);
EXPORT_SYMBOL_GPL(ata_sg_init_one);
diff --git a/include/linux/libata.h b/include/linux/libata.h
index e098d32..5263e6b 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -692,8 +692,9 @@ extern int ata_pci_clear_simplex(struct
#endif /* CONFIG_PCI */
extern int ata_host_start(struct ata_host *host);
extern int ata_device_add(const struct ata_probe_ent *ent);
-extern void ata_port_detach(struct ata_port *ap);
+extern void ata_host_detach(struct ata_host *host);
extern void ata_host_stop(struct ata_host *host);
+extern void ata_host_free(struct ata_host *host);
extern void ata_host_init(struct ata_host *, struct device *,
unsigned long, const struct ata_port_operations *);
extern void ata_host_remove(struct ata_host *host);
--
1.4.1.1
next prev parent reply other threads:[~2006-08-19 8:59 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-19 8:57 [PATCHSET] libata: implement new initialization model w/ iomap support, take 2 Tejun Heo
2006-08-19 8:59 ` [PATCH 1/20] libata: kill ata_host_stop() Tejun Heo
2006-08-19 14:51 ` Jeff Garzik
2006-08-19 15:29 ` Tejun Heo
2006-09-19 4:46 ` Jeff Garzik
2006-09-19 4:50 ` Tejun Heo
2006-08-19 8:59 ` [PATCH 2/20] libata: implement ata_host_start/stop() Tejun Heo
2006-08-19 8:59 ` [PATCH 6/20] libata: implement legacy ATA init helpers Tejun Heo
2006-09-19 5:26 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 5/20] libata: implement several LLD " Tejun Heo
2006-08-22 22:11 ` Brian King
2006-08-27 9:52 ` Tejun Heo
2006-08-30 21:16 ` Brian King
2006-09-19 5:16 ` Jeff Garzik
2006-09-19 5:57 ` Tejun Heo
2006-08-19 8:59 ` Tejun Heo [this message]
2006-09-19 4:59 ` [PATCH 3/20] libata: implement ata_host_detach() and ata_host_free() Jeff Garzik
2006-08-19 8:59 ` [PATCH 4/20] libata: separate out ata_host_alloc() and ata_host_attach() Tejun Heo
2006-09-19 5:08 ` Jeff Garzik
2006-09-19 5:48 ` Tejun Heo
2006-08-19 8:59 ` [PATCH 7/20] libata: implement PCI ATA init helpers Tejun Heo
2006-09-19 5:29 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 8/20] libata: reimplement ata_pci_init_one() using new " Tejun Heo
2006-09-19 5:32 ` Jeff Garzik
2006-09-19 6:04 ` Tejun Heo
2006-09-19 6:09 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 11/20] libata: use remove_one() for deinit instead of ->host_stop() Tejun Heo
2006-09-19 5:42 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 10/20] libata: reimplement ata_pci_remove_one() using new PCI init helpers Tejun Heo
2006-08-19 8:59 ` [PATCH 13/20] libata: kill unused ->host_stop() operation and related functions Tejun Heo
2006-09-19 5:42 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 12/20] libata: kill old init helpers Tejun Heo
2006-08-19 8:59 ` [PATCH 15/20] libata: move ->irq_handler from port_ops to port_info Tejun Heo
2006-09-19 5:43 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 16/20] libata: make ata_host_alloc() take care of hpriv alloc/free Tejun Heo
2006-09-19 5:45 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 19/20] libata: kill unused ATA_FLAG_MMIO Tejun Heo
2006-08-19 8:59 ` [PATCH 17/20] libata: make ata_pci_acquire_resources() handle iomap Tejun Heo
2006-09-19 5:47 ` Jeff Garzik
2006-09-19 6:27 ` Tejun Heo
2006-09-19 6:32 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 14/20] libata: use LLD name where possible Tejun Heo
2006-09-19 5:43 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 20/20] libata: move scattered PCI ATA functions into liata-pci.c Tejun Heo
2006-09-19 5:50 ` Jeff Garzik
2006-08-22 22:10 ` [PATCHSET] libata: implement new initialization model w/ iomap support, take 2 Brian King
2006-08-27 10:12 ` Tejun Heo
2006-08-30 20:58 ` Brian King
2006-09-01 13:45 ` Tejun Heo
2006-09-07 13:22 ` Brian King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1155977971165-git-send-email-htejun@gmail.com \
--to=htejun@gmail.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=albertcc@tw.ibm.com \
--cc=brking@us.ibm.com \
--cc=forrest.zhao@intel.com \
--cc=jgarzik@pobox.com \
--cc=linux-ide@vger.kernel.org \
--cc=mlord@pobox.com \
--cc=uchang@tw.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).