[Linux-stm32] [PATCH 0/4] Introduce the Counter character device interface

Jonathan Cameron jic23 at kernel.org
Sun May 3 15:18:12 UTC 2020


On Sun, 3 May 2020 14:21:11 +0000
David Laight <David.Laight at ACULAB.COM> wrote:

> 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.

Fair point I'd forgotten that c still doesn't make bool a particular
size.  c99 defines it a 0 or 1, but not what the storage size is..

Jonathan



> 
> 	David
> 
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
> 




More information about the Linux-stm32 mailing list