lkml.org 
[lkml]   [2023]   [Jul]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] stm class: Use struct_size()
Date
Use struct_size() instead of hand-writing it, when allocating a structure
with a flex array.

This is less verbose, more robust and more informative.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
It will also be helpful if the __counted_by() annotation is added with a
Coccinelle script such as:
https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=devel/counted_by&id=adc5b3cb48a049563dc673f348eab7b6beba8a9b
---
drivers/hwtracing/stm/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
index 534fbefc7f6a..2195310ab81c 100644
--- a/drivers/hwtracing/stm/core.c
+++ b/drivers/hwtracing/stm/core.c
@@ -863,7 +863,7 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data,
return -EINVAL;

nmasters = stm_data->sw_end - stm_data->sw_start + 1;
- stm = vzalloc(sizeof(*stm) + nmasters * sizeof(void *));
+ stm = vzalloc(struct_size(stm, masters, nmasters));
if (!stm)
return -ENOMEM;

--
2.34.1
\
 
 \ /
  Last update: 2023-07-22 22:08    [W:0.956 / U:0.468 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site