Skip to contentSkip to conversation

korina: fix probing crash

PATCH Applied Florian Fainelli 4 participants 6 messages Jan 11, 2009 – Jan 29, 2009 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 korina: fix probing crash

From: Florian Fainelli <[email protected]>
Subject: [PATCH] korina: fix probing crash

This patch fixes the wrong retrieval of platform_data which makes the driver crash on probe. Propagate error if the platform_driver cannot use its data.

---

drivers/net/korina.c +7 -1
index e185763..b2a3949 100644
@@ -1078,12 +1078,18 @@ static int korina_close(struct net_device *dev)
 
 static int korina_probe(struct platform_device *pdev)
 {
-	struct korina_device *bif = platform_get_drvdata(pdev);
+	struct korina_device *bif;
 	struct korina_private *lp;
 	struct net_device *dev;
 	struct resource *r;
 	int rc;
 
+	bif = (struct korina_device *)pdev->dev.platform_data;
+	if (!bif) {
+		printk(KERN_ERR DRV_NAME ": missing platform data\n");
+		return -ENODEV;
+	}
+
 	dev = alloc_etherdev(sizeof(struct korina_private));
 	if (!dev) {
 		printk(KERN_ERR DRV_NAME ": alloc_etherdev failed\n");
maintainer
#1 lore raw

From: Florian Fainelli <[email protected]>
Date: Sun, 11 Jan 2009 16:54:24 +0100

Quoted 7 lines

korina: fix probing crash

This patch fixes the wrong retrieval of platform_data which makes the driver crash on probe. Propagate error if the platform_driver cannot use its data.

There are several problems with this patch:

drivers/net/korina.c static int korina_close(struct net_device *dev) · line 1087

Quoted 12 lines
drivers/net/korina.c +2 -1
@@ -1078,12 +1078,18 @@ static int korina_close(struct net_device *dev)
 
 static int korina_probe(struct platform_device *pdev)
 {
-	struct korina_device *bif = platform_get_drvdata(pdev);
+	struct korina_device *bif;
 	struct korina_private *lp;
 	struct net_device *dev;
 	struct resource *r;
 	int rc;
 
+	bif = (struct korina_device *)pdev->dev.platform_data;

This cast is unnecessary, platform_data is "void *"

Secondly, korina_remove() also expects the korina_device pointer to be in the platform drvdata. It therefore has the same bug as korina_probe() and needs to be fixed too.

But I suspect there is some other weird problem here. If you need to change from drvdata over to platform_data, then this driver never could have been probed or removed properly.

This is absolutely a fundamental bug, where did it come from?

A message that is not in the archive (sent off-list or not yet received): [email protected]

author Acked-by
#3 lore raw

Re: [PATCH] MIPS: rb532: use driver_data instead of platform_data

Le Wednesday 14 January 2009 18:41:14 Phil Sutter, vous avez écrit :

Quoted 3 lines

As the korina ethernet driver uses platform_get_drvdata() to extract the driver specific data from the platform device, driver_data has to be used here.

Right, thanks for changing this.

Quoted 2 lines
Signature · 4 lines
Best regards, Florian Fainelli
Email : [email protected]
http://openwrt.org
-------------------------------

A message that is not in the archive (sent off-list or not yet received): [email protected]

maintainer Applied
#5 lore raw

Re: [PATCH] korina: fix usage of driver_data

From: Phil Sutter <[email protected]>
Date: Wed, 14 Jan 2009 18:47:21 +0100

Quoted 6 lines

Using platform_set_drvdata() here makes no sense, since the driver_data field has already been filled with valuable data (i.e. the MAC address). Also having driver_data point to the net_device is rather pointless since struct korina_device contains an apropriate field for it.

Applied.

#6 lore raw

PATCH 1/1 MIPS: rb532: use driver_data instead of platform_data

In reply to David Miller

As the korina ethernet driver uses platform_get_drvdata() to extract the driver specific data from the platform device, driver_data has to be used here.

---
 arch/mips/rb532/devices.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/mips/rb532/devices.c +1 -1
index 9b6b744..3c74561 100644
@@ -89,7 +89,7 @@ static struct korina_device korina_dev0_data = {
 static struct platform_device korina_dev0 = {
 	.id = -1,
 	.name = "korina",
-	.dev.platform_data = &korina_dev0_data,
+	.dev.driver_data = &korina_dev0_data,
 	.resource = korina_dev0_res,
 	.num_resources = ARRAY_SIZE(korina_dev0_res),
 };
Signature · 1 line
1.5.6.4
Applied
#7 lore raw

Re: [PATCH] MIPS: rb532: use driver_data instead of platform_data

On Thu, Jan 15, 2009 at 03:41:44PM +0100, Phil Sutter wrote:

Applied. Thanks,

Ralf