Skip to contentSkip to conversation

drm/vmwgfx: Fix possible usage of an uninitialized variable

PATCH In review Zack Rusin 2 participants 2 messages Dec 15, 2021 – Dec 16, 2021

Subsystems (3)
lore
Share & tools
lore

Zack Rusin

author
#0 lore raw

PATCH 1/1 drm/vmwgfx: Fix possible usage of an uninitialized variable

From: Zack Rusin <[email protected]>

vmw_user_bo_lookup can fail to lookup user buffers, especially because the buffer handles come from the userspace. The return value has to be checked before the buffers are put back.

This was spotted by Dan's Smatch statick checker:
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c:574 vmw_user_bo_synccpu_release()
error: uninitialized symbol 'vmw_bo'.

Fixes 8afa13a0583f ("drm/vmwgfx: Implement DRIVER_GEM")
---
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +5 -3
index 15fead85450c..31aecc46624b 100644
@@ -568,10 +568,12 @@ static int vmw_user_bo_synccpu_release(struct drm_file *filp,
 	struct vmw_buffer_object *vmw_bo;
 	int ret = vmw_user_bo_lookup(filp, handle, &vmw_bo);
 
-	if (!(flags & drm_vmw_synccpu_allow_cs)) {
-		atomic_dec(&vmw_bo->cpu_writers);
+	if (!ret) {
+		if (!(flags & drm_vmw_synccpu_allow_cs)) {
+			atomic_dec(&vmw_bo->cpu_writers);
+		}
+		ttm_bo_put(&vmw_bo->base);
 	}
-	ttm_bo_put(&vmw_bo->base);
 
 	return ret;
 }
Signature · 1 line
2.32.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines · Zack Rusin

From: Zack Rusin <[email protected]>

vmw_user_bo_lookup can fail to lookup user buffers, especially because the buffer handles come from the userspace. The return value has to be checked before the buffers are put back.

This was spotted by Dan's Smatch statick checker:
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c:574 vmw_user_bo_synccpu_release()
error: uninitialized symbol 'vmw_bo'.

Fixes 8afa13a0583f ("drm/vmwgfx: Implement DRIVER_GEM")
---
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +0 -2
index 15fead85450c..31aecc46624b 100644
@@ -568,10 +568,12 @@ static int vmw_user_bo_synccpu_release(struct drm_file *filp,
 	struct vmw_buffer_object *vmw_bo;
 	int ret = vmw_user_bo_lookup(filp, handle, &vmw_bo);
 
-	if (!(flags & drm_vmw_synccpu_allow_cs)) {
-		atomic_dec(&vmw_bo->cpu_writers);

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c static int vmw_user_bo_synccpu_release(struct drm_file *filp, · line 579

Quoted 10 lines
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +5 -1
+	if (!ret) {
+		if (!(flags & drm_vmw_synccpu_allow_cs)) {
+			atomic_dec(&vmw_bo->cpu_writers);
+		}
+		ttm_bo_put(&vmw_bo->base);
 	}
-	ttm_bo_put(&vmw_bo->base);
 
 	return ret;
 }
Signature · 2 lines
Regards,
Martin