drm/vmwgfx: Use struct_size() helper
authorGustavo A. R. Silva <gustavoars@kernel.org>
Wed, 17 Jun 2020 21:51:44 +0000 (16:51 -0500)
committerRoland Scheidegger <sroland@vmware.com>
Tue, 11 Aug 2020 01:16:02 +0000 (03:16 +0200)
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 <gustavoars@kernel.org>
Signed-off-by: Roland Scheidegger <sroland@vmware.com>
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c

index 126f93c0b0b89b5898853ab9329902a9cec9af3b..3914bfee0533b578a176a2de9de51ceb33a2ea82 100644 (file)
@@ -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);