* [PATCH] drm/nouveau/mmu: use struct_size() helper
@ 2019-05-24 17:15 Gustavo A. R. Silva
2019-05-27 6:21 ` [Nouveau] " Ben Skeggs
0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2019-05-24 17:15 UTC (permalink / raw)
To: Ben Skeggs, David Airlie, Daniel Vetter
Cc: dri-devel, nouveau, 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, 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>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Nouveau] [PATCH] drm/nouveau/mmu: use struct_size() helper
2019-05-24 17:15 [PATCH] drm/nouveau/mmu: use struct_size() helper Gustavo A. R. Silva
@ 2019-05-27 6:21 ` Ben Skeggs
0 siblings, 0 replies; 2+ messages in thread
From: Ben Skeggs @ 2019-05-27 6:21 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Ben Skeggs, David Airlie, Daniel Vetter, nouveau, linux-kernel,
dri-devel
On Sat, 25 May 2019 at 03:35, Gustavo A. R. Silva
<gustavo@embeddedor.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@embeddedor.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@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/nouveau
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-05-27 6:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-24 17:15 [PATCH] drm/nouveau/mmu: use struct_size() helper Gustavo A. R. Silva
2019-05-27 6:21 ` [Nouveau] " Ben Skeggs
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).