From patchwork Fri Mar 17 16:54:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 71367 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp463775wrt; Fri, 17 Mar 2023 10:21:20 -0700 (PDT) X-Google-Smtp-Source: AK7set8o7nvXAPOO3ICyRDzn6v/BKlHMqBtw1TcgiqvHNquxBLPLgQerpmkhDmwgSrz0d1Y24PmR X-Received: by 2002:a05:6a21:99a9:b0:cd:fc47:dd74 with SMTP id ve41-20020a056a2199a900b000cdfc47dd74mr9291159pzb.4.1679073680381; Fri, 17 Mar 2023 10:21:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679073680; cv=none; d=google.com; s=arc-20160816; b=xpoZo7aY/XbxDLH013MSe71ugAK32r9yLwEMVjt+bj5hC7hZrE2zzgMDSBSfx7FaTr 2eowefJmgRxBOnqyLPlhJ62mxIXAm1kihMVYTdyeEk317rAKOyj9pI6DqDeKL2+aJYJL wpaFZXhIOHjIypJ4cB9Cg+xF16oU0NUgmszKjF/2F0xqVIsjMno/4Wf/mMA1bJFKjlVU uNrrYjeRZQVZYQ318g1HjEPw2II8gdo2Up8O/AMFg3uvKHppXea3N1sO7qCyCGqcLJv8 ajFUeWd4zbd3+wF2DMWNgby3C5LC9sXT4g5lfgs1YcQ3epbNbcwDImTofhHqSML9Tpiq NKZQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=tT7Bu+vwy8Rv07p1PsiCIVtX8+qScX3qmiVZIJi21DQ=; b=fXm4yINKcLaEQFEdAS1+J27V38LSCk6IgyfHTEJdg+2HYt0+N3DljYabFAT56+5af9 Ev/BugRf2Yd0Vx7nmZbB6uR4fEKKd7qj7KHNJbfwGhpBgj+N8pDggZGXR3BWNbB5bCrx /AJC050bNgnuH6vmt/10eHisYYpOJpRXgCcTQNvEUCeQuCFbZaavjW1Z5+iDkr2xRWuV AuPmBLno7e9y1qfQJOa6aaz+ZYjcrHThhrDhE6Ns5oIu2pUkjLYn7dkNSoHmRJ/7peWl +YdymURVp5hL+XPEMWJz88649kEn0DQRsd8GBU5FBsZG65vjDqlWpnXpW62iRgj3Qla3 /urw== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x24-20020a63db58000000b005030009496asi2793349pgi.34.2023.03.17.10.21.05; Fri, 17 Mar 2023 10:21:20 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230088AbjCQREV (ORCPT + 99 others); Fri, 17 Mar 2023 13:04:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229842AbjCQREQ (ORCPT ); Fri, 17 Mar 2023 13:04:16 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05C6C1F484; Fri, 17 Mar 2023 10:04:14 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.1.0) id 91921d84dc82a107; Fri, 17 Mar 2023 18:04:13 +0100 Received: from kreacher.localnet (unknown [213.134.163.228]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 9F8EE1C52C22; Fri, 17 Mar 2023 18:04:12 +0100 (CET) From: "Rafael J. Wysocki" To: Linux PM Cc: Zhang Rui , Linux ACPI , LKML , Daniel Lezcano , Srinivas Pandruvada , Viresh Kumar , Quanxian Wang Subject: [PATCH v3 2/4] thermal: core: Introduce thermal_cooling_device_present() Date: Fri, 17 Mar 2023 17:54:34 +0100 Message-ID: <2280752.ElGaqSPkdT@kreacher> In-Reply-To: <2678096.mvXUDI8C0e@kreacher> References: <2678096.mvXUDI8C0e@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 213.134.163.228 X-CLIENT-HOSTNAME: 213.134.163.228 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrvdefvddgleehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppedvudefrddufeegrdduieefrddvvdeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvddufedrudefgedrudeifedrvddvkedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepkedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthht ohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrghdprhgtphhtthhopehsrhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760636363359007749?= X-GMAIL-MSGID: =?utf-8?q?1760636363359007749?= From: Rafael J. Wysocki Introduce a helper function, thermal_cooling_device_present(), for checking if the given cooling device is in the list of registered cooling devices to avoid some code duplication in a subsequent patch. No expected functional impact. Signed-off-by: Rafael J. Wysocki Tested-by: Zhang Rui Reviewed-by: Zhang Rui --- v2 -> v3: Add tags from Rui. v1 -> v2: No changes --- drivers/thermal/thermal_core.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -1045,6 +1045,18 @@ devm_thermal_of_cooling_device_register( } EXPORT_SYMBOL_GPL(devm_thermal_of_cooling_device_register); +static bool thermal_cooling_device_present(struct thermal_cooling_device *cdev) +{ + struct thermal_cooling_device *pos = NULL; + + list_for_each_entry(pos, &thermal_cdev_list, node) { + if (pos == cdev) + return true; + } + + return false; +} + static void __unbind(struct thermal_zone_device *tz, int mask, struct thermal_cooling_device *cdev) { @@ -1067,20 +1079,17 @@ void thermal_cooling_device_unregister(s int i; const struct thermal_zone_params *tzp; struct thermal_zone_device *tz; - struct thermal_cooling_device *pos = NULL; if (!cdev) return; mutex_lock(&thermal_list_lock); - list_for_each_entry(pos, &thermal_cdev_list, node) - if (pos == cdev) - break; - if (pos != cdev) { - /* thermal cooling device not found */ + + if (!thermal_cooling_device_present(cdev)) { mutex_unlock(&thermal_list_lock); return; } + list_del(&cdev->node); /* Unbind all thermal zones associated with 'this' cdev */