netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* question about drivers/net/cpmac.c
@ 2009-12-13 10:22 Julia Lawall
  2009-12-13 10:25 ` question about drivers/net/3c507.c Julia Lawall
  2009-12-13 10:39 ` question about drivers/net/cpmac.c David Miller
  0 siblings, 2 replies; 8+ messages in thread
From: Julia Lawall @ 2009-12-13 10:22 UTC (permalink / raw)
  To: florian, netdev

The function __devinit cpmac_probe in the file drivers/net/cpmac.c 
contains the following code:

memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));

Is it correct that the size of the pointer is what is wanted?

julia

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

* question about drivers/net/3c507.c
  2009-12-13 10:22 question about drivers/net/cpmac.c Julia Lawall
@ 2009-12-13 10:25 ` Julia Lawall
  2009-12-13 10:40   ` David Miller
  2009-12-13 10:39 ` question about drivers/net/cpmac.c David Miller
  1 sibling, 1 reply; 8+ messages in thread
From: Julia Lawall @ 2009-12-13 10:25 UTC (permalink / raw)
  To: netdev

The function __devinit cpmac_probe in the file drivers/net/3c507.c 
contains the following code:

       memcpy_toio(lp->base+SA_OFFSET, dev->dev_addr,
                  sizeof(dev->dev_addr));
 
Is it correct that the size of the pointer is what is wanted?

julia


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

* Re: question about drivers/net/cpmac.c
  2009-12-13 10:22 question about drivers/net/cpmac.c Julia Lawall
  2009-12-13 10:25 ` question about drivers/net/3c507.c Julia Lawall
@ 2009-12-13 10:39 ` David Miller
  2009-12-13 11:00   ` Julia Lawall
  1 sibling, 1 reply; 8+ messages in thread
From: David Miller @ 2009-12-13 10:39 UTC (permalink / raw)
  To: julia; +Cc: florian, netdev

From: Julia Lawall <julia@diku.dk>
Date: Sun, 13 Dec 2009 11:22:54 +0100 (CET)

> The function __devinit cpmac_probe in the file drivers/net/cpmac.c 
> contains the following code:
> 
> memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
> 
> Is it correct that the size of the pointer is what is wanted?

Everything that does sizeof(netdev->dev_addr) is a bug.

At some point we changed netdev->dev_addr from an array of chars to a
pointer to a dynamically allocated buffer.

So these cases worked before that change and need to be updated
in order to be correct.

Looking quickly there are a couple of these things under
drivers/net


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

* Re: question about drivers/net/3c507.c
  2009-12-13 10:25 ` question about drivers/net/3c507.c Julia Lawall
@ 2009-12-13 10:40   ` David Miller
  0 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2009-12-13 10:40 UTC (permalink / raw)
  To: julia; +Cc: netdev

From: Julia Lawall <julia@diku.dk>
Date: Sun, 13 Dec 2009 11:25:02 +0100 (CET)

> The function __devinit cpmac_probe in the file drivers/net/3c507.c 
> contains the following code:
> 
>        memcpy_toio(lp->base+SA_OFFSET, dev->dev_addr,
>                   sizeof(dev->dev_addr));
>  
> Is it correct that the size of the pointer is what is wanted?

Same as the cpmac.c case, needs to be fixed.

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

* Re: question about drivers/net/cpmac.c
  2009-12-13 10:39 ` question about drivers/net/cpmac.c David Miller
@ 2009-12-13 11:00   ` Julia Lawall
  2009-12-13 11:51     ` Ben Hutchings
  0 siblings, 1 reply; 8+ messages in thread
From: Julia Lawall @ 2009-12-13 11:00 UTC (permalink / raw)
  To: David Miller; +Cc: florian, netdev

On Sun, 13 Dec 2009, David Miller wrote:

> From: Julia Lawall <julia@diku.dk>
> Date: Sun, 13 Dec 2009 11:22:54 +0100 (CET)
> 
> > The function __devinit cpmac_probe in the file drivers/net/cpmac.c 
> > contains the following code:
> > 
> > memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
> > 
> > Is it correct that the size of the pointer is what is wanted?
> 
> Everything that does sizeof(netdev->dev_addr) is a bug.
> 
> At some point we changed netdev->dev_addr from an array of chars to a
> pointer to a dynamically allocated buffer.
> 
> So these cases worked before that change and need to be updated
> in order to be correct.
> 
> Looking quickly there are a couple of these things under
> drivers/net

Fixed how?  I looked a bit to find where the field was initialized, but it 
is just initialized to a field of something else, so it was not so 
clear what the size should be.

I found the following elsewhere:

memcmp(eth->h_dest, dev->dev_addr, dev->addr_len)

Could these cases be changed to use the addr_len field? On the other hand, 
only rtl8150.c contains any mention of the addr_len field.

        memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
	dbg("%s: Setting MAC address to ", netdev->name);
        for (i = 0; i < 5; i++)
                dbg("%02X:", netdev->dev_addr[i]);
        dbg("%02X\n", netdev->dev_addr[i]);
        /* Set the IDR registers. */
        set_registers(dev, IDR, sizeof(netdev->dev_addr), netdev->dev_addr);


julia

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

* Re: question about drivers/net/cpmac.c
  2009-12-13 11:00   ` Julia Lawall
@ 2009-12-13 11:51     ` Ben Hutchings
  2009-12-13 12:19       ` Florian Fainelli
  0 siblings, 1 reply; 8+ messages in thread
From: Ben Hutchings @ 2009-12-13 11:51 UTC (permalink / raw)
  To: Julia Lawall; +Cc: David Miller, florian, netdev

On Sun, 2009-12-13 at 12:00 +0100, Julia Lawall wrote:
> On Sun, 13 Dec 2009, David Miller wrote:
> 
> > From: Julia Lawall <julia@diku.dk>
> > Date: Sun, 13 Dec 2009 11:22:54 +0100 (CET)
> > 
> > > The function __devinit cpmac_probe in the file drivers/net/cpmac.c 
> > > contains the following code:
> > > 
> > > memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
> > > 
> > > Is it correct that the size of the pointer is what is wanted?
> > 
> > Everything that does sizeof(netdev->dev_addr) is a bug.
> > 
> > At some point we changed netdev->dev_addr from an array of chars to a
> > pointer to a dynamically allocated buffer.
> > 
> > So these cases worked before that change and need to be updated
> > in order to be correct.
> > 
> > Looking quickly there are a couple of these things under
> > drivers/net
> 
> Fixed how?  I looked a bit to find where the field was initialized, but it 
> is just initialized to a field of something else, so it was not so 
> clear what the size should be.
[...]

The size should be dev->addr_len (assuming that has already been
initialised) which will be ETH_ALEN for Ethernet devices.

Ben.

-- 
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.


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

* Re: question about drivers/net/cpmac.c
  2009-12-13 11:51     ` Ben Hutchings
@ 2009-12-13 12:19       ` Florian Fainelli
  2009-12-13 12:43         ` Julia Lawall
  0 siblings, 1 reply; 8+ messages in thread
From: Florian Fainelli @ 2009-12-13 12:19 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: Julia Lawall, David Miller, netdev

Le dimanche 13 décembre 2009 12:51:59, Ben Hutchings a écrit :
> On Sun, 2009-12-13 at 12:00 +0100, Julia Lawall wrote:
> > On Sun, 13 Dec 2009, David Miller wrote:
> > > From: Julia Lawall <julia@diku.dk>
> > > Date: Sun, 13 Dec 2009 11:22:54 +0100 (CET)
> > >
> > > > The function __devinit cpmac_probe in the file drivers/net/cpmac.c
> > > > contains the following code:
> > > >
> > > > memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
> > > >
> > > > Is it correct that the size of the pointer is what is wanted?
> > >
> > > Everything that does sizeof(netdev->dev_addr) is a bug.
> > >
> > > At some point we changed netdev->dev_addr from an array of chars to a
> > > pointer to a dynamically allocated buffer.
> > >
> > > So these cases worked before that change and need to be updated
> > > in order to be correct.
> > >
> > > Looking quickly there are a couple of these things under
> > > drivers/net
> >
> > Fixed how?  I looked a bit to find where the field was initialized, but
> > it is just initialized to a field of something else, so it was not so
> > clear what the size should be.
> 
> [...]
> 
> The size should be dev->addr_len (assuming that has already been
> initialised) which will be ETH_ALEN for Ethernet devices.

From arch/mips/include/asm/mach-ar7/ar7.h:

struct plat_cpmac_data {
[..]
        char dev_addr[6];
};

So this should be fine to either use ETH_ALEN or sizeof(pdata->dev_addr).
-- 
Best regards, Florian Fainelli
Email: florian@openwrt.org
Web: http://openwrt.org
IRC: [florian] on irc.freenode.net
-------------------------------

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

* Re: question about drivers/net/cpmac.c
  2009-12-13 12:19       ` Florian Fainelli
@ 2009-12-13 12:43         ` Julia Lawall
  0 siblings, 0 replies; 8+ messages in thread
From: Julia Lawall @ 2009-12-13 12:43 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: Ben Hutchings, David Miller, netdev

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1655 bytes --]

On Sun, 13 Dec 2009, Florian Fainelli wrote:

> Le dimanche 13 décembre 2009 12:51:59, Ben Hutchings a écrit :
> > On Sun, 2009-12-13 at 12:00 +0100, Julia Lawall wrote:
> > > On Sun, 13 Dec 2009, David Miller wrote:
> > > > From: Julia Lawall <julia@diku.dk>
> > > > Date: Sun, 13 Dec 2009 11:22:54 +0100 (CET)
> > > >
> > > > > The function __devinit cpmac_probe in the file drivers/net/cpmac.c
> > > > > contains the following code:
> > > > >
> > > > > memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
> > > > >
> > > > > Is it correct that the size of the pointer is what is wanted?
> > > >
> > > > Everything that does sizeof(netdev->dev_addr) is a bug.
> > > >
> > > > At some point we changed netdev->dev_addr from an array of chars to a
> > > > pointer to a dynamically allocated buffer.
> > > >
> > > > So these cases worked before that change and need to be updated
> > > > in order to be correct.
> > > >
> > > > Looking quickly there are a couple of these things under
> > > > drivers/net
> > >
> > > Fixed how?  I looked a bit to find where the field was initialized, but
> > > it is just initialized to a field of something else, so it was not so
> > > clear what the size should be.
> > 
> > [...]
> > 
> > The size should be dev->addr_len (assuming that has already been
> > initialised) which will be ETH_ALEN for Ethernet devices.
> 
> From arch/mips/include/asm/mach-ar7/ar7.h:
> 
> struct plat_cpmac_data {
> [..]
>         char dev_addr[6];
> };
> 
> So this should be fine to either use ETH_ALEN or sizeof(pdata->dev_addr).

Thanks.  I will send a patch later today.

julia

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

end of thread, other threads:[~2009-12-13 12:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-13 10:22 question about drivers/net/cpmac.c Julia Lawall
2009-12-13 10:25 ` question about drivers/net/3c507.c Julia Lawall
2009-12-13 10:40   ` David Miller
2009-12-13 10:39 ` question about drivers/net/cpmac.c David Miller
2009-12-13 11:00   ` Julia Lawall
2009-12-13 11:51     ` Ben Hutchings
2009-12-13 12:19       ` Florian Fainelli
2009-12-13 12:43         ` Julia Lawall

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