drm/vmwgfx: use kzalloc in vmw_surface_define_ioctl()
PATCH 1/2 drm/vmwgfx: use kzalloc in vmw_surface_define_ioctl()
--- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +2 -5
@@ -814,11 +814,8 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data, srf->sizes[0].height == 64 && srf->format == SVGA3D_A8R8G8B8) { - srf->snooper.image =kmalloc (64 *64 *4 ,GFP_KERNEL ); -/* clear the image */ -if (srf->snooper.image) { -memset (srf->snooper.image,0x00 ,64 *64 *4 ); - }else { + srf->snooper.image =kzalloc (64 *64 *4 ,GFP_KERNEL ); +if (!srf->snooper.image) {DRM_ERROR ("Failed to allocate cursor_image\n" ); ret = -ENOMEM ; goto out_no_copy;
Signature · 1 line
2.1.3
PATCH 2/2 drm/omap: use kzalloc in sita_init()
--- drivers/gpu/drm/omapdrm/tcm-sita.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/omapdrm/tcm-sita.c +2 -5
@@ -87,14 +87,11 @@ struct tcm *sita_init(u16 width, u16 height, struct tcm_pt *attr)if (width ==0 || height ==0 )return NULL ; - tcm =kmalloc (sizeof (*tcm),GFP_KERNEL ); - pvt =kmalloc (sizeof (*pvt),GFP_KERNEL ); + tcm =kzalloc (sizeof (*tcm),GFP_KERNEL ); + pvt =kzalloc (sizeof (*pvt),GFP_KERNEL );if (!tcm || !pvt) goto error; -memset (tcm,0 ,sizeof (*tcm)); -memset (pvt,0 ,sizeof (*pvt)); -/* Updating the pointers to SiTA implementation APIs */ tcm->height = height; tcm->width = width;
Signature · 1 line
2.1.3
kbuild test robot
build botcoccinelle warnings: (new ones prefixed by >>)
Hi Rasmus,
[auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore]
coccinelle warnings: (new ones prefixed by >>)
>> drivers/gpu/drm/vmwgfx/vmwgfx_surface.c:771:1-13: alloc with no test, possible model on line 817
vim +771 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
543831cf Thomas Hellstrom 2012-11-20 765
543831cf Thomas Hellstrom 2012-11-20 766 srf->sizes = kmalloc(srf->num_sizes * sizeof(*srf->sizes), GFP_KERNEL);
543831cf Thomas Hellstrom 2012-11-20 767 if (unlikely(srf->sizes == NULL)) {
543831cf Thomas Hellstrom 2012-11-20 768 ret = -ENOMEM;
543831cf Thomas Hellstrom 2012-11-20 769 goto out_no_sizes;
543831cf Thomas Hellstrom 2012-11-20 770 }
543831cf Thomas Hellstrom 2012-11-20 @771 srf->offsets = kmalloc(srf->num_sizes * sizeof(*srf->offsets),
543831cf Thomas Hellstrom 2012-11-20 772 GFP_KERNEL);
543831cf Thomas Hellstrom 2012-11-20 773 if (unlikely(srf->sizes == NULL)) {
543831cf Thomas Hellstrom 2012-11-20 774 ret = -ENOMEM;
543831cf Thomas Hellstrom 2012-11-20 775 goto out_no_offsets;
543831cf Thomas Hellstrom 2012-11-20 776 }
543831cf Thomas Hellstrom 2012-11-20 777
543831cf Thomas Hellstrom 2012-11-20 778 user_sizes = (struct drm_vmw_size __user *)(unsigned long)
543831cf Thomas Hellstrom 2012-11-20 779 req->size_addr;
543831cf Thomas Hellstrom 2012-11-20 780
543831cf Thomas Hellstrom 2012-11-20 781 ret = copy_from_user(srf->sizes, user_sizes,
543831cf Thomas Hellstrom 2012-11-20 782 srf->num_sizes * sizeof(*srf->sizes));
543831cf Thomas Hellstrom 2012-11-20 783 if (unlikely(ret != 0)) {
543831cf Thomas Hellstrom 2012-11-20 784 ret = -EFAULT;
543831cf Thomas Hellstrom 2012-11-20 785 goto out_no_copy;
543831cf Thomas Hellstrom 2012-11-20 786 }
543831cf Thomas Hellstrom 2012-11-20 787
543831cf Thomas Hellstrom 2012-11-20 788 srf->base_size = *srf->sizes;
543831cf Thomas Hellstrom 2012-11-20 789 srf->autogen_filter = SVGA3D_TEX_FILTER_NONE;
15c6f656 Zack Rusin 2012-11-21 790 srf->multisample_count = 0;
543831cf Thomas Hellstrom 2012-11-20 791
543831cf Thomas Hellstrom 2012-11-20 792 cur_bo_offset = 0;
543831cf Thomas Hellstrom 2012-11-20 793 cur_offset = srf->offsets;
543831cf Thomas Hellstrom 2012-11-20 794 cur_size = srf->sizes;
543831cf Thomas Hellstrom 2012-11-20 795
543831cf Thomas Hellstrom 2012-11-20 796 for (i = 0; i < DRM_VMW_MAX_SURFACE_FACES; ++i) {
543831cf Thomas Hellstrom 2012-11-20 797 for (j = 0; j < srf->mip_levels[i]; ++j) {
7e8d9da3 Thomas Hellstrom 2012-11-20 798 uint32_t stride = svga3dsurface_calculate_pitch
7e8d9da3 Thomas Hellstrom 2012-11-20 799 (desc, cur_size);
543831cf Thomas Hellstrom 2012-11-20 800
543831cf Thomas Hellstrom 2012-11-20 801 cur_offset->face = i;
543831cf Thomas Hellstrom 2012-11-20 802 cur_offset->mip = j;
543831cf Thomas Hellstrom 2012-11-20 803 cur_offset->bo_offset = cur_bo_offset;
7e8d9da3 Thomas Hellstrom 2012-11-20 804 cur_bo_offset += svga3dsurface_get_image_buffer_size
7e8d9da3 Thomas Hellstrom 2012-11-20 805 (desc, cur_size, stride);
543831cf Thomas Hellstrom 2012-11-20 806 ++cur_offset;
543831cf Thomas Hellstrom 2012-11-20 807 ++cur_size;
543831cf Thomas Hellstrom 2012-11-20 808 }
543831cf Thomas Hellstrom 2012-11-20 809 }
543831cf Thomas Hellstrom 2012-11-20 810 res->backup_size = cur_bo_offset;
543831cf Thomas Hellstrom 2012-11-20 811 if (srf->scanout &&
543831cf Thomas Hellstrom 2012-11-20 812 srf->num_sizes == 1 &&
543831cf Thomas Hellstrom 2012-11-20 813 srf->sizes[0].width == 64 &&
543831cf Thomas Hellstrom 2012-11-20 814 srf->sizes[0].height == 64 &&
543831cf Thomas Hellstrom 2012-11-20 815 srf->format == SVGA3D_A8R8G8B8) {
543831cf Thomas Hellstrom 2012-11-20 816
fc815f88 Rasmus Villemoes 2015-09-30 @817 srf->snooper.image = kzalloc(64 * 64 * 4, GFP_KERNEL);
fc815f88 Rasmus Villemoes 2015-09-30 818 if (!srf->snooper.image) {
543831cf Thomas Hellstrom 2012-11-20 819 DRM_ERROR("Failed to allocate cursor_image\n");
543831cf Thomas Hellstrom 2012-11-20 820 ret = -ENOMEM;:::::: The code at line 771 was first introduced by commit
:::::: 543831cfc976669b8da963b3e94933e21e051846 drm/vmwgfx: Break out surface and context management to separate files
:::::: TO: Thomas Hellstrom <[email protected]> :::::: CC: Dave Airlie <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 23 lines · kbuild test robot
Hi Rasmus,
[auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore]
coccinelle warnings: (new ones prefixed by >>)
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c:771:1-13: alloc with no test, possible model on line 817
vim +771
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c543831cf Thomas Hellstrom 2012-11-20 765 543831cf Thomas Hellstrom 2012-11-20 766 srf->sizes = kmalloc(srf->num_sizes * sizeof(*srf->sizes), GFP_KERNEL); 543831cf Thomas Hellstrom 2012-11-20 767 if (unlikely(srf->sizes == NULL)) { 543831cf Thomas Hellstrom 2012-11-20 768 ret = -ENOMEM; 543831cf Thomas Hellstrom 2012-11-20 769 goto out_no_sizes; 543831cf Thomas Hellstrom 2012-11-20 770 } 543831cf Thomas Hellstrom 2012-11-20 @771 srf->offsets = kmalloc(srf->num_sizes * sizeof(*srf->offsets), 543831cf Thomas Hellstrom 2012-11-20 772 GFP_KERNEL); 543831cf Thomas Hellstrom 2012-11-20 773 if (unlikely(srf->sizes == NULL)) { 543831cf Thomas Hellstrom 2012-11-20 774 ret = -ENOMEM; 543831cf Thomas Hellstrom 2012-11-20 775 goto out_no_offsets; 543831cf Thomas Hellstrom 2012-11-20 776 }
Quoted 1 line
543831cfThomas Hellstrom 2012-11-20 777
Wauv, that was fast. So, I'm pretty sure this has nothing to do with the patch I just sent, but there's a bug nevertheless. The NULL test has been copy-pasted from just above, but we're testing srf->sizes again, not srf->offsets which we just tried to allocate.
Subject: [PATCH] drm/vmwgfx: check kmalloc return value
srf->sizes has been allocated and checked a few lines above; fix up the copy-pasto so that we check srf->offsets.
--- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +1 -1
@@ -770,7 +770,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data, } srf->offsets =kmalloc (srf->num_sizes *sizeof (*srf->offsets),GFP_KERNEL ); -if (unlikely (srf->sizes ==NULL )) { +if (unlikely (srf->offsets ==NULL )) { ret = -ENOMEM ; goto out_no_offsets; }