All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@redhat.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
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: Wed, 02 May 2012 19:17:30 -0300	[thread overview]
Message-ID: <4FA1B27A.2030405@redhat.com> (raw)
In-Reply-To: <201205022245.22585.hverkuil@xs4all.nl>

Hi Hans,

Em 02-05-2012 17:45, Hans Verkuil escreveu:
> 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.

"Most" is not enough. We need a solution for all.

Also, the usage of -fshort-enum compilation directive would cause a V4L2 application 
to not work.

  I've checked with a gcc developer: he said that,
C standard says that the type should be represented as an integer, but it does allow
that it could be represented by a sorter type, like char. Gcc also allows using larger
enumber types, as a compatible extension, but doesn't use (by default) sorter types,
except if packed attribute is used.

As we use __packed on several structs, this can cause troubles.

It seems that the compiler may also choose to use either signed or unsigned integers
for enums.

He also doesn't recommend to use enums for any bitfield, as this is not defined on
C standard, and the way GCC implements it can cause troubles.

I would prefer a simpler solution, but, after thinking for some time, we should really
do something like that. Yes, compat code sucks, but, on the long term, we'll get rid
of all those mess. If we don't do that, I'm sure that this problem will return back in
the future (as this is the second time it returned. If we had fixed it on that time,
all our problems would already be solved nowadays).

> 
> Note that I don't question that using u32 is better than using enums, but I
> really wonder if there is any need for all the conversions.

We can speed-up the conversions, with something like:

enum foo {
	BAR
};

if (sizeof(foo) != sizeof(u32))
	call_compat_logic().

I suspect that sizeof() won't work inside a macro. 

Regards,
Mauro

  parent reply	other threads:[~2012-05-02 22:17 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
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 [this message]
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=4FA1B27A.2030405@redhat.com \
    --to=mchehab@redhat.com \
    --cc=hverkuil@xs4all.nl \
    --cc=james.dutton@gmail.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --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.