Re: [RFC] [PATCH] v4l2: use unsigned rather than enums in ioctl()structs

From: Mauro Carvalho Chehab
Date: Wed Apr 11 2012 - 16:08:20 EST


Em 11-04-2012 15:47, RÃmi Denis-Courmont escreveu:
> Hello,
>
> Le mercredi 11 avril 2012 20:02:00 Mauro Carvalho Chehab, vous avez Ãcrit :
>> Using unsigned instead of enum is not a good idea, from API POV, as
>> unsigned has different sizes on 32 bits and 64 bits.
>
> Fair enough. But then we can do that instead:
> typedef XXX __enum_t;
> where XXX is the unsigned integer with the right number of bits. Since Linux
> does not use short enums, this ought to work fine.

I forgot to comment about that on the last e-mail.

A solution close to the above one were already proposed:
http://www.spinics.net/lists/vfl/msg25707.html

There were also another proposal there that might solve:
http://www.spinics.net/lists/vfl/msg25702.html


Something like:

#if sizeof(enum) == 1
typedef u8 __enum_t;
#elif sizeof(enum) == 2
typedef u16 __enum_t;
#elif sizeof(enum) == 4
typedef u32 __enum_t;
#elif sizeof(enum) == 8
typedef u64 __enum_t;
#else
typedef enum __enum_t;
#endif

Can actually work. Not sure if I really like adding a typedef, but maybe
this is the less dirty way to fix it.

We'll need to properly test the v4l2-compat32 code, as it will need
to handle a different enum size on userspace. So, there, we'll likely
need to replace every enum with just "u32". Hmm... arm with 64 bits
(if/when added) may be an additional issue for the compat stuff.

Regards,
Mauro
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/