From: Pavel Machek <pavel@ucw.cz>
To: Julia Lawall <julia@diku.dk>
Cc: tglx@linutronix.de, viro@ftp.linux.org.uk,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 1/3] arch/x86: Use offsetof
Date: Wed, 26 Dec 2007 20:47:18 +0100 [thread overview]
Message-ID: <20071226194718.GB8844@elf.ucw.cz> (raw)
In-Reply-To: <Pine.LNX.4.58.0712261712450.1185@pc-041.diku.dk>
Hi!
> From: Julia Lawall <julia@diku.dk>
>
> In the patch cc154ac64aa8d3396b187f64cef01ce67f433324, Al Viro observed
> that the proper way to compute the distance between two structure fields is
> to use offsetof() or a cast to a pointer to character. The same change can
> be applied to a few more files.
>
> The change was made using the following semantic patch
> (http://www.emn.fr/x-info/coccinelle/)
>
> // <smpl>
> @r@
> type T;
> T s;
> type T1, T2;
> identifier fld1, fld2;
> typedef uint8_t;
> typedef u8;
> @@
>
> (
> (char *)&s.fld1 - (char *)&s.fld2
> |
> (uint8_t *)&s.fld1 - (uint8_t *)&s.fld2
> |
> (u8 *)&s.fld1 - (u8 *)&s.fld2
> |
> - (T1)&s.fld1 - (T2)&s.fld2
> + offsetof(T,fld1) - offsetof(T,fld2)
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <julia@diku.dk>
> ---
>
> diff -u -p a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
> --- a/arch/x86/kernel/vm86_32.c 2007-10-22 11:25:00.000000000 +0200
> +++ b/arch/x86/kernel/vm86_32.c 2007-12-26 16:27:15.000000000 +0100
> @@ -215,7 +215,9 @@ asmlinkage int sys_vm86old(struct pt_reg
> ret = -EFAULT;
> if (tmp)
> goto out;
> - memset(&info.vm86plus, 0, (int)&info.regs32 - (int)&info.vm86plus);
> + memset(&info.vm86plus, 0,
> + offsetof(struct kernel_vm86_struct, regs32) -
> + offsetof(struct kernel_vm86_struct, vm86plus));
I do not think this makes it more readable... (int) -> (char *) would
make it portable and readable, AFAICT.
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
next prev parent reply other threads:[~2007-12-26 19:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-26 16:13 Julia Lawall
2007-12-26 19:47 ` Pavel Machek [this message]
2007-12-27 1:01 ` H. Peter Anvin
2007-12-27 1:17 ` Al Viro
2007-12-27 1:21 ` H. Peter Anvin
2007-12-30 13:54 ` Ingo Molnar
2007-12-27 1:44 ` Jan Engelhardt
2007-12-27 1:49 ` H. Peter Anvin
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=20071226194718.GB8844@elf.ucw.cz \
--to=pavel@ucw.cz \
--cc=julia@diku.dk \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=viro@ftp.linux.org.uk \
/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
all inboxes | Powered by JetHome®