Skip to content

Commit fc2ef5b

Browse files
luoqingAndi Shyti
authored andcommitted
selftests: i915: Use struct_size() helper in kmalloc()
Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. Signed-off-by: luoqing <luoqing@kylinos.cn> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> Signed-off-by: Andi Shyti <andi.shyti@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20250208013539.3586855-1-l1138897701@163.com
1 parent 8d83346 commit fc2ef5b

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/gpu/drm/i915/gem/selftests/mock_dmabuf.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ static struct dma_buf *mock_dmabuf(int npages)
103103
struct dma_buf *dmabuf;
104104
int i;
105105

106-
mock = kmalloc(sizeof(*mock) + npages * sizeof(struct page *),
107-
GFP_KERNEL);
106+
mock = kmalloc(struct_size(mock, pages, npages), GFP_KERNEL);
108107
if (!mock)
109108
return ERR_PTR(-ENOMEM);
110109

0 commit comments

Comments
 (0)