From patchwork Thu Jul 28 20:48:41 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 1017762 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p6SKmlS2013408 for ; Thu, 28 Jul 2011 20:48:59 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755292Ab1G1Us5 (ORCPT ); Thu, 28 Jul 2011 16:48:57 -0400 Received: from smtp1.linux-foundation.org ([140.211.169.13]:54586 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754942Ab1G1Us4 (ORCPT ); Thu, 28 Jul 2011 16:48:56 -0400 Received: from imap1.linux-foundation.org (imap1.linux-foundation.org [140.211.169.55]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p6SKmgIK025568 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 28 Jul 2011 13:48:42 -0700 Received: from localhost.localdomain (localhost [127.0.0.1]) by imap1.linux-foundation.org (8.13.5.20060308/8.13.5/Debian-3ubuntu1.1) with ESMTP id p6SKmfVA007582; Thu, 28 Jul 2011 13:48:41 -0700 Message-Id: <201107282048.p6SKmfVA007582@imap1.linux-foundation.org> Subject: [patch 2/5] thermal: split hwmon lookup to a separate function To: lenb@kernel.org Cc: linux-acpi@vger.kernel.org, akpm@linux-foundation.org, khali@linux-fr.org, guenter.roeck@ericsson.com, len.brown@intel.com, rene.herman@gmail.com From: akpm@linux-foundation.org Date: Thu, 28 Jul 2011 13:48:41 -0700 MIME-Version: 1.0 X-Spam-Status: No, hits=-103.474 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SUBJECT_BRACKETED, USER_IN_WHITELIST X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf$Revision: 1.188 $ X-Scanned-By: MIMEDefang 2.63 on 140.211.169.13 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 28 Jul 2011 20:49:00 +0000 (UTC) From: Jean Delvare We'll soon need to reuse it. Signed-off-by: Jean Delvare Cc: Rene Herman Cc: Len Brown Acked-by: Guenter Roeck Signed-off-by: Andrew Morton --- drivers/thermal/thermal_sys.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff -puN drivers/thermal/thermal_sys.c~thermal-split-hwmon-lookup-to-a-separate-function drivers/thermal/thermal_sys.c --- a/drivers/thermal/thermal_sys.c~thermal-split-hwmon-lookup-to-a-separate-function +++ a/drivers/thermal/thermal_sys.c @@ -469,22 +469,35 @@ temp_crit_show(struct device *dev, struc } -static int -thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) +static struct thermal_hwmon_device * +thermal_hwmon_lookup_by_type(const struct thermal_zone_device *tz) { struct thermal_hwmon_device *hwmon; - int new_hwmon_device = 1; - int result; mutex_lock(&thermal_list_lock); list_for_each_entry(hwmon, &thermal_hwmon_list, node) if (!strcmp(hwmon->type, tz->type)) { - new_hwmon_device = 0; mutex_unlock(&thermal_list_lock); - goto register_sys_interface; + return hwmon; } mutex_unlock(&thermal_list_lock); + return NULL; +} + +static int +thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) +{ + struct thermal_hwmon_device *hwmon; + int new_hwmon_device = 1; + int result; + + hwmon = thermal_hwmon_lookup_by_type(tz); + if (hwmon) { + new_hwmon_device = 0; + goto register_sys_interface; + } + hwmon = kzalloc(sizeof(struct thermal_hwmon_device), GFP_KERNEL); if (!hwmon) return -ENOMEM;