From: David Lechner <david@lechnology.com>
To: William Breathitt Gray <vilhelm.gray@gmail.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: Mon, 10 Aug 2020 17:48:07 -0500 [thread overview]
Message-ID: <ca6337f5-b28b-a19e-735c-3cd124570c27@lechnology.com> (raw)
In-Reply-To: <20200809191500.GC6542@shinobu>
>>>>>
>>>>> 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)
{
...
}
next prev parent reply other threads:[~2020-08-10 22:48 UTC|newest]
Thread overview: 20+ 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 ` [PATCH v4 2/5] docs: counter: Update to reflect sysfs internalization William Breathitt Gray
2020-07-21 19:35 ` [PATCH v4 3/5] counter: Add character device interface William Breathitt Gray
2020-07-29 0:20 ` David Lechner
2020-07-30 22:49 ` David Lechner
2020-07-31 8:13 ` Alexandre Belloni
2020-08-02 21:11 ` William Breathitt Gray
2020-08-09 14:51 ` William Breathitt Gray
2020-08-10 23:02 ` David Lechner
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 ` [PATCH v4 5/5] counter: 104-quad-8: Add IRQ support for the ACCES 104-QUAD-8 William Breathitt Gray
2020-07-30 17:07 ` Syed Nayyar Waris
[not found] ` <e13d43849f68af8227c6aaa0ef672b459d47e9ab.1595358237.git.vilhelm.gray@gmail.com>
[not found] ` <7209ac3d-d1ca-1b4c-b22c-8d98b13742e2@lechnology.com>
[not found] ` <20200802210415.GA606173@shinobu>
2020-08-03 20:00 ` [PATCH v4 1/5] counter: Internalize sysfs interface code David Lechner
2020-08-09 13:42 ` Jonathan Cameron
2020-08-09 19:15 ` William Breathitt Gray
2020-08-10 22:48 ` David Lechner [this message]
2020-08-15 16:33 ` William Breathitt Gray
2020-08-09 13:48 ` [PATCH v4 0/5] Introduce the Counter character device interface Jonathan Cameron
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=ca6337f5-b28b-a19e-735c-3cd124570c27@lechnology.com \
--to=david@lechnology.com \
--cc=David.Laight@ACULAB.COM \
--cc=alexandre.belloni@bootlin.com \
--cc=alexandre.torgue@st.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 \
--cc=vilhelm.gray@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).