Skip to contentSkip to conversation

virtio-gpu: fix shift wrapping bug in virtio_gpu_fence_event_create()

PATCH Superseded Dan Carpenter 2 participants 3 messages Sep 15, 2022 – Sep 16, 2022

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-gpu: fix shift wrapping bug in virtio_gpu_fence_event_create()

The ->ring_idx_mask variable is a u64 so static checkers, Smatch in this case, complain if the BIT() is not also a u64.

drivers/gpu/drm/virtio/virtgpu_ioctl.c:50 virtio_gpu_fence_event_create()
warn: should '(1 << ring_idx)' be a 64 bit type?

Fixes cd7f5ca33585 ("drm/virtio: implement context init: add virtio_gpu_fence_event")
---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +1 -1
index 3b1701607aae..14eedb75f8a8 100644
@@ -47,7 +47,7 @@ static int virtio_gpu_fence_event_create(struct drm_device *dev,
 	struct virtio_gpu_fence_event *e = NULL;
 	int ret;
 
-	if (!(vfpriv->ring_idx_mask & (1 << ring_idx)))
+	if (!(vfpriv->ring_idx_mask & (1ULL << ring_idx)))
 		return 0;
 
 	e = kzalloc(sizeof(*e), GFP_KERNEL);
Signature · 1 line
2.35.1
reviewer
#1 lore raw
Quoted 18 lines · Dan Carpenter

The ->ring_idx_mask variable is a u64 so static checkers, Smatch in this case, complain if the BIT() is not also a u64.

drivers/gpu/drm/virtio/virtgpu_ioctl.c:50 virtio_gpu_fence_event_create()
warn: should '(1 << ring_idx)' be a 64 bit type?

Fixes cd7f5ca33585 ("drm/virtio: implement context init: add virtio_gpu_fence_event")
---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0 -0
index 3b1701607aae..14eedb75f8a8 100644

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_fence_event_create(struct drm_device *dev, · line 50

Quoted 5 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +1 -1
@@ -47,7 +47,7 @@ static int virtio_gpu_fence_event_create(struct drm_device *dev,
        struct virtio_gpu_fence_event *e = NULL;
        int ret;
 
-       if (!(vfpriv->ring_idx_mask & (1 << ring_idx)))
+       if (!(vfpriv->ring_idx_mask & (1ULL << ring_idx)))

BIT_ULL(ring_indx)?

Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0 -1
                return 0;
 
        e = kzalloc(sizeof(*e), GFP_KERNEL);
--

2.35.1

#2 lore raw
Quoted 22 lines · Chia-I Wu
Quoted 21 lines · Dan Carpenter

The ->ring_idx_mask variable is a u64 so static checkers, Smatch in this case, complain if the BIT() is not also a u64.

drivers/gpu/drm/virtio/virtgpu_ioctl.c:50 virtio_gpu_fence_event_create()
warn: should '(1 << ring_idx)' be a 64 bit type?

Fixes cd7f5ca33585 ("drm/virtio: implement context init: add virtio_gpu_fence_event")
---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0 -0
index 3b1701607aae..14eedb75f8a8 100644
@@ -47,7 +47,7 @@ static int virtio_gpu_fence_event_create(struct drm_device *dev,
        struct virtio_gpu_fence_event *e = NULL;
        int ret;
 
Quoted 4 lines

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_fence_event_create(struct drm_device *dev, · line 50

Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +1 -1
-       if (!(vfpriv->ring_idx_mask & (1 << ring_idx)))
+       if (!(vfpriv->ring_idx_mask & (1ULL << ring_idx)))

BIT_ULL(ring_indx)?

Sure. I can resend.

regards,
dan carpenter