Skip to contentSkip to conversation

drm/vmwgfx: Zero initialize handle in vmw_execbuf_process

PATCH In review Nathan Chancellor 3 participants 3 messages Mar 7, 2019 – Mar 11, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/vmwgfx: Zero initialize handle in vmw_execbuf_process

When building with -Wsometimes-uninitialized, Clang warns:

drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c:3964:7: warning: variable 'handle' is used uninitialized whenever '?:' condition is false [-Wsometimes-uninitialized]

It's not wrong; however, in practice, this is never an issue because the value of handle isn't used when user_fence_rep is NULL because vmw_execbuf_copy_fence_user returns immediately when that is the case. Just zero initialize this variable so that Clang no longer warns.

---
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +1 -1
index 88b8178d4687..4ba06c2828a1 100644
@@ -3829,7 +3829,7 @@ int vmw_execbuf_process(struct drm_file *file_priv,
 	struct vmw_sw_context *sw_context = &dev_priv->ctx;
 	struct vmw_fence_obj *fence = NULL;
 	struct vmw_cmdbuf_header *header;
-	uint32_t handle;
+	uint32_t handle = 0;
 	int ret;
 	int32_t out_fence_fd = -1;
 	struct sync_file *sync_file = NULL;
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c:3964:7: warning: variable 'handle' is used uninitialized whenever '?:' condition is false [-Wsometimes-uninitialized]

It's not wrong; however, in practice, this is never an issue because the value of handle isn't used when user_fence_rep is NULL because vmw_execbuf_copy_fence_user returns immediately when that is the case.

Still, it's better not to conditionally pass unitialized memory to functions. Invariants like "don't touch this possibly unitialized memory in THIS case" don't always pass from maintainer to maintainer. Thanks for the patch.

Quoted 30 lines

Just zero initialize this variable so that Clang no longer warns.

---
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +1 -2
index 88b8178d4687..4ba06c2828a1 100644
@@ -3829,7 +3829,7 @@ int vmw_execbuf_process(struct drm_file *file_priv,
        struct vmw_sw_context *sw_context = &dev_priv->ctx;
        struct vmw_fence_obj *fence = NULL;
        struct vmw_cmdbuf_header *header;
-       uint32_t handle;
+       uint32_t handle = 0;
        int ret;
        int32_t out_fence_fd = -1;
        struct sync_file *sync_file = NULL;
--

2.21.0

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20190307222611.18100-1-natechancellor%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Signature · 2 lines
Thanks,
~Nick Desaulniers
Reviewed-by on v1 1/1
#2 lore raw
In reply to Nathan Chancellor

Hi Nathan,

Thanks for doing this. I will include this in vmwgfx-next.

Quoted 34 lines · Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c:3964:7: warning: variable 'handle' is used uninitialized whenever '?:' condition is false [-Wsometimes-uninitialized]

It's not wrong; however, in practice, this is never an issue because the value of handle isn't used when user_fence_rep is NULL because vmw_execbuf_copy_fence_user returns immediately when that is the case.
Just zero initialize this variable so that Clang no longer warns.

Link:
https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FClangBuiltLinux%2Flinux%2Fissues%2F397&data=02%7C01%7Cdrawat%40vmware.com%7C6b9c429d16d844a5740c08d6a34bedb4%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636875943916412703&sdata=Yf7%2BzrbZS96yNJQewYQQ7YsHUDtJSvPaomyTJFZjsDk%3D&reserved=0

---
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +1 -1
index 88b8178d4687..4ba06c2828a1 100644
@@ -3829,7 +3829,7 @@ int vmw_execbuf_process(struct drm_file
 *file_priv,
 	struct vmw_sw_context *sw_context = &dev_priv->ctx;
 	struct vmw_fence_obj *fence = NULL;
 	struct vmw_cmdbuf_header *header;
-	uint32_t handle;
+	uint32_t handle = 0;
 	int ret;
 	int32_t out_fence_fd = -1;

struct sync_file *sync_file = NULL;