* [PATCH][next] drm/vmwgfx: Use struct_size() helper
@ 2020-06-17 21:51 Gustavo A. R. Silva
2020-06-22 15:50 ` Roland Scheidegger
0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2020-06-17 21:51 UTC (permalink / raw)
To: VMware Graphics, Roland Scheidegger, David Airlie, Daniel Vetter
Cc: dri-devel, linux-kernel, Gustavo A. R. Silva
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>
---
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
index 126f93c0b0b8..3914bfee0533 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);
--
2.27.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH][next] drm/vmwgfx: Use struct_size() helper
2020-06-17 21:51 [PATCH][next] drm/vmwgfx: Use struct_size() helper Gustavo A. R. Silva
@ 2020-06-22 15:50 ` Roland Scheidegger
0 siblings, 0 replies; 2+ messages in thread
From: Roland Scheidegger @ 2020-06-22 15:50 UTC (permalink / raw)
To: Gustavo A. R. Silva, VMware Graphics, David Airlie, Daniel Vetter
Cc: dri-devel, linux-kernel, Gustavo A. R. Silva
I've commited this to our next branch, thanks!
(I'm actually kind of impressed this can be found automatically...)
Roland
Am 17.06.20 um 23:51 schrieb Gustavo A. R. Silva:
> 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>
> ---
> drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
> index 126f93c0b0b8..3914bfee0533 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);
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-22 15:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-17 21:51 [PATCH][next] drm/vmwgfx: Use struct_size() helper Gustavo A. R. Silva
2020-06-22 15:50 ` Roland Scheidegger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).