From patchwork Tue May 31 06:18:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9143395 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E106F60777 for ; Tue, 31 May 2016 06:21:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5CBF281ED for ; Tue, 31 May 2016 06:21:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAAF32821C; Tue, 31 May 2016 06:21:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48AA9281ED for ; Tue, 31 May 2016 06:21:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756034AbcEaGUz (ORCPT ); Tue, 31 May 2016 02:20:55 -0400 Received: from mail-pa0-f66.google.com ([209.85.220.66]:32961 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756028AbcEaGUw (ORCPT ); Tue, 31 May 2016 02:20:52 -0400 Received: by mail-pa0-f66.google.com with SMTP id f8so23994415pag.0; Mon, 30 May 2016 23:20:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Pfur4wB3QGjz9WNDQ6fQ1ylULnSSYuOYuxW37+Dj1jA=; b=rpsiIJ/29Ov3W51A3inTQok/UDRYQ3w7xebDzZfwvrBZCQfUiRJ+pXFuGkA8Ut4fut j2S5THCrySvBeGgSgsuBCFPF4cspI+Jn2wQNhwobuKiiKG7xefiQKYk2T7r3xAENHUNP mFxzxl+q1g0bhlcwJYWo8a3cVW4ybK5l3saq+m+DQQRab7r+ckPpwQpAKqiKqnRfnwTU ZAXlVW+w5qWEQFzuCkOXSQvPga8z3Kr6OzRcc79csWCW2aaOoC3WAnRDo5d1BE1YLnan +yFu32lXJtcWoO3sqUsm2M+hLX3vvtzCaPb8v1xKQcwIC/YQjoCV8dPZcVf1fFDxqJqm sU7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Pfur4wB3QGjz9WNDQ6fQ1ylULnSSYuOYuxW37+Dj1jA=; b=Ky6E24Yy4WyWLubLPk3lplSmMVdNvhzkl4Dc5GYOu57PdDeux2wFbc069B0NhE830S oWbmAxtKZRK50apCGpFO+rpBl4wTC/QyCuigACUQIe/3Lp9jfgxWLmASpfGEv+2hCO/h xcVSdBy0/GzNv4e11roem6oJdC49lN/xoTJ+syvJ0CcUQGpCtGxRcTNOZP6SJq75DIkh nL4H0KOd4YFHUjB02aZTi4kgzVE+qiYJuJGiz8nerfZ2kI7qNXHgdSp2myJUV8sUPs6v pt9VBf+IYK8Pp3uOwOl25Z8wl8PK/UPsooFZ289eOWdqmxDi/Dx66jy69qNRMkbuwx97 shBQ== X-Gm-Message-State: ALyK8tKu7hNIxvGV8CZofHQNmD/X6v1TpJ7xAo5hF4yFnGpzUY3toVoa7GVZ2vbV4vO0qg== X-Received: by 10.66.65.133 with SMTP id x5mr53235203pas.108.1464675651784; Mon, 30 May 2016 23:20:51 -0700 (PDT) Received: from localhost ([2601:b00:c501:3660:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id m81sm23839366pfi.51.2016.05.30.23.20.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2016 23:20:51 -0700 (PDT) From: Eduardo Valentin To: Rui Zhang Cc: Linux PM , LKML , Keerthy , Eduardo Valentin Subject: [PATCHv4 48/48] thermal: sysfs: use kcalloc() instead of kzalloc() Date: Mon, 30 May 2016 23:18:55 -0700 Message-Id: <1464675535-2433-49-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464675535-2433-1-git-send-email-edubezval@gmail.com> References: <1464675535-2433-1-git-send-email-edubezval@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Simplify size computation by using kcalloc() for allocating memory for arrays. Cc: Zhang Rui Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- drivers/thermal/thermal_sysfs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index ca4b83a..4136b71 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -505,22 +505,25 @@ static const struct attribute_group *thermal_zone_attribute_groups[] = { */ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) { - int size = sizeof(struct thermal_attr) * tz->trips; struct attribute **attrs; int indx; - tz->trip_type_attrs = kzalloc(size, GFP_KERNEL); + tz->trip_type_attrs = kcalloc(tz->trips, sizeof(*tz->trip_type_attrs), + GFP_KERNEL); if (!tz->trip_type_attrs) return -ENOMEM; - tz->trip_temp_attrs = kzalloc(size, GFP_KERNEL); + tz->trip_temp_attrs = kcalloc(tz->trips, sizeof(*tz->trip_temp_attrs), + GFP_KERNEL); if (!tz->trip_temp_attrs) { kfree(tz->trip_type_attrs); return -ENOMEM; } if (tz->ops->get_trip_hyst) { - tz->trip_hyst_attrs = kzalloc(size, GFP_KERNEL); + tz->trip_hyst_attrs = kcalloc(tz->trips, + sizeof(*tz->trip_hyst_attrs), + GFP_KERNEL); if (!tz->trip_hyst_attrs) { kfree(tz->trip_type_attrs); kfree(tz->trip_temp_attrs); @@ -528,7 +531,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) } } - attrs = kzalloc(sizeof(*attrs) * tz->trips * 3 + 1, GFP_KERNEL); + attrs = kcalloc(tz->trips * 3 + 1, sizeof(*attrs), GFP_KERNEL); if (!attrs) { kfree(tz->trip_type_attrs); kfree(tz->trip_temp_attrs);