lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 29 Sep 2021 09:39:41 -0700
From:   Nathan Chancellor <nathan@...nel.org>
To:     Ido Schimmel <idosch@...dia.com>
Cc:     kernel test robot <lkp@...el.com>,
        "llvm@...ts.linux.dev" <llvm@...ts.linux.dev>,
        "kbuild-all@...ts.01.org" <kbuild-all@...ts.01.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        Jiri Pirko <jiri@...dia.com>
Subject: Re:
 drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c:2022:1: warning:
 unused function 'mlxsw_afa_sampler_mirror_agent_get'

Hi Ido,

On Wed, Sep 29, 2021 at 12:44:16PM +0300, Ido Schimmel wrote:
> On Tue, Sep 28, 2021 at 09:06:54PM +0300, kernel test robot wrote:
> > All warnings (new ones prefixed by >>):
> > 
> >    static inline u32 mlxsw_##_type##_##_cname##_##_iname##_get(const char ^
> >    <scratch space>:119:1: note: expanded from here
> >    mlxsw_afa_polcnt_c_p_get
> >    ^
> 
> I saw your reply to a similar issue here [1] and I got the impression
> that you are leading the LLVM-related efforts, so I thought I will
> consult with you regarding a possible solution.
> 
> The inline functions that clang is complaining about are generated by
> macros that make it easy to set/get fields in the payloads of
> configuration messages used to communicate with the device. It is
> possible that sometime we only set a field, but never retrieve its value
> such as in the warning above. This is very much intentional and not
> indicative of a function we forgot to remove.
> 
> The patch below [2] adds the "__maybe_unused" keyword to these macros
> and makes clang happy [3].
> 
> Is this acceptable or you suggest a different solution?

Yes, I would say this is a perfectly fine solution. The warning is there
to make you consider if you have forgotten to use or remove a function
depending on the context and if this is expected behavior, silencing the
compiler with the __maybe_unused attribute is the right thing to do. The
kernel does this for resume and suspend functions as CONFIG_PM might not
be set.

Cheers,
Nathan

> Thanks
> 
> [1] https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org/thread/TIUWC7KZVTHGJKIZ4M3LI3JJYVAAINJX/
> 
> [2]
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/item.h b/drivers/net/ethernet/mellanox/mlxsw/item.h
> index e92cadc98128..d2c8f436efb7 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/item.h
> +++ b/drivers/net/ethernet/mellanox/mlxsw/item.h
> @@ -290,13 +290,13 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = {			\
>  	.size = {.bits = _sizebits,},						\
>  	.name = #_type "_" #_cname "_" #_iname,					\
>  };										\
> -static inline u8								\
> +static inline u8 __maybe_unused							\
>  mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf, unsigned short index)\
>  {										\
>  	return __mlxsw_item_get8(buf, &__ITEM_NAME(_type, _cname, _iname),	\
>  				 index);					\
>  }										\
> -static inline void								\
> +static inline void __maybe_unused						\
>  mlxsw_##_type##_##_cname##_##_iname##_set(char *buf, unsigned short index,	\
>  					  u8 val)				\
>  {										\
> @@ -311,11 +311,13 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = {			\
>  	.size = {.bits = _sizebits,},						\
>  	.name = #_type "_" #_cname "_" #_iname,					\
>  };										\
> -static inline u16 mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf)	\
> +static inline u16 __maybe_unused						\
> +mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf)			\
>  {										\
>  	return __mlxsw_item_get16(buf, &__ITEM_NAME(_type, _cname, _iname), 0);	\
>  }										\
> -static inline void mlxsw_##_type##_##_cname##_##_iname##_set(char *buf, u16 val)\
> +static inline void __maybe_unused						\
> +mlxsw_##_type##_##_cname##_##_iname##_set(char *buf, u16 val)			\
>  {										\
>  	__mlxsw_item_set16(buf, &__ITEM_NAME(_type, _cname, _iname), 0, val);	\
>  }
> @@ -331,13 +333,13 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = {			\
>  	.size = {.bits = _sizebits,},						\
>  	.name = #_type "_" #_cname "_" #_iname,					\
>  };										\
> -static inline u16								\
> +static inline u16 __maybe_unused						\
>  mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf, unsigned short index)\
>  {										\
>  	return __mlxsw_item_get16(buf, &__ITEM_NAME(_type, _cname, _iname),	\
>  				  index);					\
>  }										\
> -static inline void								\
> +static inline void __maybe_unused						\
>  mlxsw_##_type##_##_cname##_##_iname##_set(char *buf, unsigned short index,	\
>  					  u16 val)				\
>  {										\
> @@ -352,11 +354,13 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = {			\
>  	.size = {.bits = _sizebits,},						\
>  	.name = #_type "_" #_cname "_" #_iname,					\
>  };										\
> -static inline u32 mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf)	\
> +static inline u32 __maybe_unused						\
> +mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf)			\
>  {										\
>  	return __mlxsw_item_get32(buf, &__ITEM_NAME(_type, _cname, _iname), 0);	\
>  }										\
> -static inline void mlxsw_##_type##_##_cname##_##_iname##_set(char *buf, u32 val)\
> +static inline void __maybe_unused						\
> +mlxsw_##_type##_##_cname##_##_iname##_set(char *buf, u32 val)			\
>  {										\
>  	__mlxsw_item_set32(buf, &__ITEM_NAME(_type, _cname, _iname), 0, val);	\
>  }
> @@ -372,13 +376,13 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = {			\
>  	.size = {.bits = _sizebits,},						\
>  	.name = #_type "_" #_cname "_" #_iname,					\
>  };										\
> -static inline u32								\
> +static inline u32 __maybe_unused						\
>  mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf, unsigned short index)\
>  {										\
>  	return __mlxsw_item_get32(buf, &__ITEM_NAME(_type, _cname, _iname),	\
>  				  index);					\
>  }										\
> -static inline void								\
> +static inline void __maybe_unused						\
>  mlxsw_##_type##_##_cname##_##_iname##_set(char *buf, unsigned short index,	\
>  					  u32 val)				\
>  {										\
> @@ -393,11 +397,13 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = {			\
>  	.size = {.bits = _sizebits,},						\
>  	.name = #_type "_" #_cname "_" #_iname,					\
>  };										\
> -static inline u64 mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf)	\
> +static inline u64 __maybe_unused						\
> +mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf)			\
>  {										\
>  	return __mlxsw_item_get64(buf, &__ITEM_NAME(_type, _cname, _iname), 0);	\
>  }										\
> -static inline void mlxsw_##_type##_##_cname##_##_iname##_set(char *buf, u64 val)\
> +static inline void __maybe_unused						\
> +mlxsw_##_type##_##_cname##_##_iname##_set(char *buf, u64 val)			\
>  {										\
>  	__mlxsw_item_set64(buf, &__ITEM_NAME(_type, _cname, _iname), 0,	val);	\
>  }
> @@ -413,13 +419,13 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = {			\
>  	.size = {.bits = _sizebits,},						\
>  	.name = #_type "_" #_cname "_" #_iname,					\
>  };										\
> -static inline u64								\
> +static inline u64 __maybe_unused						\
>  mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf, unsigned short index)\
>  {										\
>  	return __mlxsw_item_get64(buf, &__ITEM_NAME(_type, _cname, _iname),	\
>  				  index);					\
>  }										\
> -static inline void								\
> +static inline void __maybe_unused						\
>  mlxsw_##_type##_##_cname##_##_iname##_set(char *buf, unsigned short index,	\
>  					  u64 val)				\
>  {										\
> @@ -433,19 +439,19 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = {			\
>  	.size = {.bytes = _sizebytes,},						\
>  	.name = #_type "_" #_cname "_" #_iname,					\
>  };										\
> -static inline void								\
> +static inline void __maybe_unused						\
>  mlxsw_##_type##_##_cname##_##_iname##_memcpy_from(const char *buf, char *dst)	\
>  {										\
>  	__mlxsw_item_memcpy_from(buf, dst,					\
>  				 &__ITEM_NAME(_type, _cname, _iname), 0);	\
>  }										\
> -static inline void								\
> +static inline void __maybe_unused						\
>  mlxsw_##_type##_##_cname##_##_iname##_memcpy_to(char *buf, const char *src)	\
>  {										\
>  	__mlxsw_item_memcpy_to(buf, src,					\
>  			       &__ITEM_NAME(_type, _cname, _iname), 0);		\
>  }										\
> -static inline char *								\
> +static inline char * __maybe_unused						\
>  mlxsw_##_type##_##_cname##_##_iname##_data(char *buf)				\
>  {										\
>  	return __mlxsw_item_data(buf, &__ITEM_NAME(_type, _cname, _iname), 0);	\
> @@ -460,7 +466,7 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = {			\
>  	.size = {.bytes = _sizebytes,},						\
>  	.name = #_type "_" #_cname "_" #_iname,					\
>  };										\
> -static inline void								\
> +static inline void __maybe_unused						\
>  mlxsw_##_type##_##_cname##_##_iname##_memcpy_from(const char *buf,		\
>  						  unsigned short index,		\
>  						  char *dst)			\
> @@ -468,7 +474,7 @@ mlxsw_##_type##_##_cname##_##_iname##_memcpy_from(const char *buf,		\
>  	__mlxsw_item_memcpy_from(buf, dst,					\
>  				 &__ITEM_NAME(_type, _cname, _iname), index);	\
>  }										\
> -static inline void								\
> +static inline void __maybe_unused						\
>  mlxsw_##_type##_##_cname##_##_iname##_memcpy_to(char *buf,			\
>  						unsigned short index,		\
>  						const char *src)		\
> @@ -476,7 +482,7 @@ mlxsw_##_type##_##_cname##_##_iname##_memcpy_to(char *buf,			\
>  	__mlxsw_item_memcpy_to(buf, src,					\
>  			       &__ITEM_NAME(_type, _cname, _iname), index);	\
>  }										\
> -static inline char *								\
> +static inline char * __maybe_unused						\
>  mlxsw_##_type##_##_cname##_##_iname##_data(char *buf, unsigned short index)	\
>  {										\
>  	return __mlxsw_item_data(buf,						\
> @@ -491,14 +497,14 @@ static struct mlxsw_item __ITEM_NAME(_type, _cname, _iname) = {			\
>  	.size = {.bytes = _sizebytes,},						\
>  	.name = #_type "_" #_cname "_" #_iname,					\
>  };										\
> -static inline u8								\
> +static inline u8 __maybe_unused							\
>  mlxsw_##_type##_##_cname##_##_iname##_get(const char *buf, u16 index)		\
>  {										\
>  	return __mlxsw_item_bit_array_get(buf,					\
>  					  &__ITEM_NAME(_type, _cname, _iname),	\
>  					  index);				\
>  }										\
> -static inline void								\
> +static inline void __maybe_unused						\
>  mlxsw_##_type##_##_cname##_##_iname##_set(char *buf, u16 index, u8 val)		\
>  {										\
>  	return __mlxsw_item_bit_array_set(buf,					\
> 
> [3]
> $ make -j8 CC=clang C=2 W=1 drivers/net/ethernet/mellanox/mlxsw/                                                                                      
>   DESCEND bpf/resolve_btfids                                                          
>   DESCEND objtool                                                                     
>   CHECK   scripts/mod/empty.c                                                         
>   CALL    scripts/atomic/check-atomics.sh                                             
>   CALL    scripts/checksyscalls.sh                                                    
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/core.c              
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.c       
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/core_env.c     
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c       
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/core_thermal.c   
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/pci.c         
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/i2c.c         
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum.c     
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c         
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c    
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c  
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_router_xm.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum1_kvdl.c  
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum2_kvdl.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c 
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_ctcam.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_atcam.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum1_acl_tcam.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum2_acl_tcam.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_bloom_filter.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_flow.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_matchall.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_fid.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_ipip.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_actions.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_keys.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum1_mr_tcam.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum2_mr_tcam.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_mr_tcam.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_mr.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_nve.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_policer.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_dcb.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c
>   CHECK   drivers/net/ethernet/mellanox/mlxsw/minimal.c

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ