media: pvrusb2: Use kmemdup_array instead of kmemdup for multiple allocation

Let the kmemdup_array() take care about multiplication
and possible overflows.

Using kmemdup_array() is more appropriate and makes the code
easier to audit.

Signed-off-by: Shen Lichuan <shenlichuan@vivo.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
This commit is contained in:
Shen Lichuan 2024-08-26 11:46:38 +08:00 committed by Hans Verkuil
parent 953c03d8cb
commit 4510319676

View File

@ -335,8 +335,8 @@ static int pvr2_stream_buffer_count(struct pvr2_stream *sp, unsigned int cnt)
if (scnt < sp->buffer_slot_count) {
struct pvr2_buffer **nb = NULL;
if (scnt) {
nb = kmemdup(sp->buffers, scnt * sizeof(*nb),
GFP_KERNEL);
nb = kmemdup_array(sp->buffers, scnt, sizeof(*nb),
GFP_KERNEL);
if (!nb) return -ENOMEM;
}
kfree(sp->buffers);