From patchwork Tue Nov 22 17:57:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 9441859 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 120B9605EE for ; Tue, 22 Nov 2016 18:03:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 085CE285C4 for ; Tue, 22 Nov 2016 18:03:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F109E285C6; Tue, 22 Nov 2016 18:02:59 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 79E5427FC0 for ; Tue, 22 Nov 2016 18:02:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933808AbcKVSAD (ORCPT ); Tue, 22 Nov 2016 13:00:03 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:60543 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933616AbcKVSAC (ORCPT ); Tue, 22 Nov 2016 13:00:02 -0500 Received: from localhost ([127.0.0.1] helo=[127.0.1.1]) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1c9FJZ-0000Ww-JW; Tue, 22 Nov 2016 18:57:05 +0100 Message-Id: <20161122175357.029139356@linutronix.de> User-Agent: quilt/0.63-1 Date: Tue, 22 Nov 2016 17:57:05 -0000 From: Thomas Gleixner To: LKML Cc: Rui Zhang , edubezval@gmail.com, Peter Zijlstra , Borislav Petkov , linux-pm@vger.kernel.org, x86@kernel.org, rt@linutronix.de, Srinivas Pandruvada Subject: [patch V2 02/12] thermal/x86_pkg_temp: Remove redundant package search References: <20161122175256.922158782@linutronix.de> MIME-Version: 1.0 Content-Disposition: inline; filename=thermalx86_pkg_temp_Remove_redundant_package_search.patch 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 In pkg_temp_thermal_device_remove() the package device is searched at the beginning of the function. When the device refcount becomes zero another search for the same device is conducted. Remove the pointless loop and use the device pointer which was retrieved at the beginning of the function. Signed-off-by: Thomas Gleixner --- drivers/thermal/x86_pkg_temp_thermal.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/drivers/thermal/x86_pkg_temp_thermal.c +++ b/drivers/thermal/x86_pkg_temp_thermal.c @@ -479,10 +479,8 @@ static int pkg_temp_thermal_device_add(u static int pkg_temp_thermal_device_remove(unsigned int cpu) { - struct phy_dev_entry *n; + struct phy_dev_entry *phdev = pkg_temp_thermal_get_phy_entry(cpu); u16 phys_proc_id = topology_physical_package_id(cpu); - struct phy_dev_entry *phdev = - pkg_temp_thermal_get_phy_entry(cpu); if (!phdev) return -ENODEV; @@ -503,22 +501,19 @@ static int pkg_temp_thermal_device_remov --phdev->ref_cnt; pr_debug("thermal_device_remove: pkg: %d cpu %d ref_cnt %d\n", phys_proc_id, cpu, phdev->ref_cnt); - if (!phdev->ref_cnt) - list_for_each_entry_safe(phdev, n, &phy_dev_list, list) { - if (phdev->phys_proc_id == phys_proc_id) { - thermal_zone_device_unregister(phdev->tzone); - /* - * Restore original MSR value for package - * thermal interrupt. - */ - wrmsr_on_cpu(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, - phdev->start_pkg_therm_low, - phdev->start_pkg_therm_high); - list_del(&phdev->list); - kfree(phdev); - break; - } - } + + if (!phdev->ref_cnt) { + thermal_zone_device_unregister(phdev->tzone); + /* + * Restore original MSR value for package thermal + * interrupt. + */ + wrmsr_on_cpu(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, + phdev->start_pkg_therm_low, + phdev->start_pkg_therm_high); + list_del(&phdev->list); + kfree(phdev); + } mutex_unlock(&phy_dev_list_mutex); return 0;