All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: Mauro Carvalho Chehab <mchehab@redhat.com>
Cc: Sakari Ailus <sakari.ailus@iki.fi>,
	linux-media@vger.kernel.org, laurent.pinchart@ideasonboard.com,
	remi@remlab.net, nbowler@elliptictech.com,
	james.dutton@gmail.com
Subject: Re: [RFC v3 1/2] v4l: Do not use enums in IOCTL structs
Date: Thu, 3 May 2012 16:12:07 +0200	[thread overview]
Message-ID: <201205031612.07952.hverkuil@xs4all.nl> (raw)
In-Reply-To: <4FA28B56.1070801@redhat.com>

On Thursday 03 May 2012 15:42:46 Mauro Carvalho Chehab wrote:
> Em 03-05-2012 04:02, Hans Verkuil escreveu:
> > On Wed May 2 2012 23:39:15 Sakari Ailus wrote:
> >> Hi Hans,
> >>
> >> On Wed, May 02, 2012 at 10:45:22PM +0200, Hans Verkuil wrote:
> >>> On Wed May 2 2012 21:13:47 Sakari Ailus wrote:
> >>>> Replace enums in IOCTL structs by __u32. The size of enums is variable and
> >>>> thus problematic. Compatibility structs having exactly the same as original
> >>>> definition are provided for compatibility with old binaries with the
> >>>> required conversion code.
> >>>
> >>> Does someone actually have hard proof that there really is a problem? You know,
> >>> demonstrate it with actual example code?
> >>>
> >>> It's pretty horrible that you have to do all those conversions and that code
> >>> will be with us for years to come.
> >>>
> >>> For most (if not all!) architectures sizeof(enum) == sizeof(u32), so there is
> >>> no need for any compat code for those.
> >>
> >> Cases I know where this can go wrong are, but there may well be others:
> >>
> >> - ppc64: int is 64 bits there, and thus also enums,
> > 
> > Are you really, really certain that's the case? If I look at
> > arch/powerpc/include/asm/types.h it includes either asm-generic/int-l64.h
> > or asm-generic/int-ll64.h and both of those headers define u32 as unsigned int.
> > Also, if sizeof(int) != 4, then how would you define u32?
> > 
> > Ask a ppc64 kernel maintainer what sizeof(int) and sizeof(enum) are in the kernel
> > before we start doing lots of work for no reason.
> > 
> > Looking at arch/*/include/asm/types.h it seems all architectures define sizeof(int)
> > as 4.
> > 
> > What sizeof(long) is will actually differ between architectures, but char, short
> > and int seem to be fixed everywhere.
> 
> Yes, it seems that, inside the Kernel, "int" it will always be 32 bits. It doesn't
> necessarily means that "enum" will be 32 bits.

Actually, I believe it is. It is my understanding that --short-enums is not allowed
inside the kernel and so enums are the same size as int. But I'd like to have some
confirmation about that first. That compiler option isn't used anywhere in the kernel
in any case and gcc on ARM will default to int-sized enums on linux.

So just changing all the enums in videodev2.h to u32 should almost certainly be all
we need to do.

> Also, as it is recommended to not use "int/unsigned int/long/unsigned long" at 
> kernel<->userspace API, I bet that this will cause problems on userspace (maybe
> with non-gcc compilers?)

'long' is certainly known to change size depending on the compiler. 'int' can be
two bytes on *really* old hardware/compilers.

struct v4l2_jpegcompression is the only place where int is still used. I wouldn't
mind if that changes to u32 at the same time (those ints should have been unsigned
anyway).

Regards,

	Hans

  reply	other threads:[~2012-05-03 14:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-02 19:13 [RFC v2 0/2] V4L2 IOCTL enum compat wrapper Sakari Ailus
2012-05-02 19:13 ` [RFC v3 1/2] v4l: Do not use enums in IOCTL structs Sakari Ailus
2012-05-02 20:45   ` Hans Verkuil
2012-05-02 21:39     ` Sakari Ailus
2012-05-03  7:02       ` Hans Verkuil
2012-05-03 13:42         ` Mauro Carvalho Chehab
2012-05-03 14:12           ` Hans Verkuil [this message]
2012-05-03 10:57       ` Rémi Denis-Courmont
2012-05-03 10:58         ` Rémi Denis-Courmont
2012-05-03 12:20           ` Sakari Ailus
2012-05-02 22:17     ` Mauro Carvalho Chehab
2012-05-03  0:42       ` Andy Walls
2012-05-03 10:22         ` Mauro Carvalho Chehab
2012-05-03 10:35           ` Sakari Ailus
2012-05-03 12:07             ` Mauro Carvalho Chehab
2012-05-03 10:45           ` Sylwester Nawrocki
2012-05-03 23:02           ` Andy Walls
2012-05-03 10:39         ` Mauro Carvalho Chehab
2012-05-02 19:13 ` [RFC v3 2/2] v4l: Implement compat functions for enum to __u32 change Sakari Ailus
2012-05-02 22:32   ` Mauro Carvalho Chehab
2012-05-02 23:38     ` Laurent Pinchart
2012-05-03 12:20       ` Mauro Carvalho Chehab

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=201205031612.07952.hverkuil@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=james.dutton@gmail.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@redhat.com \
    --cc=nbowler@elliptictech.com \
    --cc=remi@remlab.net \
    --cc=sakari.ailus@iki.fi \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.