Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/vmwgfx: Correctly NULLify dma buffer pointer on failure

cppcheck on lines 917 and 977 show an ineffective assignment
to the dma buffer pointer:

[drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c:917]:
[drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c:977]:
(warning) Assignment of function parameter has no effect
outside the function. Did you forget dereferencing it?

On a successful DMA buffer lookup, the dma buffer pointer is
assigned, however, on failure it currently is left in an
undefined state.

The original intention in the error exit path was to nullify
the pointer on an error (which the original code failed to
do properly). This patch fixes this also ensures all failure
paths nullify the buffer pointer on the error return.

Fortunately the callers to vmw_translate_mob_ptr and
vmw_translate_guest_ptr are checking on a return status and not
on the dma buffer pointer, so the original code worked.

Reviewed-by: Thomas Hellstrom <thellstrom@vmware.com>
Signed-off-by: Colin Ian King <colin.king@canonical.com>

authored by

Colin Ian King and committed by
Thomas Hellstrom
da5efffc 3458390b

+6 -4
+6 -4
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
··· 890 890 ret = vmw_user_dmabuf_lookup(sw_context->fp->tfile, handle, &vmw_bo); 891 891 if (unlikely(ret != 0)) { 892 892 DRM_ERROR("Could not find or use MOB buffer.\n"); 893 - return -EINVAL; 893 + ret = -EINVAL; 894 + goto out_no_reloc; 894 895 } 895 896 bo = &vmw_bo->base; 896 897 ··· 915 914 916 915 out_no_reloc: 917 916 vmw_dmabuf_unreference(&vmw_bo); 918 - vmw_bo_p = NULL; 917 + *vmw_bo_p = NULL; 919 918 return ret; 920 919 } 921 920 ··· 952 951 ret = vmw_user_dmabuf_lookup(sw_context->fp->tfile, handle, &vmw_bo); 953 952 if (unlikely(ret != 0)) { 954 953 DRM_ERROR("Could not find or use GMR region.\n"); 955 - return -EINVAL; 954 + ret = -EINVAL; 955 + goto out_no_reloc; 956 956 } 957 957 bo = &vmw_bo->base; 958 958 ··· 976 974 977 975 out_no_reloc: 978 976 vmw_dmabuf_unreference(&vmw_bo); 979 - vmw_bo_p = NULL; 977 + *vmw_bo_p = NULL; 980 978 return ret; 981 979 } 982 980