[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CACAvsv53mxOyQCyxxAoTkxocMTPedPb5F2orYAM8K_JcPuYGtw@mail.gmail.com>
Date: Mon, 27 May 2019 16:21:42 +1000
From: Ben Skeggs <skeggsb@...il.com>
To: "Gustavo A. R. Silva" <gustavo@...eddedor.com>
Cc: Ben Skeggs <bskeggs@...hat.com>, David Airlie <airlied@...ux.ie>,
Daniel Vetter <daniel@...ll.ch>, nouveau@...ts.freedesktop.org,
linux-kernel@...r.kernel.org, dri-devel@...ts.freedesktop.org
Subject: Re: [Nouveau] [PATCH] drm/nouveau/mmu: use struct_size() helper
On Sat, 25 May 2019 at 03:35, Gustavo A. R. Silva
<gustavo@...eddedor.com> wrote:
>
> Make use of the struct_size() helper instead of an open-coded version
> in order to avoid any potential type mistakes, in particular in the
> context in which this code is being used.
>
> So, replace the following form:
>
> sizeof(*kind) + sizeof(*kind->data) * mmu->kind_nr;
>
> with:
>
> struct_size(kind, data, mmu->kind_nr)
>
> This code was detected with the help of Coccinelle.
>
> Signed-off-by: Gustavo A. R. Silva <gustavo@...eddedor.com>
Thanks!
> ---
> drivers/gpu/drm/nouveau/nvif/mmu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nvif/mmu.c b/drivers/gpu/drm/nouveau/nvif/mmu.c
> index ae08a1ca8044..5641bda2046d 100644
> --- a/drivers/gpu/drm/nouveau/nvif/mmu.c
> +++ b/drivers/gpu/drm/nouveau/nvif/mmu.c
> @@ -110,7 +110,7 @@ nvif_mmu_init(struct nvif_object *parent, s32 oclass, struct nvif_mmu *mmu)
>
> if (mmu->kind_nr) {
> struct nvif_mmu_kind_v0 *kind;
> - u32 argc = sizeof(*kind) + sizeof(*kind->data) * mmu->kind_nr;
> + size_t argc = struct_size(kind, data, mmu->kind_nr);
>
> if (ret = -ENOMEM, !(kind = kmalloc(argc, GFP_KERNEL)))
> goto done;
> --
> 2.21.0
>
> _______________________________________________
> Nouveau mailing list
> Nouveau@...ts.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/nouveau
Powered by blists - more mailing lists