lkml.org 
[lkml]   [2015]   [Mar]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/2] move offsetofend() from vfio.h to stddef.h

* Denys Vlasenko <vda.linux@googlemail.com> wrote:

> On Mon, Mar 9, 2015 at 3:58 PM, Ingo Molnar <mingo@kernel.org> wrote:
> >> -/**
> >> - * offsetofend(TYPE, MEMBER)
> >> - *
> >> - * @TYPE: The type of the structure
> >> - * @MEMBER: The member within the structure to get the end offset of
> >> - *
> >> - * Simple helper macro for dealing with variable sized structures passed
> >> - * from user space. This allows us to easily determine if the provided
> >> - * structure is sized to include various fields.
> >> - */
> >> -#define offsetofend(TYPE, MEMBER) \
> >> - (offsetof(TYPE, MEMBER) + sizeof(((TYPE *)0)->MEMBER))
> >
> > So I like it, and because it is not particularly trivial when to use
> > this primitive it was explained nicely in a description in the vfio.h
> > version.
> >
> > But you lost that nice description during the code move!!
>
> That description was clearly specific to how that macro is used in
> drivers/vfio/*.c, along the lines of
>
> minsz = offsetofend(struct vfio_eeh_pe_op, op);

Hm, but here 'minsz' == sizeof(struct vfio_eeh_pe_op), so the vfio
usage does not seem to be justified.

> if (copy_from_user(&op, (void __user *)arg, minsz))
> return -EFAULT;
> if (op.argsz < minsz || op.flags)
> return -EINVAL;
>
> But the macro is generic, it has many other uses besides this one.

So I might be missing something, but what generic uses does it have,
beyond structures that have some rare size related weirdness, such as
alignment attributes? In 99% of the cases:

sizeof(struct) == offsetofend(struct, last_member)

right?

> Nevertheless, I can resend a version where comment survives if you
> want...

So maybe extend it to a description that you think describes its uses
correctly? People will keep wondering about when to use this.

Thanks,

Ingo


\
 
 \ /
  Last update: 2015-03-09 16:41    [W:3.152 / U:0.672 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site