From patchwork Mon Mar 13 14:28:08 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: 68872 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1229033wrd; Mon, 13 Mar 2023 07:49:17 -0700 (PDT) X-Google-Smtp-Source: AK7set8Wa3Ipiry/JLUFVQa0v8eVfDnLD1Fk6J6VOMK3r93qWlygJn/LNvrQbdW3HsDSFdchbrmu X-Received: by 2002:a62:5585:0:b0:61d:8a6e:342d with SMTP id j127-20020a625585000000b0061d8a6e342dmr12746515pfb.26.1678718957549; Mon, 13 Mar 2023 07:49:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678718957; cv=none; d=google.com; s=arc-20160816; b=0Gg9pYz99Ji91hLVNWVt8/WCa42DRALoI2hNT7aZcFUnDU9T5RAwGE5gUzd0PK5Mqt TfbSHdVYxAoadAOmQyuMYfVv9GXsX21iqd9hW/ijsmYVwHb9QsYKPJNyotlsNwFO47Jr 3ZBcqmqIKZDp5zZp9N0sHrn+yWL6thn7mK5gson4Z4TGxDMN8xTnmwoit2tCBbPWTNU4 S3BWI3GPB5BKMeP2WkwKKHpemVUCYeMW0aDOCKkZwkgMY5WFl/Nd6MSbe6Alt2y0xdWE sdEArFXYKN4FVCNK6joTH0UFXThjBaFPXQcmOr7EgUM0itgW+9agOsI6imlk3+vSWkjh IDGA== 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=Tr17jcrOZ0jyUd1nLao+xjR9pnS6EIJ9FtxzOxdBEow=; b=o7zeUpcl+YsUYZim0VBKBSPHuiMAggJy4CteyOpwLY0P/dGuNR6L00928uCkDctiRG MsSptIBOdwJpH73nbsqXOD+kdCgWm6Udqz1WilxCf5BphBfMPxicqMbvn/xolhsVQqVX 08s+//hSGE0D7sKqOUzUIJN6nvXHXgWOx6VSyB4GXKM4Kntc2D/8a5DgyNq4LyBhAnSR Vg8HSzFuLYj/95yCxJLrzUzEmugPVFrk/QGGU/72ehbIFeJ81fuPB1cDRfL/10it/DzI m4M5e5n1gNGh7FNl+IfgsTBlcQYpCUlrgiRqsR3d45+xE5/Y2hngLD1KIMt9YLUk9z9X TJSA== 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 k190-20020a6384c7000000b0050ac80fc7b1si2792919pgd.658.2023.03.13.07.49.02; Mon, 13 Mar 2023 07:49:17 -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 S231484AbjCMOfB (ORCPT + 99 others); Mon, 13 Mar 2023 10:35:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231441AbjCMOej (ORCPT ); Mon, 13 Mar 2023 10:34:39 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6959B234D6; Mon, 13 Mar 2023 07:34:38 -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 59da252f0a8029b0; Mon, 13 Mar 2023 15:34:36 +0100 Received: from kreacher.localnet (unknown [213.134.189.11]) (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 082459C5854; Mon, 13 Mar 2023 15:34:35 +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 v2 2/4] thermal: core: Introduce thermal_cooling_device_present() Date: Mon, 13 Mar 2023 15:28:08 +0100 Message-ID: <4488488.LvFx2qVVIh@kreacher> In-Reply-To: <2692681.mvXUDI8C0e@kreacher> References: <2692681.mvXUDI8C0e@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 213.134.189.11 X-CLIENT-HOSTNAME: 213.134.189.11 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrvddvgedgieegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppedvudefrddufeegrddukeelrdduudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvudefrddufeegrddukeelrdduuddphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepkedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohep uggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrghdprhgtphhtthhopehsrhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhm 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?1760264409115172667?= X-GMAIL-MSGID: =?utf-8?q?1760264409115172667?= 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 --- 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 */