media: use struct_size() helper
authorYu Liao <liaoyu15@huawei.com>
Wed, 16 Aug 2023 06:31:43 +0000 (14:31 +0800)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Wed, 27 Sep 2023 07:40:01 +0000 (09:40 +0200)
Prefer struct_size() over open-coded versions of idiom:

sizeof(struct-with-flex-array) + sizeof(typeof-flex-array-elements) * count

where count is the max number of items the flexible array is supposed to
contain.

Signed-off-by: Yu Liao <liaoyu15@huawei.com>
Reviewed-by: Tomasz Figa <tfiga@chromium.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/common/videobuf2/frame_vector.c

index fd87747be9b177c07c25048a62fbbded363fab5e..41f289c75cbb6e17c928265a226fc9cb3cef31c2 100644 (file)
@@ -159,7 +159,7 @@ EXPORT_SYMBOL(frame_vector_to_pfns);
 struct frame_vector *frame_vector_create(unsigned int nr_frames)
 {
        struct frame_vector *vec;
-       int size = sizeof(struct frame_vector) + sizeof(void *) * nr_frames;
+       int size = struct_size(vec, ptrs, nr_frames);
 
        if (WARN_ON_ONCE(nr_frames == 0))
                return NULL;