From: Markus Elfring <[email protected]>
Date: Sun, 4 Sep 2016 17:28:13 +0200

* A multiplication for the size determination of a memory allocation
  indicated that an array data structure should be processed.
  Thus use the corresponding function "kmalloc_array".

  This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
 arch/x86/events/intel/cqm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/events/intel/cqm.c b/arch/x86/events/intel/cqm.c
index 783c49d..ec61522 100644
--- a/arch/x86/events/intel/cqm.c
+++ b/arch/x86/events/intel/cqm.c
@@ -1651,8 +1651,9 @@ static int intel_mbm_init(void)
                goto out;
        }
 
-       array_size = sizeof(struct hrtimer) * mbm_socket_max;
-       mbm_timers = kmalloc(array_size, GFP_KERNEL);
+       mbm_timers = kmalloc_array(mbm_socket_max,
+                                  sizeof(*mbm_timers),
+                                  GFP_KERNEL);
        if (!mbm_timers) {
                ret = -ENOMEM;
                goto out;
-- 
2.9.3

Reply via email to