Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp693447rwl; Fri, 24 Mar 2023 00:10:34 -0700 (PDT) X-Google-Smtp-Source: AKy350b+Eyd0P/8CdfhaMLxYZjwmdPOcQx5XLX0zkscHbRGTa69HfBIMDbIQqdgMEsXkHL0XfLjo X-Received: by 2002:a17:90b:388e:b0:23f:7c8c:4f2d with SMTP id mu14-20020a17090b388e00b0023f7c8c4f2dmr1844062pjb.16.1679641834458; Fri, 24 Mar 2023 00:10:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679641834; cv=none; d=google.com; s=arc-20160816; b=S8TXhVmHcuzxWZ4ANoh0P0okuD2wu10I2pt0aBL58PPX37bRBrELDNMDCQnPhEapL5 X3jEjR9lMC7zPAxd2mOX7nji7EEUhwIQ7Yn42VbeRpXoQDTuA+EBCTpH2pMSkQSEQsJt nKQ+yqxXpK8WZX/ui8EKS7Okj70ryQworXMQqS2f6UioKF617uJjD1ERbqw0jYES5U09 Yn11jxwQgK7Md93cjvTeKVYGdigKHSit6hB1YMowyAciSTJXy9qJwC39DE5Hh3ucmgwS qZhqq0gsTke2RG63vau1xznSzQ4cn8lwJWF+7T+lNy7zDT4QFRJ2dTIL+MzMDqoGBcse mZag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=B7RsG/rKBwQv8qGXUpSzvFhtSda7aZPNKtKUl0neA2c=; b=lRRoogsEbvJ3tPawC8clDDFz2/0PFP3XREZHtOLP0X9f8GpCagkJ/Y3Wo03kpxfLde w/QaRkwlhb6SlEZT2jzoPwAkW3cpOcDuTGzq4Ga9t6//i0LSRUMS6ZxjUn/9jgTDp5eL 8fz2LZ3lhyRpx5NcLv2UnZuhd0VzPcf9KXLt8HZPJhch8+8Ry68LCNxCl8nIoYrV0iW6 XVVlQxCWQ7t4sp3Yomsgox0MA4iDdB5ZwLYPpWkqdnXwqV8C6tVxKVuErNNtqfo1KRnp thVdWFSlltAxQ+qvUyXg1/LHEtPD3VRaHF2fKofv5rIBwxJMZ85sO3UXsq2S84THoRvH bUmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WTsqof7Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kf12-20020a17090305cc00b001a1a8ead6c1si18756950plb.641.2023.03.24.00.10.22; Fri, 24 Mar 2023 00:10:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WTsqof7Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231194AbjCXHIV (ORCPT + 99 others); Fri, 24 Mar 2023 03:08:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230079AbjCXHIR (ORCPT ); Fri, 24 Mar 2023 03:08:17 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A684270B; Fri, 24 Mar 2023 00:08:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679641696; x=1711177696; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=1QwNjA/703mfJcIj5DSMOgyWQ/j+uRh45wv8E+wMysE=; b=WTsqof7QB+w8HsQPQScXcuo8Fw4ijRo5+OJt7cRp/JmkxlF++//1FRAg dLdYVwBn8jVOCr6le+X0/Bdh2MjkgYyqZSxYhzl4SX7S1AvNcjK9+Q47p vYFuxCR7il+hxsl8mKRHMyz5iAGn9sK3Du0S8ktcCa7a6qPrC8qM8VnPV b5L0Tm3u8sCjrmqAp3SFZ2vr8agLUpT6+w2A/se/U4wT0XlLcuz8yROsU QYZ2Mqw5mgH6b8PkVNX4QczPVjqn7a/U6uYOVPJ9+128OiLzuqUs/GiuQ pmRtLSGVs5h2IpnVOFEJUBj3omup+OitRjZh8dZu19KfIHbQ9IcJPkpRc w==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="402296711" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="402296711" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2023 00:08:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="747046047" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="747046047" Received: from fli4-mobl1.ccr.corp.intel.com (HELO rzhang1-DESK.intel.com) ([10.255.28.30]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2023 00:08:14 -0700 From: Zhang Rui To: linux-pm@vger.kernel.org, rafael.j.wysocki@intel.com, daniel.lezcano@linaro.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 1/5] thermal/core: Update cooling device during thermal zone unregistration Date: Fri, 24 Mar 2023 15:08:03 +0800 Message-Id: <20230324070807.6342-1-rui.zhang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When unregistering a thermal zone device, update all cooling devices bound to the thermal zone device. This fixes a problem that the frequency of ACPI processors are still limited after unloading ACPI thermal driver while ACPI passive cooling is activated. Cc: stable@vger.kernel.org Signed-off-by: Zhang Rui --- v1 -> v2 Changelog update. Rearrange the code to elimiate an "iterator used outside loop" warning. --- drivers/thermal/thermal_core.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index cfd4c1afeae7..30ff39154598 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1497,9 +1497,24 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz) /* Unbind all cdevs associated with 'this' thermal zone */ list_for_each_entry(cdev, &thermal_cdev_list, node) { + struct thermal_instance *ti; + + mutex_lock(&tz->lock); + list_for_each_entry(ti, &tz->thermal_instances, tz_node) { + if (ti->cdev == cdev) { + mutex_unlock(&tz->lock); + goto unbind; + } + } + + /* The cooling device is not bound to current thermal zone */ + mutex_unlock(&tz->lock); + continue; + +unbind: if (tz->ops->unbind) { tz->ops->unbind(tz, cdev); - continue; + goto deactivate; } if (!tzp || !tzp->tbp) @@ -1511,6 +1526,16 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz) tzp->tbp[i].cdev = NULL; } } + +deactivate: + /* + * The thermal instances for current thermal zone has been + * removed. Update the cooling device in case it is activated + * by current thermal zone device. + */ + mutex_lock(&cdev->lock); + __thermal_cdev_update(cdev); + mutex_unlock(&cdev->lock); } mutex_unlock(&thermal_list_lock); -- 2.25.1