From: Gustavo A. R. Silva Date: Wed, 17 Jun 2020 21:51:44 +0000 (-0500) Subject: drm/vmwgfx: Use struct_size() helper X-Git-Tag: locking-urgent-2020-08-15~9^2~1^2~7 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=4f88b4ccb7036ce523b3c031d1226d6eda36417b;p=users%2Fdwmw2%2Flinux.git drm/vmwgfx: Use struct_size() helper 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: Gustavo A. R. Silva Signed-off-by: Roland Scheidegger --- diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c index 126f93c0b0b89..3914bfee0533b 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c @@ -1969,7 +1969,7 @@ static int vmw_surface_dirty_alloc(struct vmw_resource *res) num_mip = 1; num_subres = num_layers * num_mip; - dirty_size = sizeof(*dirty) + num_subres * sizeof(dirty->boxes[0]); + dirty_size = struct_size(dirty, boxes, num_subres); acc_size = ttm_round_pot(dirty_size); ret = ttm_mem_global_alloc(vmw_mem_glob(res->dev_priv), acc_size, &ctx);