From: Markus Elfring <[email protected]>
Date: Tue, 13 Sep 2016 17:51:32 +0200

Multiplications for the size determination of memory allocations
indicated that array data structures should be processed.
Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
 drivers/char/agp/compat_ioctl.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
index a48e05b..a2b69db 100644
--- a/drivers/char/agp/compat_ioctl.c
+++ b/drivers/char/agp/compat_ioctl.c
@@ -98,11 +98,15 @@ static int compat_agpioc_reserve_wrap(struct 
agp_file_private *priv, void __user
                if (ureserve.seg_count >= 16384)
                        return -EINVAL;
 
-               usegment = kmalloc(sizeof(*usegment) * ureserve.seg_count, 
GFP_KERNEL);
+               usegment = kmalloc_array(ureserve.seg_count,
+                                        sizeof(*usegment),
+                                        GFP_KERNEL);
                if (!usegment)
                        return -ENOMEM;
 
-               ksegment = kmalloc(sizeof(*ksegment) * kreserve.seg_count, 
GFP_KERNEL);
+               ksegment = kmalloc_array(kreserve.seg_count,
+                                        sizeof(*ksegment),
+                                        GFP_KERNEL);
                if (!ksegment) {
                        kfree(usegment);
                        return -ENOMEM;
-- 
2.10.0

Reply via email to