RE: [PATCH 0/4] Introduce the Counter character device interface
From: David Laight
Date: Sun May 03 2020 - 10:21:42 EST
From: Jonathan Cameron
> Sent: 03 May 2020 15:13
...
> > The following are some questions I have about this patchset:
> >
> > 1. Should enums be used to represent standard counter component states
> > (e.g. COUNTER_SIGNAL_LOW), or would these be better defined as int?
> >
> > These standard counter component states are defined in the
> > counter-types.h file and serve as constants used by counter device
> > drivers and Counter subsystem components in order to ensure a
> > consistent interface.
> >
> > My concern is whether enum constants will cause problems when passed
> > to userspace via the Counter character device ioctl calls. Along the
> > same lines is whether the C bool datatype is safe to pass as well,
> > given that it is a more modern C datatype.
>
> For enums, I'd pass them as integers.
>
> Bool is probably fine either way.
Always use fixed size types in any API structures.
Ensure that fields are always on their natural boundaries.
So no enums and no bools.
It may even be worth using uint64_t for any userspace pointers.
At some point you'll live to regret anything else.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)