From patchwork Tue Nov 8 05:09:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9416489 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 77BF360512 for ; Tue, 8 Nov 2016 05:11:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6905428B9A for ; Tue, 8 Nov 2016 05:11:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CC4D28B9C; Tue, 8 Nov 2016 05:11:46 +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 08C4728B9A for ; Tue, 8 Nov 2016 05:11:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753439AbcKHFL0 (ORCPT ); Tue, 8 Nov 2016 00:11:26 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34024 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753511AbcKHFLY (ORCPT ); Tue, 8 Nov 2016 00:11:24 -0500 Received: by mail-pf0-f196.google.com with SMTP id y68so18088948pfb.1; Mon, 07 Nov 2016 21:11:24 -0800 (PST) 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=kmEePumEOpEqI/XWEyLO4VF+R0D0+o6eP0qI/xhk3LQ=; b=e+iZWOKPhqi4PpOFF3vctdV7PMa4OIknYTt0G/8GK19EWfi9SPnSRRvFYYPnapAXNQ g23KgcDcUmFgKyQI1vXGcTY5QfTnGUY2h35eZgcf4sikIhcOIGSlLiF+0SjvATOE+/My sBDVok2QnuaVcWDLDZrWSqeO3fXLaSV7MllABQXoZU0xJsC+Ff4xPzTcFvveemsoVsoD sHB1khWEyj2zky/n0mGNwfrq4SDgpdpUzkN6TVLBWbdb3/NTZHBgz5ZpGttPIPyxXp+0 KRUf0VUuycUMP9LIi/a/Z3vhwQSbxYF+9xVj9bPGAmy0MbDEMAx99y1kIrvMp2CT07Y0 bYcA== 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=kmEePumEOpEqI/XWEyLO4VF+R0D0+o6eP0qI/xhk3LQ=; b=UtByqdpbpHdWz+rfpbTZ9W/FUqXqFJAK53nOogFHuH4A6Zo2sl56B/F4i/PIiekh8d /pf+y+GSRWnljPQfXrhfBETyCgk4a3UzASSNDiVE4GskFhT2GqJ/Z4CRB5vhKuafQwP2 tf7MAhfKwnPRaInWHVuRdMsV/4J+lfKFjxOyHbT8djQwa65ntFK1LdR9A+t0xW/x5q0v fgme118UaDVb8F3lA4kN/UjJ/lSNP3MhS42Ipa1bl3NEV1V1+TN6GhzGzXT9JtXYhs0H ocFn8fnDJq9e0KOvbWO0QtEFeEA5/HecEb7talO5Cd+uI9ifr4EfERZdNp4h95MADl3z yRKw== X-Gm-Message-State: ABUngvdDyBDK3FldyhRbf6KuegoNyxKmNrxqSvTMtEMTPxnenP7Pe6CnhaTqVDogf9vIEw== X-Received: by 10.98.207.195 with SMTP id b186mr19994167pfg.40.1478581878744; Mon, 07 Nov 2016 21:11:18 -0800 (PST) Received: from localhost ([2601:647:4401:a2f0:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id pe4sm36678054pac.6.2016.11.07.21.11.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Nov 2016 21:11:18 -0800 (PST) From: Eduardo Valentin To: Rui Zhang Cc: LKML , Linux PM , Eduardo Valentin Subject: [PATCHv2 48/49] thermal: sysfs: use kcalloc() instead of kzalloc() Date: Mon, 7 Nov 2016 21:09:26 -0800 Message-Id: <1478581767-7009-49-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1478581767-7009-1-git-send-email-edubezval@gmail.com> References: <1478581767-7009-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 4807015..a694de9 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -511,7 +511,6 @@ 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; @@ -519,18 +518,22 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) if (tz->trips <= 0) return -EINVAL; - 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); @@ -538,7 +541,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);