netdev
[Top] [All Lists]

Re: double-check me?

To: Krzysztof Halasa <khc@xxxxxxxxx>
Subject: Re: double-check me?
From: Jeff Garzik <jgarzik@xxxxxxxxx>
Date: Sun, 17 Aug 2003 18:31:02 -0400
Cc: Maillist netdev <netdev@xxxxxxxxxxx>, "David S. Miller" <davem@xxxxxxxxxx>
In-reply-to: <m3n0e8uhl4.fsf@defiant.pm.waw.pl>
Organization: none
References: <3F3FBF50.8070207@pobox.com> <m3n0e8uhl4.fsf@defiant.pm.waw.pl>
Sender: netdev-bounce@xxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021213 Debian/1.2.1-2.bunk
Krzysztof Halasa wrote:
Jeff Garzik <jgarzik@xxxxxxxxx> writes:


Maybe you guys can spot something I'm missing here.  alloc_netdev is
supposed to guarantee that dev->priv is aligned by 32 bytes:

        struct net_device *dev;

        if (sizeof_priv)
                dev->priv = (void *) (((long)(dev + 1) + 31) & ~31);


Now... shouldn't that last line of code be "dev + 1 + sizeof(*dev)" ?

It seems to work 2.[456] for a long time, so I am doubting
myself... surely it would have caused memory corruption or something
by now if I have really found a bug.


Looks ok... not very readable, though.

dev + 1 = ((u8*)dev) + sizeof(dev) = pointer to end of net_device struct.


C pointer arithmatic.  Ok, duh, thanks :)

        Jeff, too used to void pointer arith



<Prev in Thread] Current Thread [Next in Thread>