Thread (6 messages) flat view 6 messages, 3 authors, 2003-08-18

Re: double-check me?

From: Krzysztof Halasa <khc@pm.waw.pl>
Date: 2003-08-17 20:58:31

Jeff Garzik [off-list ref] 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.

(X + 31) & ~31 makes sure X is 32-bytes aligned (0-31 bytes are added).
Hope the alloc_size has enough space for this.

31 should be better 0x1F I think.

I also like sizeof(struct net_device) more than sizeof(*dev).

Why do you want "+ 1" if you add sizeof(*dev)?
-- 
Krzysztof Halasa
Network Administrator
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help