From: Roger Quadros <rogerq@kernel.org>
To: Simon Horman <horms@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Siddharth Vadapalli <s-vadapalli@ti.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
netdev@vger.kernel.org, linux-omap@vger.kernel.org,
llvm@lists.linux.dev
Subject: Re: [PATCH net-next 3/3] net: ethernet: ti: cpsw_ale: Remove unused accessor functions
Date: Thu, 12 Sep 2024 13:54:45 +0300 [thread overview]
Message-ID: <97c7665c-d05f-4363-94c6-9ce89921096a@kernel.org> (raw)
In-Reply-To: <20240912085929.GF572255@kernel.org>
On 12/09/2024 11:59, Simon Horman wrote:
> On Thu, Sep 12, 2024 at 10:07:27AM +0300, Roger Quadros wrote:
>> Hi Simon,
>>
>> On 10/09/2024 10:17, Simon Horman wrote:
>>> W=1 builds flag that some accessor functions for ALE fields are unused.
>>>
>>> Address this by splitting up the macros used to define these
>>> accessors to allow only those that are used to be declared.
>>>
>>> The warnings are verbose, but for example, the mcast_state case is
>>> flagged by clang-18 as:
>>>
>>> .../cpsw_ale.c:220:1: warning: unused function 'cpsw_ale_get_mcast_state' [-Wunused-function]
>>> 220 | DEFINE_ALE_FIELD(mcast_state, 62, 2)
>>> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> .../cpsw_ale.c:145:19: note: expanded from macro 'DEFINE_ALE_FIELD'
>>> 145 | static inline int cpsw_ale_get_##name(u32 *ale_entry) \
>>> | ^~~~~~~~~~~~~~~~~~~
>>> <scratch space>:196:1: note: expanded from here
>>> 196 | cpsw_ale_get_mcast_state
>>> | ^~~~~~~~~~~~~~~~~~~~~~~~
>>>
>>> Compile tested only.
>>> No functional change intended.
>>>
>>> Signed-off-by: Simon Horman <horms@kernel.org>
>>> ---
>>> drivers/net/ethernet/ti/cpsw_ale.c | 30 +++++++++++++++++++++---------
>>> 1 file changed, 21 insertions(+), 9 deletions(-)
>>>
>>> diff --git a/drivers/net/ethernet/ti/cpsw_ale.c b/drivers/net/ethernet/ti/cpsw_ale.c
>>> index 64bf22cd860c..d37b4ddd6787 100644
>>> --- a/drivers/net/ethernet/ti/cpsw_ale.c
>>> +++ b/drivers/net/ethernet/ti/cpsw_ale.c
>>> @@ -141,27 +141,39 @@ static inline void cpsw_ale_set_field(u32 *ale_entry, u32 start, u32 bits,
>>> ale_entry[idx] |= (value << start);
>>> }
>>>
>>> -#define DEFINE_ALE_FIELD(name, start, bits) \
>>> +#define DEFINE_ALE_FIELD_GET(name, start, bits) \
>>> static inline int cpsw_ale_get_##name(u32 *ale_entry) \
>>> { \
>>> return cpsw_ale_get_field(ale_entry, start, bits); \
>>> -} \
>>> +}
>>> +
>>> +#define DEFINE_ALE_FIELD_SET(name, start, bits) \
>>> static inline void cpsw_ale_set_##name(u32 *ale_entry, u32 value) \
>>> { \
>>> cpsw_ale_set_field(ale_entry, start, bits, value); \
>>> }
>>>
>>> -#define DEFINE_ALE_FIELD1(name, start) \
>>> +#define DEFINE_ALE_FIELD(name, start, bits) \
>>> +DEFINE_ALE_FIELD_GET(name, start, bits) \
>>> +DEFINE_ALE_FIELD_SET(name, start, bits)
>>> +
>>> +#define DEFINE_ALE_FIELD1_GET(name, start) \
>>> static inline int cpsw_ale_get_##name(u32 *ale_entry, u32 bits) \
>>> { \
>>> return cpsw_ale_get_field(ale_entry, start, bits); \
>>> -} \
>>> +}
>>> +
>>> +#define DEFINE_ALE_FIELD1_SET(name, start) \
>>> static inline void cpsw_ale_set_##name(u32 *ale_entry, u32 value, \
>>> u32 bits) \
>>> { \
>>> cpsw_ale_set_field(ale_entry, start, bits, value); \
>>> }
>>>
>>> +#define DEFINE_ALE_FIELD1(name, start) \
>>> +DEFINE_ALE_FIELD1_GET(name, start) \
>>> +DEFINE_ALE_FIELD1_SET(name, start)
>>> +
>>> enum {
>>> ALE_ENT_VID_MEMBER_LIST = 0,
>>> ALE_ENT_VID_UNREG_MCAST_MSK,
>>> @@ -217,14 +229,14 @@ static const struct ale_entry_fld vlan_entry_k3_cpswxg[] = {
>>>
>>> DEFINE_ALE_FIELD(entry_type, 60, 2)
>>> DEFINE_ALE_FIELD(vlan_id, 48, 12)
>>> -DEFINE_ALE_FIELD(mcast_state, 62, 2)
>>> +DEFINE_ALE_FIELD_SET(mcast_state, 62, 2)
>>
>> I don't understand why we need separate macros for GET and SET.
>> The original intent was to use one macro for both.
>>
>> Otherwise we will have to add DEFINE_ALE_FIELD/1_SET to all the fields.
>
> Hi Roger,
>
> Sorry for not being clearer.
>
> My intent was to avoid declaring functions that are never used.
> Perhaps it is best explained by some examples.
>
> In the case of mcast_state, the compiler flags that the get accessor is
> never used. The intent is of this patch addresses that by declaring the set
> accessor for mcast_state. Likewise for other similar cases.
>
> OTOH, in the case of, f.e. vlan_id, the set and get accessor functions are
> both used, and DEFINE_ALE_FIELD continues to be used to define them both.
> DEFINE_ALE_FIELD is implemented as the combination of _SET and _GET.
>
Thanks for the explanation Simon. I understand now.
Would using __maybe_unused__ be preferable to get rid of the warnings?
That way we don't need to care if both set/get helpers are used or not
and don't have to touch the below code ever again except to add new fields.
>>
>>> DEFINE_ALE_FIELD1(port_mask, 66)
>>> DEFINE_ALE_FIELD(super, 65, 1)
>>> DEFINE_ALE_FIELD(ucast_type, 62, 2)
>>> -DEFINE_ALE_FIELD1(port_num, 66)
>>> -DEFINE_ALE_FIELD(blocked, 65, 1)
>>> -DEFINE_ALE_FIELD(secure, 64, 1)
>>> -DEFINE_ALE_FIELD(mcast, 40, 1)
>>> +DEFINE_ALE_FIELD1_SET(port_num, 66)
>>> +DEFINE_ALE_FIELD_SET(blocked, 65, 1)
>>> +DEFINE_ALE_FIELD_SET(secure, 64, 1)
>>> +DEFINE_ALE_FIELD_GET(mcast, 40, 1)
>>>
>>> #define NU_VLAN_UNREG_MCAST_IDX 1
>>>
>>>
>>
--
cheers,
-roger
next prev parent reply other threads:[~2024-09-12 10:54 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-10 7:17 [PATCH net-next 0/3] net: ethernet: ti: Address some warnings Simon Horman
2024-09-10 7:17 ` [PATCH net-next 1/3] net: ethernet: ti: am65-cpsw: Address __percpu Sparse warnings Simon Horman
2024-09-12 0:06 ` Jakub Kicinski
2024-09-12 9:58 ` Simon Horman
2024-09-12 15:45 ` Jakub Kicinski
2024-09-12 19:48 ` Simon Horman
2024-09-10 7:17 ` [PATCH net-next 2/3] net: ethernet: ti: am65-cpsw: Use __be64 type for id_temp Simon Horman
2024-09-10 8:42 ` Kalesh Anakkur Purayil
2024-09-12 7:10 ` Roger Quadros
2024-09-10 7:17 ` [PATCH net-next 3/3] net: ethernet: ti: cpsw_ale: Remove unused accessor functions Simon Horman
2024-09-12 7:07 ` Roger Quadros
2024-09-12 8:59 ` Simon Horman
2024-09-12 10:54 ` Roger Quadros [this message]
2024-09-12 11:27 ` Simon Horman
2024-09-12 13:29 ` Roger Quadros
2024-09-12 15:43 ` Simon Horman
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=97c7665c-d05f-4363-94c6-9ce89921096a@kernel.org \
--to=rogerq@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=justinstitt@google.com \
--cc=kuba@kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=s-vadapalli@ti.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).