2011-02-21 06:02:37

by Stephen Rothwell

[permalink] [raw]
Subject: linux-next: build warning after merge of the driver-core tree

Hi Greg,

After merging the driver-core tree, today's linux-next build (x86_64
allmodconfig) produced this warning:

drivers/net/dnet.c: In function 'dnet_mii_init':
drivers/net/dnet.c:340: warning: passing argument 1 of 'platform_set_drvdata' from incompatible pointer type
include/linux/platform_device.h:138: note: expected 'struct platform_device *' but argument is of type 'struct net_device *'

Revealed by commit 71d642908d4e8e7a2a4a6e0490432e719ff466d5 ("Driver
core: convert platform_{get,set}_drvdata to static inline functions").
Introduced by commit 4796417417a62e2ae83d92cb92e1ecf9ec67b5f5 ("dnet:
Dave DNET ethernet controller driver (updated)").
--
Cheers,
Stephen Rothwell [email protected]
http://www.canb.auug.org.au/~sfr/


Attachments:
(No filename) (764.00 B)
(No filename) (490.00 B)
Download all attachments

2011-02-21 06:32:03

by Greg KH

[permalink] [raw]
Subject: Re: linux-next: build warning after merge of the driver-core tree

On Mon, Feb 21, 2011 at 05:02:26PM +1100, Stephen Rothwell wrote:
> Hi Greg,
>
> After merging the driver-core tree, today's linux-next build (x86_64
> allmodconfig) produced this warning:
>
> drivers/net/dnet.c: In function 'dnet_mii_init':
> drivers/net/dnet.c:340: warning: passing argument 1 of 'platform_set_drvdata' from incompatible pointer type
> include/linux/platform_device.h:138: note: expected 'struct platform_device *' but argument is of type 'struct net_device *'
>
> Revealed by commit 71d642908d4e8e7a2a4a6e0490432e719ff466d5 ("Driver
> core: convert platform_{get,set}_drvdata to static inline functions").
> Introduced by commit 4796417417a62e2ae83d92cb92e1ecf9ec67b5f5 ("dnet:
> Dave DNET ethernet controller driver (updated)").

It sounds like the driver is wrong here :(

thanks,

greg k-h

2011-02-21 20:20:47

by Ilya Yanok

[permalink] [raw]
Subject: [PATCH] dnet: fix wrong use of platform_set_drvdata()

platform_set_drvdata() was used with argument of incorrect type and
could cause memory corruption. Moreover, because of not setting drvdata
in the correct place not all resources were freed upon module unload.

Signed-off-by: Ilya Yanok <[email protected]>
---
drivers/net/dnet.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dnet.c b/drivers/net/dnet.c
index 9d8a20b..8318ea0 100644
--- a/drivers/net/dnet.c
+++ b/drivers/net/dnet.c
@@ -337,8 +337,6 @@ static int dnet_mii_init(struct dnet *bp)
for (i = 0; i < PHY_MAX_ADDR; i++)
bp->mii_bus->irq[i] = PHY_POLL;

- platform_set_drvdata(bp->dev, bp->mii_bus);
-
if (mdiobus_register(bp->mii_bus)) {
err = -ENXIO;
goto err_out_free_mdio_irq;
@@ -863,6 +861,7 @@ static int __devinit dnet_probe(struct platform_device *pdev)
bp = netdev_priv(dev);
bp->dev = dev;

+ platform_set_drvdata(pdev, dev);
SET_NETDEV_DEV(dev, &pdev->dev);

spin_lock_init(&bp->lock);
--
1.7.4

2011-02-21 21:05:20

by Ilya Yanok

[permalink] [raw]
Subject: Re: linux-next: build warning after merge of the driver-core tree

Hi Stephen, Greg,

On 21.02.2011 09:02, Stephen Rothwell wrote:
> After merging the driver-core tree, today's linux-next build (x86_64
> allmodconfig) produced this warning:
>
> drivers/net/dnet.c: In function 'dnet_mii_init':
> drivers/net/dnet.c:340: warning: passing argument 1 of 'platform_set_drvdata' from incompatible pointer type
> include/linux/platform_device.h:138: note: expected 'struct platform_device *' but argument is of type 'struct net_device *'

It's actually a bug in the driver. Thanks for reporting. I'll send the
patch as a follow up.

Regards, Ilya.

2011-02-28 20:22:06

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] dnet: fix wrong use of platform_set_drvdata()

From: Ilya Yanok <[email protected]>
Date: Mon, 21 Feb 2011 21:20:30 +0100

> platform_set_drvdata() was used with argument of incorrect type and
> could cause memory corruption. Moreover, because of not setting drvdata
> in the correct place not all resources were freed upon module unload.
>
> Signed-off-by: Ilya Yanok <[email protected]>

Applied.