Re: [PATCH] enic: fix build warning without CONFIG_CPUMASK_OFFSTACK

From: Nathan Chancellor
Date: Thu Mar 07 2019 - 10:14:44 EST


On Thu, Mar 07, 2019 at 10:33:02AM +0100, Arnd Bergmann wrote:
> The enic driver relies on the CONFIG_CPUMASK_OFFSTACK feature to
> dynamically allocate a struct member, but this is normally intended for
> local variables.
>
> Building with clang, I get a warning for a few locations that check the
> address of the cpumask_var_t:
>
> drivers/net/ethernet/cisco/enic/enic_main.c:122:22: error: address of array 'enic->msix[i].affinity_mask' will always evaluate to 'true' [-Werror,-Wpointer-bool-conversion]
>
> As far as I can tell, the code is still correct, as the truth value of
> the pointer is what we need in this configuration. To get rid of the
> warning, I split out the check into a separate function, and hide that
> portion if CONFIG_CPUMASK_OFFSTACK is disabled.
>
> Fixes: 322cf7e3a4e8 ("enic: assign affinity hint to interrupts")
> Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
> ---
> drivers/net/ethernet/cisco/enic/enic_main.c | 18 ++++++++++++------
> 1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
> index 9a7f70db20c7..f652a8bd163e 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_main.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_main.c
> @@ -112,6 +112,15 @@ static struct enic_intr_mod_range mod_range[ENIC_MAX_LINK_SPEEDS] = {
> {3, 6}, /* 10 - 40 Gbps */
> };
>
> +static inline int enic_affinity_mask_empty(struct enic *enic, int i)
> +{
> +#ifdef CONFIG_CPUMASK_OFFSTACK
> + if (!enic->msix[i].affinity_mask)
> + return 1;
> +#endif
> + return cpumask_empty(enic->msix[i].affinity_mask);
> +}
> +
> static void enic_init_affinity_hint(struct enic *enic)
> {
> int numa_node = dev_to_node(&enic->pdev->dev);
> @@ -119,8 +128,7 @@ static void enic_init_affinity_hint(struct enic *enic)
>
> for (i = 0; i < enic->intr_count; i++) {
> if (enic_is_err_intr(enic, i) || enic_is_notify_intr(enic, i) ||
> - (enic->msix[i].affinity_mask &&
> - !cpumask_empty(enic->msix[i].affinity_mask)))
> + !enic_affinity_mask_empty(enic, i))
> continue;
> if (zalloc_cpumask_var(&enic->msix[i].affinity_mask,
> GFP_KERNEL))
> @@ -148,8 +156,7 @@ static void enic_set_affinity_hint(struct enic *enic)
> for (i = 0; i < enic->intr_count; i++) {
> if (enic_is_err_intr(enic, i) ||
> enic_is_notify_intr(enic, i) ||
> - !enic->msix[i].affinity_mask ||
> - cpumask_empty(enic->msix[i].affinity_mask))
> + enic_affinity_mask_empty(enic, i))
> continue;
> err = irq_set_affinity_hint(enic->msix_entry[i].vector,
> enic->msix[i].affinity_mask);
> @@ -161,8 +168,7 @@ static void enic_set_affinity_hint(struct enic *enic)
> for (i = 0; i < enic->wq_count; i++) {
> int wq_intr = enic_msix_wq_intr(enic, i);
>
> - if (enic->msix[wq_intr].affinity_mask &&
> - !cpumask_empty(enic->msix[wq_intr].affinity_mask))
> + if (!enic_affinity_mask_empty(enic, wq_intr))
> netif_set_xps_queue(enic->netdev,
> enic->msix[wq_intr].affinity_mask,
> i);
> --
> 2.20.0
>

A slightly less intrusive change would be using cpumask_available, which
was specifically introduced for this purpose in commit f7e30f01a9e2
("cpumask: Add helper cpumask_available()").