Message ID | 20230816063143.1003676-1-liaoyu15@huawei.com |
---|---|
State | Superseded |
Headers | show |
Series | [v2,-next] media: use struct_size() helper | expand |
On Wed, Aug 16, 2023 at 3:35 PM Yu Liao <liaoyu15@huawei.com> wrote: > > 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> > --- > > v1 -> v2: > - use struct_size() since vec is declared > > drivers/media/common/videobuf2/frame_vector.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/media/common/videobuf2/frame_vector.c b/drivers/media/common/videobuf2/frame_vector.c > index 0f430ddc1f67..ff1c3ebee4b0 100644 > --- a/drivers/media/common/videobuf2/frame_vector.c > +++ b/drivers/media/common/videobuf2/frame_vector.c > @@ -157,7 +157,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; > -- > 2.25.1 > Reviewed-by: Tomasz Figa <tfiga@chromium.org> Best regards, Tomasz
diff --git a/drivers/media/common/videobuf2/frame_vector.c b/drivers/media/common/videobuf2/frame_vector.c index 0f430ddc1f67..ff1c3ebee4b0 100644 --- a/drivers/media/common/videobuf2/frame_vector.c +++ b/drivers/media/common/videobuf2/frame_vector.c @@ -157,7 +157,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;
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> --- v1 -> v2: - use struct_size() since vec is declared drivers/media/common/videobuf2/frame_vector.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)