All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libata: clear drvdata in ata_host_release()
@ 2007-02-24  7:48 Tejun Heo
  2007-02-24 13:57 ` Alan
  2007-02-25  1:51 ` Jeff Garzik
  0 siblings, 2 replies; 6+ messages in thread
From: Tejun Heo @ 2007-02-24  7:48 UTC (permalink / raw)
  To: Jeff Garzik, Alan Cox, linux-ide

ata_host_release() uses drvdata to determine ata_host to release and
clearing drvdata in ->remove_one causes NULL pointer deference.  Clear
drvdata only in ata_host_release() after all resources are freed.

This bug was first analyzed by Alan Cox for pata_pcmcia.

Signed-off-by: Tejun Heo <htejun@gmail.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
---
Alan, this is the bug you talked about, right?  I took the fix from
"[BUG] PATA_PCMCIA does not work" and expanded it.  If this isn't the
one, please let me know.  Thanks.

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index d3b4e25..a705b38 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -5638,6 +5638,8 @@ static void ata_host_release(struct device *gendev, void *res)
 
 	if (host->ops->host_stop)
 		host->ops->host_stop(host);
+
+	dev_set_drvdata(gendev, NULL);
 }
 
 /**
@@ -5860,7 +5862,6 @@ int ata_device_add(const struct ata_probe_ent *ent)
 
  err_out:
 	devres_release_group(dev, ata_device_add);
-	dev_set_drvdata(dev, NULL);
 	VPRINTK("EXIT, returning %d\n", rc);
 	return 0;
 }
diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
index b49d8b7..30e20fa 100644
--- a/drivers/ata/pata_cs5520.c
+++ b/drivers/ata/pata_cs5520.c
@@ -306,7 +306,6 @@ static void __devexit cs5520_remove_one(struct pci_dev *pdev)
 	struct ata_host *host = dev_get_drvdata(dev);
 
 	ata_host_detach(host);
-	dev_set_drvdata(dev, NULL);
 }
 
 /**
diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c
index 1bf5ec1..e19cebf 100644
--- a/drivers/ata/pata_isapnp.c
+++ b/drivers/ata/pata_isapnp.c
@@ -128,7 +128,6 @@ static void isapnp_remove_one(struct pnp_dev *idev)
 	struct ata_host *host = dev_get_drvdata(dev);
 
 	ata_host_detach(host);
-	dev_set_drvdata(dev, NULL);
 }
 
 static struct pnp_device_id isapnp_devices[] = {
diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
index d10ae3e..4ef477c 100644
--- a/drivers/ata/pata_pcmcia.c
+++ b/drivers/ata/pata_pcmcia.c
@@ -308,7 +308,6 @@ static void pcmcia_remove_one(struct pcmcia_device *pdev)
 		if (info->ndev) {
 			struct ata_host *host = dev_get_drvdata(dev);
 			ata_host_detach(host);
-			dev_set_drvdata(dev, NULL);
 		}
 		info->ndev = 0;
 		pdev->priv = NULL;
diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
index 02ea95f..4b82a54 100644
--- a/drivers/ata/pata_platform.c
+++ b/drivers/ata/pata_platform.c
@@ -228,7 +228,6 @@ static int __devexit pata_platform_remove(struct platform_device *pdev)
 	struct ata_host *host = dev_get_drvdata(dev);
 
 	ata_host_detach(host);
-	dev_set_drvdata(dev, NULL);
 
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] libata: clear drvdata in ata_host_release()
  2007-02-24  7:48 [PATCH] libata: clear drvdata in ata_host_release() Tejun Heo
@ 2007-02-24 13:57 ` Alan
  2007-02-25  1:51 ` Jeff Garzik
  1 sibling, 0 replies; 6+ messages in thread
From: Alan @ 2007-02-24 13:57 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Jeff Garzik, linux-ide

On Sat, 24 Feb 2007 16:48:23 +0900
Tejun Heo <htejun@gmail.com> wrote:

> ata_host_release() uses drvdata to determine ata_host to release and
> clearing drvdata in ->remove_one causes NULL pointer deference.  Clear
> drvdata only in ata_host_release() after all resources are freed.
> 
> This bug was first analyzed by Alan Cox for pata_pcmcia.
> 
> Signed-off-by: Tejun Heo <htejun@gmail.com>
> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
>

Acked-by: Alan Cox <alan@redhat.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] libata: clear drvdata in ata_host_release()
  2007-02-24  7:48 [PATCH] libata: clear drvdata in ata_host_release() Tejun Heo
  2007-02-24 13:57 ` Alan
@ 2007-02-25  1:51 ` Jeff Garzik
  2007-02-25 13:28   ` Alan
  2007-02-27 13:33   ` [PATCH] libata: clear drvdata in ata_host_release(), take#2 Tejun Heo
  1 sibling, 2 replies; 6+ messages in thread
From: Jeff Garzik @ 2007-02-25  1:51 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Alan Cox, linux-ide, Linux Kernel Mailing List, Komuro

Tejun Heo wrote:
> ata_host_release() uses drvdata to determine ata_host to release and
> clearing drvdata in ->remove_one causes NULL pointer deference.  Clear
> drvdata only in ata_host_release() after all resources are freed.
> 
> This bug was first analyzed by Alan Cox for pata_pcmcia.
> 
> Signed-off-by: Tejun Heo <htejun@gmail.com>
> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
> ---
> Alan, this is the bug you talked about, right?  I took the fix from
> "[BUG] PATA_PCMCIA does not work" and expanded it.  If this isn't the
> one, please let me know.  Thanks.

Has a tester confirmed that this patch fixes the problem, and supercedes 
Alan's patch?

	Jeff



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] libata: clear drvdata in ata_host_release()
  2007-02-25  1:51 ` Jeff Garzik
@ 2007-02-25 13:28   ` Alan
  2007-02-27 13:33   ` [PATCH] libata: clear drvdata in ata_host_release(), take#2 Tejun Heo
  1 sibling, 0 replies; 6+ messages in thread
From: Alan @ 2007-02-25 13:28 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Tejun Heo, linux-ide, Linux Kernel Mailing List, Komuro

On Sat, 24 Feb 2007 20:51:27 -0500
Jeff Garzik <jeff@garzik.org> wrote:

> Tejun Heo wrote:
> > ata_host_release() uses drvdata to determine ata_host to release and
> > clearing drvdata in ->remove_one causes NULL pointer deference.  Clear
> > drvdata only in ata_host_release() after all resources are freed.
> > 
> > This bug was first analyzed by Alan Cox for pata_pcmcia.
> > 
> > Signed-off-by: Tejun Heo <htejun@gmail.com>
> > Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
> > ---
> > Alan, this is the bug you talked about, right?  I took the fix from
> > "[BUG] PATA_PCMCIA does not work" and expanded it.  If this isn't the
> > one, please let me know.  Thanks.
> 
> Has a tester confirmed that this patch fixes the problem, and supercedes 
> Alan's patch?

It doesn't appear to, instead it fixes further cases.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] libata: clear drvdata in ata_host_release(), take#2
  2007-02-25  1:51 ` Jeff Garzik
  2007-02-25 13:28   ` Alan
@ 2007-02-27 13:33   ` Tejun Heo
  2007-03-02  1:16     ` Jeff Garzik
  1 sibling, 1 reply; 6+ messages in thread
From: Tejun Heo @ 2007-02-27 13:33 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Alan Cox, linux-ide, Linux Kernel Mailing List, Komuro

Clearing drvdata in ->remove_one causes NULL pointer deference.  Clear
drvdata only in ata_host_release() after all resources are freed.

Signed-off-by: Tejun Heo <htejun@gmail.com>
---
pata_pcmcia is fixed by Alan's patch.  This fixes other drivers and
make libata always clear drvdata after detach.

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index bdde327..3bdb509 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -5680,6 +5680,8 @@ static void ata_host_release(struct device *gendev, void *res)
 
 	if (host->ops->host_stop)
 		host->ops->host_stop(host);
+
+	dev_set_drvdata(gendev, NULL);
 }
 
 /**
@@ -5902,7 +5904,6 @@ int ata_device_add(const struct ata_probe_ent *ent)
 
  err_out:
 	devres_release_group(dev, ata_device_add);
-	dev_set_drvdata(dev, NULL);
 	VPRINTK("EXIT, returning %d\n", rc);
 	return 0;
 }
diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
index c1334c6..8ff2d58 100644
--- a/drivers/ata/pata_cs5520.c
+++ b/drivers/ata/pata_cs5520.c
@@ -306,7 +306,6 @@ static void __devexit cs5520_remove_one(struct pci_dev *pdev)
 	struct ata_host *host = dev_get_drvdata(dev);
 
 	ata_host_detach(host);
-	dev_set_drvdata(dev, NULL);
 }
 
 /**
diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c
index d5f2e85..1a61cc8 100644
--- a/drivers/ata/pata_isapnp.c
+++ b/drivers/ata/pata_isapnp.c
@@ -128,7 +128,6 @@ static void isapnp_remove_one(struct pnp_dev *idev)
 	struct ata_host *host = dev_get_drvdata(dev);
 
 	ata_host_detach(host);
-	dev_set_drvdata(dev, NULL);
 }
 
 static struct pnp_device_id isapnp_devices[] = {
diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
index 02ea95f..4b82a54 100644
--- a/drivers/ata/pata_platform.c
+++ b/drivers/ata/pata_platform.c
@@ -228,7 +228,6 @@ static int __devexit pata_platform_remove(struct platform_device *pdev)
 	struct ata_host *host = dev_get_drvdata(dev);
 
 	ata_host_detach(host);
-	dev_set_drvdata(dev, NULL);
 
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] libata: clear drvdata in ata_host_release(), take#2
  2007-02-27 13:33   ` [PATCH] libata: clear drvdata in ata_host_release(), take#2 Tejun Heo
@ 2007-03-02  1:16     ` Jeff Garzik
  0 siblings, 0 replies; 6+ messages in thread
From: Jeff Garzik @ 2007-03-02  1:16 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Alan Cox, linux-ide, Linux Kernel Mailing List, Komuro

Tejun Heo wrote:
> Clearing drvdata in ->remove_one causes NULL pointer deference.  Clear
> drvdata only in ata_host_release() after all resources are freed.
> 
> Signed-off-by: Tejun Heo <htejun@gmail.com>
> ---
> pata_pcmcia is fixed by Alan's patch.  This fixes other drivers and
> make libata always clear drvdata after detach.

applied



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-03-02  1:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-24  7:48 [PATCH] libata: clear drvdata in ata_host_release() Tejun Heo
2007-02-24 13:57 ` Alan
2007-02-25  1:51 ` Jeff Garzik
2007-02-25 13:28   ` Alan
2007-02-27 13:33   ` [PATCH] libata: clear drvdata in ata_host_release(), take#2 Tejun Heo
2007-03-02  1:16     ` Jeff Garzik

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.