From: akpm@linux-foundation.org Subject: [patch 2/5] thermal: split hwmon lookup to a separate function Date: Thu, 28 Jul 2011 13:48:41 -0700 Message-ID: <201107282048.p6SKmfVA007582@imap1.linux-foundation.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ASCII Content-Transfer-Encoding: 8bit Return-path: 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 Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org 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: 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; _