powercap: intel_rapl: Optimize rp->domains memory allocation
authorxiongxin <xiongxin@kylinos.cn>
Fri, 7 Apr 2023 02:47:59 +0000 (10:47 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 1 Aug 2023 11:54:00 +0000 (13:54 +0200)
In the memory allocation of rp->domains in rapl_detect_domains(), there
is an additional memory of struct rapl_domain allocated, optimize the
code here to save sizeof(struct rapl_domain) bytes of memory.

Test in Intel NUC (i5-1135G7).

Signed-off-by: xiongxin <xiongxin@kylinos.cn>
Tested-by: xiongxin <xiongxin@kylinos.cn>
Reviewed-by: Srinivas Pandruvada<srinivas.pandruvada@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/powercap/intel_rapl_common.c

index 4e646e5..5e2a1c3 100644 (file)
@@ -1485,7 +1485,7 @@ static int rapl_detect_domains(struct rapl_package *rp)
        }
        pr_debug("found %d domains on %s\n", rp->nr_domains, rp->name);
 
-       rp->domains = kcalloc(rp->nr_domains + 1, sizeof(struct rapl_domain),
+       rp->domains = kcalloc(rp->nr_domains, sizeof(struct rapl_domain),
                              GFP_KERNEL);
        if (!rp->domains)
                return -ENOMEM;