dma-buf: use struct_size macro
PATCH 1/1 dma-buf: use struct_size macro
Instead of manually calculating the structure size.
--- drivers/dma-buf/dma-resv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/dma-resv.c +1 -1
@@ -63,7 +63,7 @@ static struct dma_resv_list *dma_resv_list_alloc(unsigned int shared_max) {struct dma_resv_list *list; - list = kmalloc(offsetof(typeof(*list), shared[shared_max]), GFP_KERNEL); + list =kmalloc (struct_size (list, shared, shared_max),GFP_KERNEL );if (!list)return NULL ;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 4 lines · Christian König
Instead of manually calculating the structure size.
Signed-off-by Christian König <[email protected]>
Quoted 24 lines
--- drivers/dma-buf/dma-resv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/dma-buf/dma-resv.c +1
-2@@ -63,7 +63,7 @@ static struct dma_resv_list *dma_resv_list_alloc(unsigned int shared_max) {struct dma_resv_list *list; - list = kmalloc(offsetof(typeof(*list), shared[shared_max]), GFP_KERNEL); + list =kmalloc (struct_size (list, shared, shared_max),GFP_KERNEL );if (!list)return NULL ; --2.17.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 08.10.20 um 10:17 schrieb Daniel Vetter:
Quoted 6 lines
Quoted 3 lines · Christian König
Instead of manually calculating the structure size.
Signed-off-by Christian König <[email protected]>Reviewed-by Daniel Vetter <[email protected]>
Thanks, could anybody (not me) come up with a cocci script for this?
I'm pretty sure we have used this pattern more than once in the kernel.
Thanks,
Christian.
Quoted 18 lines
Quoted 18 lines
--- drivers/dma-buf/dma-resv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/dma-buf/dma-resv.c +1
-1@@ -63,7 +63,7 @@ static struct dma_resv_list *dma_resv_list_alloc(unsigned int shared_max) {struct dma_resv_list *list; - list = kmalloc(offsetof(typeof(*list), shared[shared_max]), GFP_KERNEL); + list =kmalloc (struct_size (list, shared, shared_max),GFP_KERNEL );if (!list)return NULL ;
Quoted 9 lines
Quoted 7 lines
--
2.17.1_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gustavo A. R. Silva
Reviewed-byQuoted 7 lines · Christian König
Am 08.10.20 um 10:17 schrieb Daniel Vetter:
Quoted 6 lines
Quoted 3 lines · Christian König
Instead of manually calculating the structure size.
Signed-off-by Christian König <[email protected]>Reviewed-by Daniel Vetter <[email protected]>
Quoted 5 lines
Thanks, could anybody (not me) come up with a cocci script for this?
I'm pretty sure we have used this pattern more than once in the kernel.
Sure thing. I'll take care of that. I saw this same pattern, recently[1]:
"
Review
Quoted 4 lines
(quoted diff) +4
-0+ size = offsetof(struct pmt_crashlog_priv, entry[pdev->num_resources]); + priv = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); + if (!priv) + return -ENOMEM;
struct_size()
"
[1] https://lore.kernel.org/lkml/CAHp75VcP58Ub=gmbRVy0TPJtntKvnQZoi3tOakxE0qsEqzGPVA@mail.gmail.com/
Thanks
--
Gustavo
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
--- drivers/dma-buf/dma-resv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/dma-buf/dma-resv.c +1
-2@@ -63,7 +63,7 @@ static struct dma_resv_list *dma_resv_list_alloc(unsigned int shared_max) {struct dma_resv_list *list; - list = kmalloc(offsetof(typeof(*list), shared[shared_max]), GFP_KERNEL); + list =kmalloc (struct_size (list, shared, shared_max),GFP_KERNEL );if (!list)return NULL ; --2.17.1
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel