drm/nouveau/mmu: use struct_size() helper
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Fri, 24 May 2019 17:15:36 +0000 (12:15 -0500)
committerBen Skeggs <bskeggs@redhat.com>
Fri, 23 Aug 2019 02:55:31 +0000 (12:55 +1000)
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@embeddedor.com>
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/nvif/mmu.c

index ae08a1ca804484b6329a5712474b158ea6b6d7ea..5641bda2046da6efb3d73cca0f5adde90ef13ae2 100644 (file)
@@ -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;