diff mbox series

vhost: silence an unused-variable warning

Message ID 20190306110602.2529137-1-arnd@arndb.de (mailing list archive)
State New, archived
Headers show
Series vhost: silence an unused-variable warning | expand

Commit Message

Arnd Bergmann March 6, 2019, 11:05 a.m. UTC
On some architectures, the MMU can be disabled, leading to access_ok()
becoming an empty macro that does not evaluate its size argument,
which in turn produces an unused-variable warning:

drivers/vhost/vhost.c:1191:9: error: unused variable 's' [-Werror,-Wunused-variable]
        size_t s = vhost_has_feature(vq, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0;

Mark the variable as __maybe_unused to shut up that warning.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/vhost/vhost.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jason Wang March 7, 2019, 3 a.m. UTC | #1
On 2019/3/6 下午7:05, Arnd Bergmann wrote:
> On some architectures, the MMU can be disabled, leading to access_ok()
> becoming an empty macro that does not evaluate its size argument,
> which in turn produces an unused-variable warning:
>
> drivers/vhost/vhost.c:1191:9: error: unused variable 's' [-Werror,-Wunused-variable]
>          size_t s = vhost_has_feature(vq, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0;
>
> Mark the variable as __maybe_unused to shut up that warning.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>   drivers/vhost/vhost.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index a2e5dc7716e2..5ace833de746 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -1188,7 +1188,7 @@ static bool vq_access_ok(struct vhost_virtqueue *vq, unsigned int num,
>   			 struct vring_used __user *used)
>   
>   {
> -	size_t s = vhost_has_feature(vq, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0;
> +	size_t s __maybe_unused = vhost_has_feature(vq, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0;
>   
>   	return access_ok(desc, num * sizeof *desc) &&
>   	       access_ok(avail,


Acked-by: Jason Wang <jasowang@redhat.com>
David Miller March 8, 2019, 11:17 p.m. UTC | #2
From: Arnd Bergmann <arnd@arndb.de>
Date: Wed,  6 Mar 2019 12:05:49 +0100

> On some architectures, the MMU can be disabled, leading to access_ok()
> becoming an empty macro that does not evaluate its size argument,
> which in turn produces an unused-variable warning:
> 
> drivers/vhost/vhost.c:1191:9: error: unused variable 's' [-Werror,-Wunused-variable]
>         size_t s = vhost_has_feature(vq, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0;
> 
> Mark the variable as __maybe_unused to shut up that warning.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

I'll apply this, thanks Arnd.
Michael S. Tsirkin March 9, 2019, 11:19 p.m. UTC | #3
On Fri, Mar 08, 2019 at 03:17:26PM -0800, David Miller wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> Date: Wed,  6 Mar 2019 12:05:49 +0100
> 
> > On some architectures, the MMU can be disabled, leading to access_ok()
> > becoming an empty macro that does not evaluate its size argument,
> > which in turn produces an unused-variable warning:
> > 
> > drivers/vhost/vhost.c:1191:9: error: unused variable 's' [-Werror,-Wunused-variable]
> >         size_t s = vhost_has_feature(vq, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0;
> > 
> > Mark the variable as __maybe_unused to shut up that warning.
> > 
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> 
> I'll apply this, thanks Arnd.

I queued this for next linux already and it's been in linux-next
for a while. Sorry that I didn't reply, will try to remember to do it
next time.
diff mbox series

Patch

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index a2e5dc7716e2..5ace833de746 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -1188,7 +1188,7 @@  static bool vq_access_ok(struct vhost_virtqueue *vq, unsigned int num,
 			 struct vring_used __user *used)
 
 {
-	size_t s = vhost_has_feature(vq, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0;
+	size_t s __maybe_unused = vhost_has_feature(vq, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0;
 
 	return access_ok(desc, num * sizeof *desc) &&
 	       access_ok(avail,