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

Configure Feed

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

drm/vmwgfx: Add error path for xa_store in vmw_bo_add_detached_resource

The xa_store() may fail due to memory allocation failure because there
is no guarantee that the index is already used. This fix introduces new
paths to handle the error.

This patch also aligns the order of function calls by calling
vmw_bo_add_detached_resource() before ttm_prime_object_init() in order
to allow consistent error handling.

Fixes: d6667f0ddf46 ("drm/vmwgfx: Fix handling of dumb buffers")
Signed-off-by: Keisuke Nishimura <keisuke.nishimura@inria.fr>
Signed-off-by: Zack Rusin <zack.rusin@broadcom.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250225145223.34773-1-keisuke.nishimura@inria.fr

authored by

Keisuke Nishimura and committed by
Zack Rusin
3282422b 0039a3b3

+17 -5
+2 -2
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
··· 848 848 vmw_bo_placement_set(bo, domain, domain); 849 849 } 850 850 851 - void vmw_bo_add_detached_resource(struct vmw_bo *vbo, struct vmw_resource *res) 851 + int vmw_bo_add_detached_resource(struct vmw_bo *vbo, struct vmw_resource *res) 852 852 { 853 - xa_store(&vbo->detached_resources, (unsigned long)res, res, GFP_KERNEL); 853 + return xa_err(xa_store(&vbo->detached_resources, (unsigned long)res, res, GFP_KERNEL)); 854 854 } 855 855 856 856 void vmw_bo_del_detached_resource(struct vmw_bo *vbo, struct vmw_resource *res)
+1 -1
drivers/gpu/drm/vmwgfx/vmwgfx_bo.h
··· 141 141 struct ttm_resource *mem); 142 142 void vmw_bo_swap_notify(struct ttm_buffer_object *bo); 143 143 144 - void vmw_bo_add_detached_resource(struct vmw_bo *vbo, struct vmw_resource *res); 144 + int vmw_bo_add_detached_resource(struct vmw_bo *vbo, struct vmw_resource *res); 145 145 void vmw_bo_del_detached_resource(struct vmw_bo *vbo, struct vmw_resource *res); 146 146 struct vmw_surface *vmw_bo_surface(struct vmw_bo *vbo); 147 147
+14 -2
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
··· 838 838 vmw_resource_unreference(&res); 839 839 goto out_unlock; 840 840 } 841 - vmw_bo_add_detached_resource(res->guest_memory_bo, res); 841 + 842 + ret = vmw_bo_add_detached_resource(res->guest_memory_bo, res); 843 + if (unlikely(ret != 0)) { 844 + vmw_resource_unreference(&res); 845 + goto out_unlock; 846 + } 842 847 } 843 848 844 849 tmp = vmw_resource_reference(&srf->res); ··· 1642 1637 1643 1638 } 1644 1639 1640 + if (res->guest_memory_bo) { 1641 + ret = vmw_bo_add_detached_resource(res->guest_memory_bo, res); 1642 + if (unlikely(ret != 0)) { 1643 + vmw_resource_unreference(&res); 1644 + goto out_unlock; 1645 + } 1646 + } 1647 + 1645 1648 tmp = vmw_resource_reference(res); 1646 1649 ret = ttm_prime_object_init(tfile, res->guest_memory_size, &user_srf->prime, 1647 1650 VMW_RES_SURFACE, ··· 1664 1651 rep->handle = user_srf->prime.base.handle; 1665 1652 rep->backup_size = res->guest_memory_size; 1666 1653 if (res->guest_memory_bo) { 1667 - vmw_bo_add_detached_resource(res->guest_memory_bo, res); 1668 1654 rep->buffer_map_handle = 1669 1655 drm_vma_node_offset_addr(&res->guest_memory_bo->tbo.base.vma_node); 1670 1656 rep->buffer_size = res->guest_memory_bo->tbo.base.size;