diff mbox

[1/1] drm/vmwgfx: avoid possible NULL pointer dereference

Message ID 1471814177-5472-1-git-send-email-xypron.glpk@gmx.de (mailing list archive)
State New, archived
Headers show

Commit Message

Heinrich Schuchardt Aug. 21, 2016, 9:16 p.m. UTC
The comment describing function vmw_cmd_res_reloc_add
explicitely mentions p_val may be NULL.

We should not assign a value (NULL) to *p_val in this case.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

kernel test robot Aug. 23, 2016, 2:05 p.m. UTC | #1
Hi Heinrich,

[auto build test WARNING on drm/drm-next]
[also build test WARNING on v4.8-rc3 next-20160823]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
[Suggest to use git(>=2.9.0) format-patch --base=<commit> (or --base=auto for convenience) to record what (public, well-known) commit your patch series was built on]
[Check https://git-scm.com/docs/git-format-patch for more information]

url:    https://github.com/0day-ci/linux/commits/Heinrich-Schuchardt/drm-vmwgfx-avoid-possible-NULL-pointer-dereference/20160822-051807
base:   git://people.freedesktop.org/~airlied/linux.git drm-next
config: x86_64-randconfig-x016-201634 (attached as .config)
compiler: gcc-6 (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c: In function 'vmw_cmd_res_reloc_add':
>> drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c:656:3: warning: 'return' with no value, in function returning non-void [-Wreturn-type]
      return;
      ^~~~~~
   drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c:646:12: note: declared here
    static int vmw_cmd_res_reloc_add(struct vmw_private *dev_priv,
               ^~~~~~~~~~~~~~~~~~~~~

vim +/return +656 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c

   640	 * @sw_context: Pointer to the software context.
   641	 * @id_loc: Pointer to where the id that needs translation is located.
   642	 * @res: Valid pointer to a struct vmw_resource.
   643	 * @p_val: If non null, a pointer to the struct vmw_resource_validate_node
   644	 * used for this resource is returned here.
   645	 */
   646	static int vmw_cmd_res_reloc_add(struct vmw_private *dev_priv,
   647					 struct vmw_sw_context *sw_context,
   648					 uint32_t *id_loc,
   649					 struct vmw_resource *res,
   650					 struct vmw_resource_val_node **p_val)
   651	{
   652		int ret;
   653		struct vmw_resource_val_node *node;
   654	
   655		if (!p_val)
 > 656			return;
   657	
   658		*p_val = NULL;
   659	
   660		ret = vmw_resource_relocation_add(&sw_context->res_relocations,
   661						  res,
   662						  id_loc - sw_context->buf_start);
   663		if (unlikely(ret != 0))
   664			return ret;

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox

Patch

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
index dc5beff..0363989 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
@@ -652,7 +652,11 @@  static int vmw_cmd_res_reloc_add(struct vmw_private *dev_priv,
 	int ret;
 	struct vmw_resource_val_node *node;
 
+	if (!p_val)
+		return;
+
 	*p_val = NULL;
+
 	ret = vmw_resource_relocation_add(&sw_context->res_relocations,
 					  res,
 					  id_loc - sw_context->buf_start);
@@ -663,8 +667,7 @@  static int vmw_cmd_res_reloc_add(struct vmw_private *dev_priv,
 	if (unlikely(ret != 0))
 		return ret;
 
-	if (p_val)
-		*p_val = node;
+	*p_val = node;
 
 	return 0;
 }