All of lore.kernel.org
 help / color / mirror / Atom feed
From: William Breathitt Gray <vilhelm.gray@gmail.com>
To: David Lechner <david@lechnology.com>
Cc: jic23@kernel.org, kamel.bouhara@bootlin.com,
	gwendal@chromium.org, alexandre.belloni@bootlin.com,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org, syednwaris@gmail.com,
	patrick.havelange@essensium.com, fabrice.gasnier@st.com,
	mcoquelin.stm32@gmail.com, alexandre.torgue@st.com,
	David.Laight@ACULAB.COM
Subject: Re: [PATCH v4 1/5] counter: Internalize sysfs interface code
Date: Sat, 15 Aug 2020 12:33:11 -0400	[thread overview]
Message-ID: <20200815163255.GA6974@shinobu> (raw)
In-Reply-To: <ca6337f5-b28b-a19e-735c-3cd124570c27@lechnology.com>

[-- Attachment #1: Type: text/plain, Size: 4127 bytes --]

On Mon, Aug 10, 2020 at 05:48:07PM -0500, David Lechner wrote:
> 
> >>>>>     
> >>>>>     CPMAC ETHERNET DRIVER
> >>>>>     M:	Florian Fainelli <f.fainelli@gmail.com>
> >>>>> diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
> >>>>> index 78766b6ec271..0f20920073d6 100644
> >>>>> --- a/drivers/counter/104-quad-8.c
> >>>>> +++ b/drivers/counter/104-quad-8.c
> >>>>> @@ -621,7 +621,7 @@ static const struct iio_chan_spec quad8_channels[] = {
> >>>>>     };
> >>>>>     
> >>>>>     static int quad8_signal_read(struct counter_device *counter,
> >>>>> -	struct counter_signal *signal, enum counter_signal_value *val)
> >>>>> +			     struct counter_signal *signal, u8 *val)
> >>>>
> >>>> I'm not a fan of replacing enum types with u8 everywhere in this patch.
> >>>> But if we have to for technical reasons (e.g. causes compiler error if
> >>>> we don't) then it would be helpful to add comments giving the enum type
> >>>> everywhere like this instance where u8 is actually an enum value.
> >>>>
> >>>> If we use u32 as the generic type for enums instead of u8, I think the
> >>>> compiler will happlily let us use enum type and u32 interchangeably and
> >>>> not complain.
> >>>
> >>> I switched to fixed-width types after the suggestion by David Laight:
> >>> https://lkml.org/lkml/2020/5/3/159. I'll CC David Laight just in case he
> >>> wants to chime in again.
> >>>
> >>> Enum types would be nice for making the valid values explicit, but there
> >>> is one benefit I have appreciated from the move to fixed-width types:
> >>> there has been a significant reduction of duplicate code; before, we had
> >>> a different read function for each different enum type, but now we use a
> >>> single function to handle them all.
> >>
> >> Yes, what I was trying to explain is that by using u32 instead of u8, I
> >> think we can actually do both.
> >>
> >> The function pointers in struct counter_device *counter would use u32 as a
> >> generic enum value in the declaration, but then the actual implementations
> >> could still use the proper enum type.
> > 
> > Oh, I see what you mean now. So for example:
> > 
> >      int (*signal_read)(struct counter_device *counter,
> >                         struct counter_signal *signal, u8 *val)
> > 
> > This will become instead:
> > 
> >      int (*signal_read)(struct counter_device *counter,
> >                         struct counter_signal *signal, u32 *val)
> > 
> > Then in the driver callback implementation we use the enum type we need:
> > 
> >      enum counter_signal_level signal_level = COUNTER_SIGNAL_HIGH;
> >      ...
> >      *val = signal_level;
> > 
> > Is that what you have in mind?
> > 
> 
> Yes.
> 
> Additionally, if we have...
> 
> 
>        int (*x_write)(struct counter_device *counter,
>                       ..., u32 val)
>   
> We should be able to define the implementation as:
> 
> static int my_driver_x_write(struct counter_device *counter,
>                               ..., enum some_type val)
> {
> 	...
> }
> 
> Not sure if it works if val is a pointer though. Little-
> endian systems would probably be fine, but maybe not big-
> endian combined with -fshort-enums compiler flag.
> 
> 
>        int (*x_read)(struct counter_device *counter,
>                      ..., u32 *val)
>   
> 
> static int my_driver_x_read(struct counter_device *counter,
>                              ..., enum some_type *val)
> {
> 	...
> }

Regardless of endianness for pointers, will targets that have
-fshort-enums enabled by default present a problem here? I imagine that
in these cases enum some_type will have a size of unsigned char because
that is the first type that can represent all the values:
https://gcc.gnu.org/onlinedocs/gcc/Structures-unions-enumerations-and-bit-fields-implementation.html

What I'm worried about is whether we can gurantee u32 val can be swapped
out with enum some_type val -- or if this is not possible because some
architectures will be built with -fshort-enums enabled?

William Breathitt Gray

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: William Breathitt Gray <vilhelm.gray@gmail.com>
To: David Lechner <david@lechnology.com>
Cc: kamel.bouhara@bootlin.com, gwendal@chromium.org,
	alexandre.torgue@st.com, linux-iio@vger.kernel.org,
	patrick.havelange@essensium.com, alexandre.belloni@bootlin.com,
	linux-kernel@vger.kernel.org, David.Laight@ACULAB.COM,
	linux-arm-kernel@lists.infradead.org, mcoquelin.stm32@gmail.com,
	fabrice.gasnier@st.com, syednwaris@gmail.com,
	linux-stm32@st-md-mailman.stormreply.com, jic23@kernel.org
Subject: Re: [PATCH v4 1/5] counter: Internalize sysfs interface code
Date: Sat, 15 Aug 2020 12:33:11 -0400	[thread overview]
Message-ID: <20200815163255.GA6974@shinobu> (raw)
In-Reply-To: <ca6337f5-b28b-a19e-735c-3cd124570c27@lechnology.com>


[-- Attachment #1.1: Type: text/plain, Size: 4127 bytes --]

On Mon, Aug 10, 2020 at 05:48:07PM -0500, David Lechner wrote:
> 
> >>>>>     
> >>>>>     CPMAC ETHERNET DRIVER
> >>>>>     M:	Florian Fainelli <f.fainelli@gmail.com>
> >>>>> diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
> >>>>> index 78766b6ec271..0f20920073d6 100644
> >>>>> --- a/drivers/counter/104-quad-8.c
> >>>>> +++ b/drivers/counter/104-quad-8.c
> >>>>> @@ -621,7 +621,7 @@ static const struct iio_chan_spec quad8_channels[] = {
> >>>>>     };
> >>>>>     
> >>>>>     static int quad8_signal_read(struct counter_device *counter,
> >>>>> -	struct counter_signal *signal, enum counter_signal_value *val)
> >>>>> +			     struct counter_signal *signal, u8 *val)
> >>>>
> >>>> I'm not a fan of replacing enum types with u8 everywhere in this patch.
> >>>> But if we have to for technical reasons (e.g. causes compiler error if
> >>>> we don't) then it would be helpful to add comments giving the enum type
> >>>> everywhere like this instance where u8 is actually an enum value.
> >>>>
> >>>> If we use u32 as the generic type for enums instead of u8, I think the
> >>>> compiler will happlily let us use enum type and u32 interchangeably and
> >>>> not complain.
> >>>
> >>> I switched to fixed-width types after the suggestion by David Laight:
> >>> https://lkml.org/lkml/2020/5/3/159. I'll CC David Laight just in case he
> >>> wants to chime in again.
> >>>
> >>> Enum types would be nice for making the valid values explicit, but there
> >>> is one benefit I have appreciated from the move to fixed-width types:
> >>> there has been a significant reduction of duplicate code; before, we had
> >>> a different read function for each different enum type, but now we use a
> >>> single function to handle them all.
> >>
> >> Yes, what I was trying to explain is that by using u32 instead of u8, I
> >> think we can actually do both.
> >>
> >> The function pointers in struct counter_device *counter would use u32 as a
> >> generic enum value in the declaration, but then the actual implementations
> >> could still use the proper enum type.
> > 
> > Oh, I see what you mean now. So for example:
> > 
> >      int (*signal_read)(struct counter_device *counter,
> >                         struct counter_signal *signal, u8 *val)
> > 
> > This will become instead:
> > 
> >      int (*signal_read)(struct counter_device *counter,
> >                         struct counter_signal *signal, u32 *val)
> > 
> > Then in the driver callback implementation we use the enum type we need:
> > 
> >      enum counter_signal_level signal_level = COUNTER_SIGNAL_HIGH;
> >      ...
> >      *val = signal_level;
> > 
> > Is that what you have in mind?
> > 
> 
> Yes.
> 
> Additionally, if we have...
> 
> 
>        int (*x_write)(struct counter_device *counter,
>                       ..., u32 val)
>   
> We should be able to define the implementation as:
> 
> static int my_driver_x_write(struct counter_device *counter,
>                               ..., enum some_type val)
> {
> 	...
> }
> 
> Not sure if it works if val is a pointer though. Little-
> endian systems would probably be fine, but maybe not big-
> endian combined with -fshort-enums compiler flag.
> 
> 
>        int (*x_read)(struct counter_device *counter,
>                      ..., u32 *val)
>   
> 
> static int my_driver_x_read(struct counter_device *counter,
>                              ..., enum some_type *val)
> {
> 	...
> }

Regardless of endianness for pointers, will targets that have
-fshort-enums enabled by default present a problem here? I imagine that
in these cases enum some_type will have a size of unsigned char because
that is the first type that can represent all the values:
https://gcc.gnu.org/onlinedocs/gcc/Structures-unions-enumerations-and-bit-fields-implementation.html

What I'm worried about is whether we can gurantee u32 val can be swapped
out with enum some_type val -- or if this is not possible because some
architectures will be built with -fshort-enums enabled?

William Breathitt Gray

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-08-15 21:59 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-21 19:35 [PATCH v4 0/5] Introduce the Counter character device interface William Breathitt Gray
2020-07-21 19:35 ` William Breathitt Gray
2020-07-21 19:35 ` [PATCH v4 1/5] counter: Internalize sysfs interface code William Breathitt Gray
2020-07-28 22:45   ` David Lechner
2020-08-02 21:04     ` William Breathitt Gray
2020-08-03 20:00       ` David Lechner
2020-08-03 20:00         ` David Lechner
2020-08-09 13:42         ` Jonathan Cameron
2020-08-09 13:42           ` Jonathan Cameron
2020-08-09 19:15         ` William Breathitt Gray
2020-08-09 19:15           ` William Breathitt Gray
2020-08-10 22:48           ` David Lechner
2020-08-10 22:48             ` David Lechner
2020-08-15 16:33             ` William Breathitt Gray [this message]
2020-08-15 16:33               ` William Breathitt Gray
2020-07-21 19:35 ` [PATCH v4 2/5] docs: counter: Update to reflect sysfs internalization William Breathitt Gray
2020-07-21 19:35   ` William Breathitt Gray
2020-07-21 19:35 ` [PATCH v4 3/5] counter: Add character device interface William Breathitt Gray
2020-07-21 19:35   ` William Breathitt Gray
2020-07-29  0:20   ` David Lechner
2020-07-29  0:20     ` David Lechner
2020-07-30 22:49     ` David Lechner
2020-07-30 22:49       ` David Lechner
2020-07-31  8:13       ` Alexandre Belloni
2020-07-31  8:13         ` Alexandre Belloni
2020-08-02 21:11       ` William Breathitt Gray
2020-08-02 21:11         ` William Breathitt Gray
2020-08-09 14:51     ` William Breathitt Gray
2020-08-09 14:51       ` William Breathitt Gray
2020-08-10 23:02       ` David Lechner
2020-08-10 23:02         ` David Lechner
2020-08-15 17:23         ` William Breathitt Gray
2020-08-15 17:23           ` William Breathitt Gray
2020-07-21 19:35 ` [PATCH v4 4/5] docs: counter: Document " William Breathitt Gray
2020-07-21 19:35   ` William Breathitt Gray
2020-07-21 19:35 ` [PATCH v4 5/5] counter: 104-quad-8: Add IRQ support for the ACCES 104-QUAD-8 William Breathitt Gray
2020-07-21 19:35   ` William Breathitt Gray
2020-07-30 17:07   ` Syed Nayyar Waris
2020-07-30 17:07     ` Syed Nayyar Waris
2020-08-09 13:48 ` [PATCH v4 0/5] Introduce the Counter character device interface Jonathan Cameron
2020-08-09 13:48   ` Jonathan Cameron
2020-08-09 17:51   ` William Breathitt Gray
2020-08-09 17:51     ` William Breathitt Gray

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=20200815163255.GA6974@shinobu \
    --to=vilhelm.gray@gmail.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=alexandre.belloni@bootlin.com \
    --cc=alexandre.torgue@st.com \
    --cc=david@lechnology.com \
    --cc=fabrice.gasnier@st.com \
    --cc=gwendal@chromium.org \
    --cc=jic23@kernel.org \
    --cc=kamel.bouhara@bootlin.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=patrick.havelange@essensium.com \
    --cc=syednwaris@gmail.com \
    /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.