netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Krzysztof Halasa <khc@pm.waw.pl>
To: Jeff Garzik <jgarzik@pobox.com>
Cc: Maillist netdev <netdev@oss.sgi.com>,
	"David S. Miller" <davem@redhat.com>
Subject: Re: double-check me?
Date: 17 Aug 2003 22:58:31 +0200	[thread overview]
Message-ID: <m3n0e8uhl4.fsf@defiant.pm.waw.pl> (raw)
In-Reply-To: <3F3FBF50.8070207@pobox.com>

Jeff Garzik <jgarzik@pobox.com> 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

  reply	other threads:[~2003-08-17 20:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-17 17:45 double-check me? Jeff Garzik
2003-08-17 20:58 ` Krzysztof Halasa [this message]
2003-08-17 22:31   ` Jeff Garzik
2003-08-18 14:38     ` Jason Lunz
2003-08-18 14:41       ` Jeff Garzik
2003-08-17 21:34 ` Jason Lunz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3n0e8uhl4.fsf@defiant.pm.waw.pl \
    --to=khc@pm.waw.pl \
    --cc=davem@redhat.com \
    --cc=jgarzik@pobox.com \
    --cc=netdev@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).