linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Murilo Opsfelder Araújo" <muriloo@linux.ibm.com>
To: mst@redhat.com
Cc: jasowang@redhat.com, virtualization@lists.linux-foundation.org,
	linux-kernel@vger.kernel.org, mopsfelder@gmail.com,
	dinechin@redhat.com
Subject: Re: [PATCH] virtio-pci: Remove wrong address verification in vp_del_vqs()
Date: Fri, 15 Apr 2022 00:51:34 -0300	[thread overview]
Message-ID: <e8620e70-16bb-639c-9446-68dcd199253f@linux.ibm.com> (raw)
In-Reply-To: <20220415023002.49805-1-muriloo@linux.ibm.com>

On 4/14/22 23:30, Murilo Opsfelder Araujo wrote:
> GCC 12 enhanced -Waddress when comparing array address to null [0],
> which warns:
> 
>      drivers/virtio/virtio_pci_common.c: In function ‘vp_del_vqs’:
>      drivers/virtio/virtio_pci_common.c:257:29: warning: the comparison will always evaluate as ‘true’ for the pointer operand in ‘vp_dev->msix_affinity_masks + (sizetype)((long unsigned int)i * 256)’ must not be NULL [-Waddress]
>        257 |                         if (vp_dev->msix_affinity_masks[i])
>            |                             ^~~~~~
> 
> In fact, the verification is comparing the result of a pointer
> arithmetic, the address "msix_affinity_masks + i", which will always
> evaluate to true.
> 
> Under the hood, free_cpumask_var() calls kfree(), which is safe to pass
> NULL, not requiring non-null verification.  So remove the verification
> to make compiler happy (happy compiler, happy life).
> 
> [0] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102103
> 
> Signed-off-by: Murilo Opsfelder Araujo <muriloo@linux.ibm.com>
> ---
>   drivers/virtio/virtio_pci_common.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
> index d724f676608b..5046efcffb4c 100644
> --- a/drivers/virtio/virtio_pci_common.c
> +++ b/drivers/virtio/virtio_pci_common.c
> @@ -254,8 +254,7 @@ void vp_del_vqs(struct virtio_device *vdev)
>   
>   	if (vp_dev->msix_affinity_masks) {
>   		for (i = 0; i < vp_dev->msix_vectors; i++)
> -			if (vp_dev->msix_affinity_masks[i])
> -				free_cpumask_var(vp_dev->msix_affinity_masks[i]);
> +			free_cpumask_var(vp_dev->msix_affinity_masks[i]);
>   	}
>   
>   	if (vp_dev->msix_enabled) {

After I sent this message, I realized that Christophe (copied here)
had already proposed a fix:

     https://lore.kernel.org/lkml/20220414150855.2407137-4-dinechin@redhat.com/

Christophe,

Since free_cpumask_var() calls kfree() and kfree() is null-safe,
can we just drop this null verification and call free_cpumask_var() right away?

-- 
Murilo

  reply	other threads:[~2022-04-15  3:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-15  2:30 [PATCH] virtio-pci: Remove wrong address verification in vp_del_vqs() Murilo Opsfelder Araujo
2022-04-15  3:51 ` Murilo Opsfelder Araújo [this message]
2022-04-28  9:46   ` Christophe Marie Francois Dupont de Dinechin
2022-04-28  9:51     ` Christophe Marie Francois Dupont de Dinechin
2022-04-28  9:55       ` Christophe Marie Francois Dupont de Dinechin
2022-04-28 11:03         ` Michael S. Tsirkin
2022-04-28 11:52           ` Christophe Marie Francois Dupont de Dinechin

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=e8620e70-16bb-639c-9446-68dcd199253f@linux.ibm.com \
    --to=muriloo@linux.ibm.com \
    --cc=dinechin@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mopsfelder@gmail.com \
    --cc=mst@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /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).