From patchwork Fri Sep 3 06:01:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 152211 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o835vw7f004362 for ; Fri, 3 Sep 2010 05:57:58 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750900Ab0ICF5x (ORCPT ); Fri, 3 Sep 2010 01:57:53 -0400 Received: from mga02.intel.com ([134.134.136.20]:35121 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750800Ab0ICF5w (ORCPT ); Fri, 3 Sep 2010 01:57:52 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 02 Sep 2010 22:57:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.56,311,1280732400"; d="scan'208";a="551271860" Received: from rui.sh.intel.com (HELO [10.239.51.31]) ([10.239.51.31]) by orsmga002.jf.intel.com with ESMTP; 02 Sep 2010 22:57:51 -0700 Subject: Re: Another bad usage of smp_processor_id From: Zhang Rui To: Maxim Levitsky Cc: "linux-acpi@vger.kernel.org" In-Reply-To: <1283336736.3564.0.camel@maxim-laptop> References: <1283077579.5529.2.camel@maxim-laptop> <1283336736.3564.0.camel@maxim-laptop> Date: Fri, 03 Sep 2010 14:01:02 +0800 Message-ID: <1283493662.2111.3158.camel@rui> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 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.3 (demeter1.kernel.org [140.211.167.41]); Fri, 03 Sep 2010 05:57:58 +0000 (UTC) Index: linux-2.6/arch/x86/kernel/cpu/mcheck/therm_throt.c =================================================================== --- linux-2.6.orig/arch/x86/kernel/cpu/mcheck/therm_throt.c 2010-09-03 10:43:29.000000000 +0800 +++ linux-2.6/arch/x86/kernel/cpu/mcheck/therm_throt.c 2010-09-03 13:38:45.000000000 +0800 @@ -202,14 +202,16 @@ #ifdef CONFIG_SYSFS /* Add/Remove thermal_throttle interface for CPU device: */ -static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev) +static __cpuinit int thermal_throttle_add_dev(unsigned int cpu) { int err; - struct cpuinfo_x86 *c = &cpu_data(smp_processor_id()); + struct sys_device *sys_dev; + struct cpuinfo_x86 *c = &cpu_data(cpu); + sys_dev=get_cpu_sysdev(cpu); err = sysfs_create_group(&sys_dev->kobj, &thermal_attr_group); if (err) - return err; + goto end; if (cpu_has(c, X86_FEATURE_PLN)) err = sysfs_add_file_to_group(&sys_dev->kobj, @@ -224,11 +226,14 @@ &attr_package_power_limit_count.attr, thermal_attr_group.name); +end: + put_cpu(); return err; } -static __cpuinit void thermal_throttle_remove_dev(struct sys_device *sys_dev) +static __cpuinit void thermal_throttle_remove_dev(unsigned int cpu) { + struct sys_device *sys_dev=get_cpu_sysdev(cpu); sysfs_remove_group(&sys_dev->kobj, &thermal_attr_group); } @@ -242,16 +247,13 @@ void *hcpu) { unsigned int cpu = (unsigned long)hcpu; - struct sys_device *sys_dev; int err = 0; - sys_dev = get_cpu_sysdev(cpu); - switch (action) { case CPU_UP_PREPARE: case CPU_UP_PREPARE_FROZEN: mutex_lock(&therm_cpu_lock); - err = thermal_throttle_add_dev(sys_dev); + err = thermal_throttle_add_dev(cpu); mutex_unlock(&therm_cpu_lock); WARN_ON(err); break; @@ -260,7 +262,7 @@ case CPU_DEAD: case CPU_DEAD_FROZEN: mutex_lock(&therm_cpu_lock); - thermal_throttle_remove_dev(sys_dev); + thermal_throttle_remove_dev(cpu); mutex_unlock(&therm_cpu_lock); break; } @@ -287,7 +289,7 @@ #endif /* connect live CPUs to sysfs */ for_each_online_cpu(cpu) { - err = thermal_throttle_add_dev(get_cpu_sysdev(cpu)); + err = thermal_throttle_add_dev(cpu); WARN_ON(err); } #ifdef CONFIG_HOTPLUG_CPU