diff mbox series

sfc: use IS_ENABLED() checks for CONFIG_SFC_SRIOV

Message ID 20230217095650.2305559-1-arnd@kernel.org (mailing list archive)
State Accepted
Commit a59f832a71c938779b8abdb022d6d39903e635c3
Delegated to: Netdev Maintainers
Headers show
Series sfc: use IS_ENABLED() checks for CONFIG_SFC_SRIOV | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 85 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Arnd Bergmann Feb. 17, 2023, 9:56 a.m. UTC
From: Arnd Bergmann <arnd@arndb.de>

One local variable has become unused after a recent change:

drivers/net/ethernet/sfc/ef100_nic.c: In function 'ef100_probe_netdev_pf':
drivers/net/ethernet/sfc/ef100_nic.c:1155:21: error: unused variable 'net_dev' [-Werror=unused-variable]
  struct net_device *net_dev = efx->net_dev;
                     ^~~~~~~

The variable is still used in an #ifdef. Replace the #ifdef with
an if(IS_ENABLED()) check that lets the compiler see where it is
used, rather than adding another #ifdef.

This also fixes an uninitialized return value in ef100_probe_netdev_pf()
that gcc did not spot.

Fixes: 7e056e2360d9 ("sfc: obtain device mac address based on firmware handle for ef100")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/net/ethernet/sfc/ef100_nic.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

Comments

Edward Cree Feb. 17, 2023, 4:13 p.m. UTC | #1
On 17/02/2023 09:56, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> One local variable has become unused after a recent change:
> 
> drivers/net/ethernet/sfc/ef100_nic.c: In function 'ef100_probe_netdev_pf':
> drivers/net/ethernet/sfc/ef100_nic.c:1155:21: error: unused variable 'net_dev' [-Werror=unused-variable]
>   struct net_device *net_dev = efx->net_dev;
>                      ^~~~~~~
> 
> The variable is still used in an #ifdef. Replace the #ifdef with
> an if(IS_ENABLED()) check that lets the compiler see where it is
> used, rather than adding another #ifdef.

So we've had Leon telling us[1] to use __maybe_unused, and you're
 saying to use IS_ENABLED() instead.  Which is right?
(And does it make any difference to build time?  I'm assuming the
 compiler is smart enough that this change doesn't affect text
 size...?)
-ed

[1]: https://lore.kernel.org/netdev/cac3fa89-50a3-6de0-796c-a215400f3710@intel.com/T/#md2ecc82f18c200391dc6581ff68ff08eee9a65cf
Arnd Bergmann Feb. 17, 2023, 4:19 p.m. UTC | #2
On Fri, Feb 17, 2023, at 17:13, Edward Cree wrote:
> On 17/02/2023 09:56, Arnd Bergmann wrote:
>> From: Arnd Bergmann <arnd@arndb.de>
>> 
>> One local variable has become unused after a recent change:
>> 
>> drivers/net/ethernet/sfc/ef100_nic.c: In function 'ef100_probe_netdev_pf':
>> drivers/net/ethernet/sfc/ef100_nic.c:1155:21: error: unused variable 'net_dev' [-Werror=unused-variable]
>>   struct net_device *net_dev = efx->net_dev;
>>                      ^~~~~~~
>> 
>> The variable is still used in an #ifdef. Replace the #ifdef with
>> an if(IS_ENABLED()) check that lets the compiler see where it is
>> used, rather than adding another #ifdef.
>
> So we've had Leon telling us[1] to use __maybe_unused, and you're
>  saying to use IS_ENABLED() instead.  Which is right?
> (And does it make any difference to build time?  I'm assuming the
>  compiler is smart enough that this change doesn't affect text
>  size...?)
> -ed

Both are correct, but I prefer the IS_ENABLED() change because it
improves build coverage. The resulting object code should be the
same, as the dead-code-elimination in gcc takes care of removing
it the same way.

If you use the __maybe_uninitialized annotation, you still need
an extra fix to initialize the ef100_probe_netdev_pf() return
code.

      Arnd
Leon Romanovsky Feb. 19, 2023, 9:31 a.m. UTC | #3
On Fri, Feb 17, 2023 at 04:13:59PM +0000, Edward Cree wrote:
> On 17/02/2023 09:56, Arnd Bergmann wrote:
> > From: Arnd Bergmann <arnd@arndb.de>
> > 
> > One local variable has become unused after a recent change:
> > 
> > drivers/net/ethernet/sfc/ef100_nic.c: In function 'ef100_probe_netdev_pf':
> > drivers/net/ethernet/sfc/ef100_nic.c:1155:21: error: unused variable 'net_dev' [-Werror=unused-variable]
> >   struct net_device *net_dev = efx->net_dev;
> >                      ^~~~~~~
> > 
> > The variable is still used in an #ifdef. Replace the #ifdef with
> > an if(IS_ENABLED()) check that lets the compiler see where it is
> > used, rather than adding another #ifdef.
> 
> So we've had Leon telling us[1] to use __maybe_unused, and you're
>  saying to use IS_ENABLED() instead.  Which is right?
> (And does it make any difference to build time?  I'm assuming the
>  compiler is smart enough that this change doesn't affect text
>  size...?)

You are mixing answers, __maybe_unused is for variables. For functions,
it will be much saner to create empty declarations for relevant
functions in tc.h, for !CONFIG_SFC_SRIOV flow.

It will be much cleaner than spaghetti code in .c files which you have now.

Thanks

> -ed
> 
> [1]: https://lore.kernel.org/netdev/cac3fa89-50a3-6de0-796c-a215400f3710@intel.com/T/#md2ecc82f18c200391dc6581ff68ff08eee9a65cf
Simon Horman Feb. 19, 2023, 1:31 p.m. UTC | #4
On Fri, Feb 17, 2023 at 05:19:26PM +0100, Arnd Bergmann wrote:
> On Fri, Feb 17, 2023, at 17:13, Edward Cree wrote:
> > On 17/02/2023 09:56, Arnd Bergmann wrote:
> >> From: Arnd Bergmann <arnd@arndb.de>
> >> 
> >> One local variable has become unused after a recent change:
> >> 
> >> drivers/net/ethernet/sfc/ef100_nic.c: In function 'ef100_probe_netdev_pf':
> >> drivers/net/ethernet/sfc/ef100_nic.c:1155:21: error: unused variable 'net_dev' [-Werror=unused-variable]
> >>   struct net_device *net_dev = efx->net_dev;
> >>                      ^~~~~~~
> >> 
> >> The variable is still used in an #ifdef. Replace the #ifdef with
> >> an if(IS_ENABLED()) check that lets the compiler see where it is
> >> used, rather than adding another #ifdef.
> >
> > So we've had Leon telling us[1] to use __maybe_unused, and you're
> >  saying to use IS_ENABLED() instead.  Which is right?
> > (And does it make any difference to build time?  I'm assuming the
> >  compiler is smart enough that this change doesn't affect text
> >  size...?)
> > -ed
> 
> Both are correct, but I prefer the IS_ENABLED() change because it
> improves build coverage. The resulting object code should be the
> same, as the dead-code-elimination in gcc takes care of removing
> it the same way.
> 
> If you use the __maybe_uninitialized annotation, you still need
> an extra fix to initialize the ef100_probe_netdev_pf() return
> code.

FWIIW, IS_ENABLED() is the approach that is more familiar to me.
Though I have nothing in particular against other approaches.

Questions of consistency aside, this patch does look good to
me and does appear to address the build problem in question - on x86_64.

Reviewed-by: Simon Horman <simon.horman@corigine.com>
patchwork-bot+netdevbpf@kernel.org Feb. 20, 2023, 10:50 a.m. UTC | #5
Hello:

This patch was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Fri, 17 Feb 2023 10:56:39 +0100 you wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> One local variable has become unused after a recent change:
> 
> drivers/net/ethernet/sfc/ef100_nic.c: In function 'ef100_probe_netdev_pf':
> drivers/net/ethernet/sfc/ef100_nic.c:1155:21: error: unused variable 'net_dev' [-Werror=unused-variable]
>   struct net_device *net_dev = efx->net_dev;
>                      ^~~~~~~
> 
> [...]

Here is the summary with links:
  - sfc: use IS_ENABLED() checks for CONFIG_SFC_SRIOV
    https://git.kernel.org/netdev/net-next/c/a59f832a71c9

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/sfc/ef100_nic.c b/drivers/net/ethernet/sfc/ef100_nic.c
index becd21c2325d..4dc643b0d2db 100644
--- a/drivers/net/ethernet/sfc/ef100_nic.c
+++ b/drivers/net/ethernet/sfc/ef100_nic.c
@@ -399,14 +399,14 @@  static int ef100_filter_table_up(struct efx_nic *efx)
 	 * filter insertion will need to take the lock for read.
 	 */
 	up_write(&efx->filter_sem);
-#ifdef CONFIG_SFC_SRIOV
-	rc = efx_tc_insert_rep_filters(efx);
+	if (IS_ENABLED(CONFIG_SFC_SRIOV))
+		rc = efx_tc_insert_rep_filters(efx);
+
 	/* Rep filter failure is nonfatal */
 	if (rc)
 		netif_warn(efx, drv, efx->net_dev,
 			   "Failed to insert representor filters, rc %d\n",
 			   rc);
-#endif
 	return 0;
 
 fail_vlan0:
@@ -419,9 +419,8 @@  static int ef100_filter_table_up(struct efx_nic *efx)
 
 static void ef100_filter_table_down(struct efx_nic *efx)
 {
-#ifdef CONFIG_SFC_SRIOV
-	efx_tc_remove_rep_filters(efx);
-#endif
+	if (IS_ENABLED(CONFIG_SFC_SRIOV))
+		efx_tc_remove_rep_filters(efx);
 	down_write(&efx->filter_sem);
 	efx_mcdi_filter_del_vlan(efx, 0);
 	efx_mcdi_filter_del_vlan(efx, EFX_FILTER_VID_UNSPEC);
@@ -737,7 +736,6 @@  static unsigned int efx_ef100_recycle_ring_size(const struct efx_nic *efx)
 	return 10 * EFX_RECYCLE_RING_SIZE_10G;
 }
 
-#ifdef CONFIG_SFC_SRIOV
 static int efx_ef100_get_base_mport(struct efx_nic *efx)
 {
 	struct ef100_nic_data *nic_data = efx->nic_data;
@@ -773,7 +771,6 @@  static int efx_ef100_get_base_mport(struct efx_nic *efx)
 
 	return 0;
 }
-#endif
 
 static int compare_versions(const char *a, const char *b)
 {
@@ -1155,10 +1152,9 @@  int ef100_probe_netdev_pf(struct efx_nic *efx)
 	struct net_device *net_dev = efx->net_dev;
 	int rc;
 
-	if (!nic_data->grp_mae)
+	if (!IS_ENABLED(CONFIG_SFC_SRIOV) || !nic_data->grp_mae)
 		return 0;
 
-#ifdef CONFIG_SFC_SRIOV
 	rc = efx_init_struct_tc(efx);
 	if (rc)
 		return rc;
@@ -1193,7 +1189,6 @@  int ef100_probe_netdev_pf(struct efx_nic *efx)
 		net_dev->features |= NETIF_F_HW_TC;
 		efx->fixed_features |= NETIF_F_HW_TC;
 	}
-#endif
 	return rc;
 }
 
@@ -1206,12 +1201,11 @@  void ef100_remove(struct efx_nic *efx)
 {
 	struct ef100_nic_data *nic_data = efx->nic_data;
 
-#ifdef CONFIG_SFC_SRIOV
-	if (efx->mae) {
+	if (IS_ENABLED(CONFIG_SFC_SRIOV) && efx->mae) {
 		efx_ef100_fini_reps(efx);
 		efx_fini_mae(efx);
 	}
-#endif
+
 	efx_mcdi_detach(efx);
 	efx_mcdi_fini(efx);
 	if (nic_data)
@@ -1304,9 +1298,8 @@  const struct efx_nic_type ef100_pf_nic_type = {
 	.update_stats = ef100_update_stats,
 	.pull_stats = efx_mcdi_mac_pull_stats,
 	.stop_stats = efx_mcdi_mac_stop_stats,
-#ifdef CONFIG_SFC_SRIOV
-	.sriov_configure = efx_ef100_sriov_configure,
-#endif
+	.sriov_configure = IS_ENABLED(CONFIG_SFC_SRIOV) ?
+		efx_ef100_sriov_configure : NULL,
 
 	/* Per-type bar/size configuration not used on ef100. Location of
 	 * registers is defined by extended capabilities.