Skip to contentSkip to conversation

libata: clear drvdata in ata_host_release()

PATCH In review Tejun Heo 3 participants 6 messages Feb 24, 2007 – Mar 2, 2007 libata

lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

PATCH 1/1 libata: clear drvdata in ata_host_release()

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.

---
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.

drivers/ata/libata-core.c +2 -1
index d3b4e25..a705b38 100644
@@ -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;
 }
drivers/ata/pata_cs5520.c +0 -1
index b49d8b7..30e20fa 100644
@@ -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);
 }
 
 /**
drivers/ata/pata_isapnp.c +0 -1
index 1bf5ec1..e19cebf 100644
@@ -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[] = {
drivers/ata/pata_pcmcia.c +0 -1
index d10ae3e..4ef477c 100644
@@ -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;
drivers/ata/pata_platform.c +0 -1
index 02ea95f..4b82a54 100644
@@ -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;
 }
Acked-by Alan Cox on v1 1/1
#1 lore raw
Quoted 9 lines · On Sat, 24 Feb 2007 16:48:23 +0900 Tejun Heo <[email protected]> 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.

#2 lore raw
In reply to Tejun Heo
Quoted 4 lines · Tejun Heo

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.

Quoted 8 lines

This bug was first analyzed by Alan Cox for pata_pcmcia.

---
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

#3 lore raw
Quoted 14 lines · On Sat, 24 Feb 2007 20:51:27 -0500 Jeff Garzik <[email protected]> wrote:
Quoted 4 lines · Tejun Heo

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.

Quoted 8 lines

This bug was first analyzed by Alan Cox for pata_pcmcia.

---
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.

Quoted 2 lines

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.

author
#4 lore raw

PATCH 1/1 libata: clear drvdata in ata_host_release(), take#2

In reply to Jeff Garzik

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

---
pata_pcmcia is fixed by Alan's patch. This fixes other drivers and make libata always clear drvdata after detach.

drivers/ata/libata-core.c +2 -1
index bdde327..3bdb509 100644
@@ -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;
 }
drivers/ata/pata_cs5520.c +0 -1
index c1334c6..8ff2d58 100644
@@ -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);
 }
 
 /**
drivers/ata/pata_isapnp.c +0 -1
index d5f2e85..1a61cc8 100644
@@ -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[] = {
drivers/ata/pata_platform.c +0 -1
index 02ea95f..4b82a54 100644
@@ -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;
 }
Applied
#5 lore raw

Re: [PATCH] libata: clear drvdata in ata_host_release(), take#2

Quoted 7 lines · Tejun Heo

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

---
pata_pcmcia is fixed by Alan's patch. This fixes other drivers and make libata always clear drvdata after detach.

applied