From: Shen Lichuan Date: Mon, 26 Aug 2024 03:46:38 +0000 (+0800) Subject: media: pvrusb2: Use kmemdup_array instead of kmemdup for multiple allocation X-Git-Tag: v6.13-rc1~149^2~192 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=4510319676bdf96da819599643809e5155ef3460;p=linux-block.git 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 Signed-off-by: Hans Verkuil --- diff --git a/drivers/media/usb/pvrusb2/pvrusb2-io.c b/drivers/media/usb/pvrusb2/pvrusb2-io.c index 675dc7153e2b..28ffe7981f8c 100644 --- a/drivers/media/usb/pvrusb2/pvrusb2-io.c +++ b/drivers/media/usb/pvrusb2/pvrusb2-io.c @@ -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);