Commit 77cf3a68 authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva Committed by Gerd Hoffmann

drm/virtio: 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.

This code was detected with the help of Coccinelle and, audited and
fixed manually.
Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20200617215707.GA16785@embeddedorSigned-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
parent 66c8ef90
......@@ -154,9 +154,8 @@ void virtio_gpu_gem_object_close(struct drm_gem_object *obj,
struct virtio_gpu_object_array *virtio_gpu_array_alloc(u32 nents)
{
struct virtio_gpu_object_array *objs;
size_t size = sizeof(*objs) + sizeof(objs->objs[0]) * nents;
objs = kmalloc(size, GFP_KERNEL);
objs = kmalloc(struct_size(objs, objs, nents), GFP_KERNEL);
if (!objs)
return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment