From patchwork Thu Oct 10 22:10:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 834418 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA0F3148301; Thu, 10 Oct 2024 22:22:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728598958; cv=none; b=RiiZ/qSou7mxxKww36s+jAxI83u9K3Pn7ZeLTJ0DXHxQIIPsrO8InCYnH1S8QPqjGvEmSHEpX0HfuRr0XWg7xYkJ2KAFESq9cnF3xiWl7HoovRdP1prz1252WDZEGWIVwwnypoQ2pkFeHvYz6nAlgY60yfIwQL8SzB/alG9N9mc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728598958; c=relaxed/simple; bh=FDHAI1QDQ4nSnmYAkIDb0LzljEngBGRbZw6cSI3zLtM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bQx87HkUnt+LB0Iw9YJfT5ZuEHNtLSe5YcawhiwvdDm/ifjXeJdvHB9EvDokNHm1NRIUL+r4B9jst47KLJX1VSuGjTcOotqxw9ESCug4N8yT7kOIF3tQxZIUu+50AXcJx4s6tpsik00Eby3uV4oG+D5CqxRKt01+j+f6vqyAcyY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=ZjwM/uD9 reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="ZjwM/uD9" 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 6.2.0) id f7b1f3f4d3445cd4; Fri, 11 Oct 2024 00:22:28 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (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 cloudserver094114.home.pl (Postfix) with ESMTPSA id 0D18169EF02; Fri, 11 Oct 2024 00:22:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1728598948; bh=FDHAI1QDQ4nSnmYAkIDb0LzljEngBGRbZw6cSI3zLtM=; h=From:Subject:Date; b=ZjwM/uD9cUTzbSs5L+yYW0DB2/ZFGC5BgcPDyPvqUQejU5rD9NHw3f5NEt29IcnYX 5Ew7SSOS6WGmXqcsUsOW7LgdRNzVoz+16YtgtGz52Rnog8fiKvIEDNgp4U8NXcrmdd rU1YoO+NMyQuwGQqL4+mQU9YfonEJXFPog9mWBxzrFlhTOXjJHcWWZaP2wD7QdLRNx xI/kpufpgYQyx0Ac328SstpBN9XWu3x8A7M+4DhzGadhVPgHCwkzzHJEEjJlVVKsuP Ww8d9R9Iyqi8ClI4Zxi2coPCzAKh9On/wf+1tCRJlT3ej1yLOaAFDhgG/1qF6u/Ppb HKFcNjAVPIygw== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Lukasz Luba , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v2 04/11] thermal: core: Manage thermal_list_lock using a mutex guard Date: Fri, 11 Oct 2024 00:10:47 +0200 Message-ID: <2010397.PYKUYFuaPT@rjwysocki.net> In-Reply-To: <4985597.31r3eYUQgx@rjwysocki.net> References: <4985597.31r3eYUQgx@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeeftddrvdefjedguddtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepfeduudeutdeugfelffduieegiedtueefledvjeegffdttefhhffhtefhleejgfetnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpehrjhifsehrjhifhihsohgtkhhirdhnvghtpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtoheprhhuihdriih X-DCC--Metrics: v370.home.net.pl 0; Body=6 Fuz1=6 Fuz2=6 From: Rafael J. Wysocki Switch over the thermal core to using a mutex guard for thermal_list_lock management. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- This is a resend of https://lore.kernel.org/linux-pm/2018087.usQuhbGJ8B@rjwysocki.net/ --- drivers/thermal/thermal_core.c | 148 ++++++++++++++++++----------------------- 1 file changed, 68 insertions(+), 80 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -140,7 +140,7 @@ int thermal_register_governor(struct the def_governor = governor; } - mutex_lock(&thermal_list_lock); + guard(mutex)(&thermal_list_lock); list_for_each_entry(pos, &thermal_tz_list, node) { /* @@ -163,7 +163,6 @@ int thermal_register_governor(struct the } } - mutex_unlock(&thermal_list_lock); mutex_unlock(&thermal_governor_lock); return err; @@ -181,7 +180,9 @@ void thermal_unregister_governor(struct if (!__find_governor(governor->name)) goto exit; - mutex_lock(&thermal_list_lock); + list_del(&governor->governor_list); + + guard(mutex)(&thermal_list_lock); list_for_each_entry(pos, &thermal_tz_list, node) { if (!strncasecmp(pos->governor->name, governor->name, @@ -189,8 +190,6 @@ void thermal_unregister_governor(struct thermal_set_governor(pos, NULL); } - mutex_unlock(&thermal_list_lock); - list_del(&governor->governor_list); exit: mutex_unlock(&thermal_governor_lock); } @@ -686,51 +685,52 @@ int for_each_thermal_cooling_device(int void *), void *data) { struct thermal_cooling_device *cdev; - int ret = 0; - mutex_lock(&thermal_list_lock); + guard(mutex)(&thermal_list_lock); + list_for_each_entry(cdev, &thermal_cdev_list, node) { + int ret; + ret = cb(cdev, data); if (ret) - break; + return ret; } - mutex_unlock(&thermal_list_lock); - return ret; + return 0; } int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *), void *data) { struct thermal_zone_device *tz; - int ret = 0; - mutex_lock(&thermal_list_lock); + guard(mutex)(&thermal_list_lock); + list_for_each_entry(tz, &thermal_tz_list, node) { + int ret; + ret = cb(tz, data); if (ret) - break; + return ret; } - mutex_unlock(&thermal_list_lock); - return ret; + return 0; } struct thermal_zone_device *thermal_zone_get_by_id(int id) { - struct thermal_zone_device *tz, *match = NULL; + struct thermal_zone_device *tz; + + guard(mutex)(&thermal_list_lock); - mutex_lock(&thermal_list_lock); list_for_each_entry(tz, &thermal_tz_list, node) { if (tz->id == id) { get_device(&tz->device); - match = tz; - break; + return tz; } } - mutex_unlock(&thermal_list_lock); - return match; + return NULL; } /* @@ -969,14 +969,12 @@ static void thermal_cooling_device_init_ { struct thermal_zone_device *tz; - mutex_lock(&thermal_list_lock); + guard(mutex)(&thermal_list_lock); list_add(&cdev->node, &thermal_cdev_list); list_for_each_entry(tz, &thermal_tz_list, node) thermal_zone_cdev_bind(tz, cdev); - - mutex_unlock(&thermal_list_lock); } /** @@ -1210,10 +1208,10 @@ void thermal_cooling_device_update(struc * Hold thermal_list_lock throughout the update to prevent the device * from going away while being updated. */ - mutex_lock(&thermal_list_lock); + guard(mutex)(&thermal_list_lock); if (!thermal_cooling_device_present(cdev)) - goto unlock_list; + return; /* * Update under the cdev lock to prevent the state from being set beyond @@ -1255,9 +1253,6 @@ void thermal_cooling_device_update(struc unlock: mutex_unlock(&cdev->lock); - -unlock_list: - mutex_unlock(&thermal_list_lock); } EXPORT_SYMBOL_GPL(thermal_cooling_device_update); @@ -1281,24 +1276,18 @@ static void thermal_zone_cdev_unbind(str static bool thermal_cooling_device_exit(struct thermal_cooling_device *cdev) { struct thermal_zone_device *tz; - bool ret = true; - mutex_lock(&thermal_list_lock); + guard(mutex)(&thermal_list_lock); - if (!thermal_cooling_device_present(cdev)) { - ret = false; - goto unlock; - } + if (!thermal_cooling_device_present(cdev)) + return false; list_del(&cdev->node); list_for_each_entry(tz, &thermal_tz_list, node) thermal_zone_cdev_unbind(tz, cdev); -unlock: - mutex_unlock(&thermal_list_lock); - - return ret; + return true; } /** @@ -1345,7 +1334,7 @@ static void thermal_zone_init_complete(s { struct thermal_cooling_device *cdev; - mutex_lock(&thermal_list_lock); + guard(mutex)(&thermal_list_lock); list_add_tail(&tz->node, &thermal_tz_list); @@ -1365,8 +1354,6 @@ static void thermal_zone_init_complete(s tz->state |= TZ_STATE_FLAG_SUSPENDED; __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); - - mutex_unlock(&thermal_list_lock); } /** @@ -1587,14 +1574,11 @@ EXPORT_SYMBOL_GPL(thermal_zone_device); static bool thermal_zone_exit(struct thermal_zone_device *tz) { struct thermal_cooling_device *cdev; - bool ret = true; - mutex_lock(&thermal_list_lock); + guard(mutex)(&thermal_list_lock); - if (list_empty(&tz->node)) { - ret = false; - goto unlock; - } + if (list_empty(&tz->node)) + return false; guard(thermal_zone)(tz); @@ -1605,10 +1589,7 @@ static bool thermal_zone_exit(struct the list_for_each_entry(cdev, &thermal_cdev_list, node) __thermal_zone_cdev_unbind(tz, cdev); -unlock: - mutex_unlock(&thermal_list_lock); - - return ret; + return true; } /** @@ -1660,24 +1641,23 @@ struct thermal_zone_device *thermal_zone unsigned int found = 0; if (!name) - goto exit; + return ERR_PTR(-EINVAL); + + guard(mutex)(&thermal_list_lock); - mutex_lock(&thermal_list_lock); list_for_each_entry(pos, &thermal_tz_list, node) if (!strncasecmp(name, pos->type, THERMAL_NAME_LENGTH)) { found++; ref = pos; } - mutex_unlock(&thermal_list_lock); - /* nothing has been found, thus an error code for it */ - if (found == 0) - ref = ERR_PTR(-ENODEV); - else if (found > 1) - /* Success only when an unique zone is found */ - ref = ERR_PTR(-EEXIST); + if (!found) + return ERR_PTR(-ENODEV); + + /* Success only when one zone is found. */ + if (found > 1) + return ERR_PTR(-EEXIST); -exit: return ref; } EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name); @@ -1718,6 +1698,18 @@ static void thermal_zone_pm_prepare(stru tz->state |= TZ_STATE_FLAG_SUSPENDED; } +static void thermal_pm_notify_prepare(void) +{ + struct thermal_zone_device *tz; + + guard(mutex)(&thermal_list_lock); + + thermal_pm_suspended = true; + + list_for_each_entry(tz, &thermal_tz_list, node) + thermal_zone_pm_prepare(tz); +} + static void thermal_zone_pm_complete(struct thermal_zone_device *tz) { guard(thermal_zone)(tz); @@ -1736,35 +1728,31 @@ static void thermal_zone_pm_complete(str mod_delayed_work(system_freezable_power_efficient_wq, &tz->poll_queue, 0); } -static int thermal_pm_notify(struct notifier_block *nb, - unsigned long mode, void *_unused) +static void thermal_pm_notify_complete(void) { struct thermal_zone_device *tz; + guard(mutex)(&thermal_list_lock); + + thermal_pm_suspended = false; + + list_for_each_entry(tz, &thermal_tz_list, node) + thermal_zone_pm_complete(tz); +} + +static int thermal_pm_notify(struct notifier_block *nb, + unsigned long mode, void *_unused) +{ switch (mode) { case PM_HIBERNATION_PREPARE: case PM_RESTORE_PREPARE: case PM_SUSPEND_PREPARE: - mutex_lock(&thermal_list_lock); - - thermal_pm_suspended = true; - - list_for_each_entry(tz, &thermal_tz_list, node) - thermal_zone_pm_prepare(tz); - - mutex_unlock(&thermal_list_lock); + thermal_pm_notify_prepare(); break; case PM_POST_HIBERNATION: case PM_POST_RESTORE: case PM_POST_SUSPEND: - mutex_lock(&thermal_list_lock); - - thermal_pm_suspended = false; - - list_for_each_entry(tz, &thermal_tz_list, node) - thermal_zone_pm_complete(tz); - - mutex_unlock(&thermal_list_lock); + thermal_pm_notify_complete(); break; default: break; From patchwork Thu Oct 10 22:15:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 834416 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D3E01E2029; Thu, 10 Oct 2024 22:22:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728598959; cv=none; b=BZegMlteA1X9MCJjQkEWT+ZE9C83dOAA3eDAGCMnavb/sbWbe71aT8YH3T6+Vx6JAVXWkuiCs99qnaGtTeTfIxQCk8iyRB+1YxiL1FN38NGWo5ffob61nEQn7koiU6drBOelP7xb+QXCKlMGYGtQNAcAeOXqunIjQs8xPQ1bJ8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728598959; c=relaxed/simple; bh=xjilEsLX+G8kf8JRPFeXyzM3RwuC/YiY5ih1BDEWdZ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IlB2V7NPCPma6ZlME0vDvUkDkbHKwd0u4RUQ5OzBDZMvsFuSNE/Bkh7TSEtSYsJAIri1nRYGi6bHRWta0i7reilAXdK3g+FLyLnQDNpXvuoZmWHzIKgiy8KyOlrVNzo0AVMyAnH+8aJznP5VuiBoXkp3myeiDwlzwxU/ECfDoo0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=p6vxYdUn; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="p6vxYdUn" 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 6.2.0) id c8883fc4938e307c; Fri, 11 Oct 2024 00:22:27 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (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 cloudserver094114.home.pl (Postfix) with ESMTPSA id DED5C69EF02; Fri, 11 Oct 2024 00:22:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1728598947; bh=xjilEsLX+G8kf8JRPFeXyzM3RwuC/YiY5ih1BDEWdZ0=; h=From:Subject:Date; b=p6vxYdUnrVEzbz4V31Kv3NQtX+8J6yRyETKOqnwQho8ukgmFBm6vKaVPJRs2OrEde 99eEJHq1+7CTE6Cm+pf1R2dWMUbTbKFKmtZVkmqJj+PI1kqpNiPr+Gzh6FT3aRMF6N YyYmQ4NaEb2zHnGQfSPNI3mJsHHQnoho0vKBTQnDjuMUyNbQzbEEoYQpi1WymRvcP8 fECHN3ucBI0hDUxu4EZsOTfx3nrAzhjktPCVxHuTSjPR8P92xisROM0PSNozWRdPNv zAYfcTVp1cij6XGtwlXLWofBLdElCAEpFOaKopPB62H3CPC1pW1wlk5zzrwc2q2O0n UGOmJUgUo7w9Q== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Lukasz Luba , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v2 07/11] thermal: core: Introduce thermal_instance_delete() Date: Fri, 11 Oct 2024 00:15:22 +0200 Message-ID: <3275745.5fSG56mABF@rjwysocki.net> In-Reply-To: <4985597.31r3eYUQgx@rjwysocki.net> References: <4985597.31r3eYUQgx@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeeftddrvdefjedguddtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepfeduudeutdeugfelffduieegiedtueefledvjeegffdttefhhffhtefhleejgfetnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpehrjhifsehrjhifhihsohgtkhhirdhnvghtpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtoheprhhuihdriih X-DCC--Metrics: v370.home.net.pl 0; Body=6 Fuz1=6 Fuz2=6 From: Rafael J. Wysocki It is not necessary to walk the thermal_instances list in a trip descriptor under a cooling device lock, so acquire that lock only for deleting the given thermal instance from the list of thermal instances in the given cdev. Moreover, in analogy with the previous change that introduced thermal_instance_add(), put the code deleting the given thermal instance from the lists it is on into a separate new function called thermal_instance_delete(). No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- This is a resend of https://lore.kernel.org/linux-pm/2224279.Mh6RI2rZIc@rjwysocki.net/ --- drivers/thermal/thermal_core.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -866,6 +866,17 @@ free_mem: return result; } +static void thermal_instance_delete(struct thermal_instance *instance) +{ + list_del(&instance->trip_node); + + mutex_lock(&instance->cdev->lock); + + list_del(&instance->cdev_node); + + mutex_unlock(&instance->cdev->lock); +} + /** * thermal_unbind_cdev_from_trip - unbind a cooling device from a thermal zone. * @tz: pointer to a struct thermal_zone_device. @@ -882,16 +893,12 @@ static void thermal_unbind_cdev_from_tri { struct thermal_instance *pos, *next; - mutex_lock(&cdev->lock); list_for_each_entry_safe(pos, next, &td->thermal_instances, trip_node) { if (pos->cdev == cdev) { - list_del(&pos->trip_node); - list_del(&pos->cdev_node); - mutex_unlock(&cdev->lock); + thermal_instance_delete(pos); goto unbind; } } - mutex_unlock(&cdev->lock); return; From patchwork Thu Oct 10 22:16:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 834419 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EA1B1E2315; Thu, 10 Oct 2024 22:22:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728598958; cv=none; b=ZdQb4my/rLhT+mgHqj5zEEafklPx2nC8cFpZOXlIxZnnyYlq1adehkHwrzKZjb5kPxaiRmVZU34TeKG6C35XFhRqa9nGdl8QNjChuWWsVPaoxufwmIY4ozoqCEF6ohQHC7LG6bGbItHVeMTatld61foS6kpsk+Fc9AYG8m6/oaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728598958; c=relaxed/simple; bh=6wJf8qwNZabXARs2oRAqCqXVBZZc0JIY1+aXfocLsq0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rZ1AmHjnE49Jo7vfuGhNzqCjUseBLLFZzC3dSns0YOe1ZEPGkpgKhhuSIg0Ap01LdZQuB4LZGOM82hD6omWbVj5HFVZO4QvtJzFE5QNwL1JJB8JRswkkjIWUDfQq5kT7DFZuX6hah1PQ0DwZUMwvBC7Y62Lwait6ak88cplZM70= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=IrJH9oWK reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="IrJH9oWK" 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 6.2.0) id 173ccb3c50bd765f; Fri, 11 Oct 2024 00:22:26 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (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 cloudserver094114.home.pl (Postfix) with ESMTPSA id 890B969EF02; Fri, 11 Oct 2024 00:22:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1728598946; bh=6wJf8qwNZabXARs2oRAqCqXVBZZc0JIY1+aXfocLsq0=; h=From:Subject:Date; b=IrJH9oWKwBNavtG94OtlC6mg+d8ZQk/aLlO3DyrNo91K/E40LmHQyhr0j8GUwAPby TTTo8AylsRTKlGi30SGHFAEUKnpDuXXYe9zLppGzoCmosc9iqQvy4Pg66D/k6tCobV aetgIKnVCj295XukDg3+C4ab/LThyu1sZIHCdN5XqzML3B7ECwXUnBIHk/u0PpfitJ ytNn8wcu6CUgQFkHxd5cNYI+IOW0e1YXzRTQrc6poDgOQ2bAIldlXfZbRK6Of1ngBJ bXLIt4n9Ciglp1mhtsF0JWMOMEQz+UaCePGkcevAo6SmMbtkFFRcbZoT6yeVhZP6Lj zMGxywOoRAotA== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Lukasz Luba , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v2 08/11] thermal: core: Introduce thermal_cdev_update_nocheck() Date: Fri, 11 Oct 2024 00:16:54 +0200 Message-ID: <1835097.VLH7GnMWUR@rjwysocki.net> In-Reply-To: <4985597.31r3eYUQgx@rjwysocki.net> References: <4985597.31r3eYUQgx@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeeftddrvdefjedguddtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepfeduudeutdeugfelffduieegiedtueefledvjeegffdttefhhffhtefhleejgfetnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpehrjhifsehrjhifhihsohgtkhhirdhnvghtpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtoheprhhuihdriih X-DCC--Metrics: v370.home.net.pl 0; Body=6 Fuz1=6 Fuz2=6 From: Rafael J. Wysocki Three thermal governors call __thermal_cdev_update() under the cdev lock without doing any checks, so in order to reduce the related code duplication, introduce a new helper function called thermal_cdev_update_nocheck() for them and make them use it. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- This is a resend of https://lore.kernel.org/linux-pm/3791590.MHq7AAxBmi@rjwysocki.net/ --- drivers/thermal/gov_bang_bang.c | 4 +--- drivers/thermal/gov_fair_share.c | 4 +--- drivers/thermal/gov_power_allocator.c | 5 ++--- drivers/thermal/thermal_core.h | 1 + drivers/thermal/thermal_helpers.c | 13 +++++++++++++ 5 files changed, 18 insertions(+), 9 deletions(-) Index: linux-pm/drivers/thermal/gov_bang_bang.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_bang_bang.c +++ linux-pm/drivers/thermal/gov_bang_bang.c @@ -30,9 +30,7 @@ static void bang_bang_set_instance_targe dev_dbg(&instance->cdev->device, "target=%ld\n", instance->target); - mutex_lock(&instance->cdev->lock); - __thermal_cdev_update(instance->cdev); - mutex_unlock(&instance->cdev->lock); + thermal_cdev_update_nocheck(instance->cdev); } /** Index: linux-pm/drivers/thermal/gov_fair_share.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_fair_share.c +++ linux-pm/drivers/thermal/gov_fair_share.c @@ -89,9 +89,7 @@ static void fair_share_throttle(struct t } instance->target = div_u64(dividend, divisor); - mutex_lock(&cdev->lock); - __thermal_cdev_update(cdev); - mutex_unlock(&cdev->lock); + thermal_cdev_update_nocheck(cdev); } } Index: linux-pm/drivers/thermal/gov_power_allocator.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_power_allocator.c +++ linux-pm/drivers/thermal/gov_power_allocator.c @@ -322,9 +322,8 @@ power_actor_set_power(struct thermal_coo return ret; instance->target = clamp_val(state, instance->lower, instance->upper); - mutex_lock(&cdev->lock); - __thermal_cdev_update(cdev); - mutex_unlock(&cdev->lock); + + thermal_cdev_update_nocheck(cdev); return 0; } Index: linux-pm/drivers/thermal/thermal_core.h =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.h +++ linux-pm/drivers/thermal/thermal_core.h @@ -213,6 +213,7 @@ static inline bool cdev_is_power_actor(s } void thermal_cdev_update(struct thermal_cooling_device *); +void thermal_cdev_update_nocheck(struct thermal_cooling_device *cdev); void __thermal_cdev_update(struct thermal_cooling_device *cdev); int get_tz_trend(struct thermal_zone_device *tz, const struct thermal_trip *trip); Index: linux-pm/drivers/thermal/thermal_helpers.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_helpers.c +++ linux-pm/drivers/thermal/thermal_helpers.c @@ -206,6 +206,19 @@ void thermal_cdev_update(struct thermal_ } /** + * thermal_cdev_update_nocheck() - Unconditionally update cooling device state + * @cdev: Target cooling device. + */ +void thermal_cdev_update_nocheck(struct thermal_cooling_device *cdev) +{ + mutex_lock(&cdev->lock); + + __thermal_cdev_update(cdev); + + mutex_unlock(&cdev->lock); +} + +/** * thermal_zone_get_slope - return the slope attribute of the thermal zone * @tz: thermal zone device with the slope attribute * From patchwork Thu Oct 10 22:19:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 834417 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 444121BE86E; Thu, 10 Oct 2024 22:22:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728598958; cv=none; b=m4Ou8O0NVi3/wQIKF25c/qAKYhrFt3tjhTHrfA+UKrzVFmXVZcUdjWOok/S9JznnZurwt0ns/GU0Z5AJX8BkfzSYtOqF59Bh7a4nkCmas/t6i1JvSlzfMu9m0GBGeXvtKQYxz8qZw8YYKva4JqRLTO207IKCSp/6uhl8S+7t3rU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728598958; c=relaxed/simple; bh=K8t6Bm2WP6f7rh1OGJJVEntmtChTr0dRhB48296CVow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aynfupF1w3s6CmZjKj+c6lZW9arBByLlPM9XA3ChbvErxh+QVQEKPQT9w53dGL+p91jQ9m8JHzyxb/6nOZm1ezQuv94OEn8D2jt0+BmBqt9uBLVYnzN4dHce6LEDi8hJhTo5Ee0jKUcgnZwAUopiNj4hGaWG1zA6Z5oYoPm8egI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=wREcPflE; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="wREcPflE" 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 6.2.0) id 25a7ccfc7e08f20b; Fri, 11 Oct 2024 00:22:26 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (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 cloudserver094114.home.pl (Postfix) with ESMTPSA id 1198A69EF02; Fri, 11 Oct 2024 00:22:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1728598946; bh=K8t6Bm2WP6f7rh1OGJJVEntmtChTr0dRhB48296CVow=; h=From:Subject:Date; b=wREcPflEAk4dL0KvWUBuGPllWQct9xTgFNwqt0P15dHJ98kq8RepVYQfuKQYGrqRh QhlKP3asdyFuR5FitiSfK1OgiuPGIhi80VLdoKNRgm3N3Nhha3NIBRN4zGzoqjPgU1 oZ9KpDe8MwRcCeMaUlYVQE/ta7tap6LKd7ujbdeexgCsu3djYGqRQAo7lqj5/DvAMl pPp2KWHKTZj4wuVfYpvCB02ZZw+1pM0RpcbUdSb3CKu5xWWDBn8rlAI93IEjaRqMNi 4PDbuDS7mT3QtUufozFzdWYH3RSv6PGhdvQaliHaLvz8HB0OOLGVcNVu5NPDSSyeI+ sj32j15iW2lMA== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Lukasz Luba , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v2 09/11] thermal: core: Add and use cooling device guard Date: Fri, 11 Oct 2024 00:19:53 +0200 Message-ID: <2655659.Lt9SDvczpP@rjwysocki.net> In-Reply-To: <4985597.31r3eYUQgx@rjwysocki.net> References: <4985597.31r3eYUQgx@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeeftddrvdefjedguddtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepfeduudeutdeugfelffduieegiedtueefledvjeegffdttefhhffhtefhleejgfetnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpehrjhifsehrjhifhihsohgtkhhirdhnvghtpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtoheprhhuihdriih X-DCC--Metrics: v370.home.net.pl 0; Body=6 Fuz1=6 Fuz2=6 From: Rafael J. Wysocki Add and use a special guard for cooling devices. This allows quite a few error code paths to be simplified among other things and brings in code size reduction for a good measure. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- This is a new iteration of https://lore.kernel.org/linux-pm/1890654.atdPhlSkOF@rjwysocki.net/ v1 -> v2: Rearrange cur_state_store() --- drivers/thermal/gov_power_allocator.c | 21 +++++++-------- drivers/thermal/gov_step_wise.c | 6 ++-- drivers/thermal/thermal_core.c | 17 +++--------- drivers/thermal/thermal_debugfs.c | 25 +++++++++++------- drivers/thermal/thermal_helpers.c | 19 +++----------- drivers/thermal/thermal_sysfs.c | 45 ++++++++++++---------------------- include/linux/thermal.h | 3 ++ 7 files changed, 57 insertions(+), 79 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -756,12 +756,10 @@ static int thermal_instance_add(struct t list_add_tail(&new_instance->trip_node, &td->thermal_instances); - mutex_lock(&cdev->lock); + guard(cooling_dev)(cdev); list_add_tail(&new_instance->cdev_node, &cdev->thermal_instances); - mutex_unlock(&cdev->lock); - return 0; } @@ -870,11 +868,9 @@ static void thermal_instance_delete(stru { list_del(&instance->trip_node); - mutex_lock(&instance->cdev->lock); + guard(cooling_dev)(instance->cdev); list_del(&instance->cdev_node); - - mutex_unlock(&instance->cdev->lock); } /** @@ -1237,10 +1233,10 @@ void thermal_cooling_device_update(struc * Update under the cdev lock to prevent the state from being set beyond * the new limit concurrently. */ - mutex_lock(&cdev->lock); + guard(cooling_dev)(cdev); if (cdev->ops->get_max_state(cdev, &cdev->max_state)) - goto unlock; + return; thermal_cooling_device_stats_reinit(cdev); @@ -1267,12 +1263,9 @@ void thermal_cooling_device_update(struc } if (cdev->ops->get_cur_state(cdev, &state) || state > cdev->max_state) - goto unlock; + return; thermal_cooling_device_stats_update(cdev, state); - -unlock: - mutex_unlock(&cdev->lock); } EXPORT_SYMBOL_GPL(thermal_cooling_device_update); Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -137,6 +137,9 @@ struct thermal_cooling_device { #endif }; +DEFINE_GUARD(cooling_dev, struct thermal_cooling_device *, mutex_lock(&_T->lock), + mutex_unlock(&_T->lock)) + /* Structure to define Thermal Zone parameters */ struct thermal_zone_params { const char *governor_name; Index: linux-pm/drivers/thermal/thermal_sysfs.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_sysfs.c +++ linux-pm/drivers/thermal/thermal_sysfs.c @@ -544,14 +544,15 @@ cur_state_store(struct device *dev, stru if (state > cdev->max_state) return -EINVAL; - mutex_lock(&cdev->lock); + guard(cooling_dev)(cdev); result = cdev->ops->set_cur_state(cdev, state); - if (!result) - thermal_cooling_device_stats_update(cdev, state); + if (result) + return result; - mutex_unlock(&cdev->lock); - return result ? result : count; + thermal_cooling_device_stats_update(cdev, state); + + return count; } static struct device_attribute @@ -625,21 +626,18 @@ static ssize_t total_trans_show(struct d { struct thermal_cooling_device *cdev = to_cooling_device(dev); struct cooling_dev_stats *stats; - int ret = 0; + int ret; - mutex_lock(&cdev->lock); + guard(cooling_dev)(cdev); stats = cdev->stats; if (!stats) - goto unlock; + return 0; spin_lock(&stats->lock); ret = sprintf(buf, "%u\n", stats->total_trans); spin_unlock(&stats->lock); -unlock: - mutex_unlock(&cdev->lock); - return ret; } @@ -652,11 +650,11 @@ time_in_state_ms_show(struct device *dev ssize_t len = 0; int i; - mutex_lock(&cdev->lock); + guard(cooling_dev)(cdev); stats = cdev->stats; if (!stats) - goto unlock; + return 0; spin_lock(&stats->lock); @@ -668,9 +666,6 @@ time_in_state_ms_show(struct device *dev } spin_unlock(&stats->lock); -unlock: - mutex_unlock(&cdev->lock); - return len; } @@ -682,11 +677,11 @@ reset_store(struct device *dev, struct d struct cooling_dev_stats *stats; int i, states; - mutex_lock(&cdev->lock); + guard(cooling_dev)(cdev); stats = cdev->stats; if (!stats) - goto unlock; + return count; states = cdev->max_state + 1; @@ -702,9 +697,6 @@ reset_store(struct device *dev, struct d spin_unlock(&stats->lock); -unlock: - mutex_unlock(&cdev->lock); - return count; } @@ -716,13 +708,11 @@ static ssize_t trans_table_show(struct d ssize_t len = 0; int i, j; - mutex_lock(&cdev->lock); + guard(cooling_dev)(cdev); stats = cdev->stats; - if (!stats) { - len = -ENODATA; - goto unlock; - } + if (!stats) + return -ENODATA; len += snprintf(buf + len, PAGE_SIZE - len, " From : To\n"); len += snprintf(buf + len, PAGE_SIZE - len, " : "); @@ -760,9 +750,6 @@ static ssize_t trans_table_show(struct d len = -EFBIG; } -unlock: - mutex_unlock(&cdev->lock); - return len; } Index: linux-pm/drivers/thermal/thermal_helpers.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_helpers.c +++ linux-pm/drivers/thermal/thermal_helpers.c @@ -58,17 +58,10 @@ bool thermal_trip_is_bound_to_cdev(struc const struct thermal_trip *trip, struct thermal_cooling_device *cdev) { - bool ret; - guard(thermal_zone)(tz); + guard(cooling_dev)(cdev); - mutex_lock(&cdev->lock); - - ret = thermal_instance_present(tz, cdev, trip); - - mutex_unlock(&cdev->lock); - - return ret; + return thermal_instance_present(tz, cdev, trip); } EXPORT_SYMBOL_GPL(thermal_trip_is_bound_to_cdev); @@ -197,12 +190,12 @@ void __thermal_cdev_update(struct therma */ void thermal_cdev_update(struct thermal_cooling_device *cdev) { - mutex_lock(&cdev->lock); + guard(cooling_dev)(cdev); + if (!cdev->updated) { __thermal_cdev_update(cdev); cdev->updated = true; } - mutex_unlock(&cdev->lock); } /** @@ -211,11 +204,9 @@ void thermal_cdev_update(struct thermal_ */ void thermal_cdev_update_nocheck(struct thermal_cooling_device *cdev) { - mutex_lock(&cdev->lock); + guard(cooling_dev)(cdev); __thermal_cdev_update(cdev); - - mutex_unlock(&cdev->lock); } /** Index: linux-pm/drivers/thermal/thermal_debugfs.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_debugfs.c +++ linux-pm/drivers/thermal/thermal_debugfs.c @@ -516,6 +516,19 @@ void thermal_debug_cdev_add(struct therm cdev->debugfs = thermal_dbg; } +static struct thermal_debugfs *thermal_debug_cdev_clear(struct thermal_cooling_device *cdev) +{ + struct thermal_debugfs *thermal_dbg; + + guard(cooling_dev)(cdev); + + thermal_dbg = cdev->debugfs; + if (thermal_dbg) + cdev->debugfs = NULL; + + return thermal_dbg; +} + /** * thermal_debug_cdev_remove - Remove a cooling device debugfs entry * @@ -527,17 +540,9 @@ void thermal_debug_cdev_remove(struct th { struct thermal_debugfs *thermal_dbg; - mutex_lock(&cdev->lock); - - thermal_dbg = cdev->debugfs; - if (!thermal_dbg) { - mutex_unlock(&cdev->lock); + thermal_dbg = thermal_debug_cdev_clear(cdev); + if (!thermal_dbg) return; - } - - cdev->debugfs = NULL; - - mutex_unlock(&cdev->lock); mutex_lock(&thermal_dbg->lock); Index: linux-pm/drivers/thermal/gov_power_allocator.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_power_allocator.c +++ linux-pm/drivers/thermal/gov_power_allocator.c @@ -549,18 +549,17 @@ static void allow_maximum_power(struct t cdev = instance->cdev; instance->target = 0; - mutex_lock(&cdev->lock); - /* - * Call for updating the cooling devices local stats and avoid - * periods of dozen of seconds when those have not been - * maintained. - */ - cdev->ops->get_requested_power(cdev, &req_power); + scoped_guard(cooling_dev, cdev) { + /* + * Call for updating the cooling devices local stats and + * avoid periods of dozen of seconds when those have not + * been maintained. + */ + cdev->ops->get_requested_power(cdev, &req_power); - if (params->update_cdevs) - __thermal_cdev_update(cdev); - - mutex_unlock(&cdev->lock); + if (params->update_cdevs) + __thermal_cdev_update(cdev); + } } } Index: linux-pm/drivers/thermal/gov_step_wise.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_step_wise.c +++ linux-pm/drivers/thermal/gov_step_wise.c @@ -97,9 +97,9 @@ static void thermal_zone_trip_update(str instance->initialized = true; - mutex_lock(&instance->cdev->lock); - instance->cdev->updated = false; /* cdev needs update */ - mutex_unlock(&instance->cdev->lock); + scoped_guard(cooling_dev, instance->cdev) { + instance->cdev->updated = false; /* cdev needs update */ + } } } From patchwork Thu Oct 10 22:20:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 834415 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4446C1C172A; Thu, 10 Oct 2024 22:22:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728598959; cv=none; b=DR8fZ0VAKHc5tYTD3z58hEh67jbDncRg/HTndtn5xjLIzRZRUE4dubytA8quk/C7XJj5DVE7Vu8xay3N+GyygMGIjKSFBgfJmpD1tfhn0XZGRWB+LpDvVzIQgjykfH+IE05LVSK3Tr9b/nl6yl4U3+CQg5Q/VO7ZkjbB+jv7FMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728598959; c=relaxed/simple; bh=sbzkRocgHF+RLVRdsZm18wLCdz4OqurChzrAtJI9nk4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fzgewm2Kk4zgpLIXCNCh+WcXRXfV07X/WhHAei6e28gc3uapmgc13B1pWivmtBvy5CtGnPaG8rsauP7j7wDgwFqKQrBkSTxlSWkTIIVnpvV9/Jhb7hF6v0arxBJQZYSf6fzvAaQlmr6ryo24K7/v2HdoZ2pG/i+ZyDysX8Ehyt0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=ucH3W9WC reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="ucH3W9WC" 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 6.2.0) id 1f06392505035da9; Fri, 11 Oct 2024 00:22:25 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (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 cloudserver094114.home.pl (Postfix) with ESMTPSA id A49A169EF02; Fri, 11 Oct 2024 00:22:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1728598945; bh=sbzkRocgHF+RLVRdsZm18wLCdz4OqurChzrAtJI9nk4=; h=From:Subject:Date; b=ucH3W9WC3xecLxItzi8dYrRNGIC75szLlUwpFNHojI7dDujDpyDzbueWWMQdTHqNx dzRojgqdSlglfTpP0ICIdWf8kkInWLNYlMYeW759w56fP2hMFQ9ltIKvAaYHy6WFSl QkYTP6Jyqx4DWs10Xhvn6SFM6ztXYBWvsPbjJ1lFfMY3tQMOXWigtNW1QRpEBTs/8U jcoQ92DEGE2T3pvHaRnjk4aVHxjlrutTZOZUKSu14otL48MStYrRaX9jzqUZoCEizN 5IdEgUtU/NHZoNyMFNtMXHRFnia6il4XieU5u9Z2NA+7vVesfKZkqbUgqG/zrn3dsI 23CHETi6jFv9Q== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Lukasz Luba , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v2 10/11] thermal: core: Separate thermal zone governor initialization Date: Fri, 11 Oct 2024 00:20:56 +0200 Message-ID: <4408795.ejJDZkT8p0@rjwysocki.net> In-Reply-To: <4985597.31r3eYUQgx@rjwysocki.net> References: <4985597.31r3eYUQgx@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeeftddrvdefjedguddtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepfeduudeutdeugfelffduieegiedtueefledvjeegffdttefhhffhtefhleejgfetnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpehrjhifsehrjhifhihsohgtkhhirdhnvghtpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtoheprhhuihdriih X-DCC--Metrics: v370.home.net.pl 0; Body=6 Fuz1=6 Fuz2=6 From: Rafael J. Wysocki In preparation for a subsequent change that will switch over the thermal core to using a mutex guard for managing thermal_governor_lock, move the code running in thermal_zone_device_register_with_trips() under that lock into a separate function called thermal_zone_init_governor(). While at it, drop a useless comment. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- This is a resend of https://lore.kernel.org/linux-pm/2495577.jE0xQCEvom@rjwysocki.net/ --- drivers/thermal/thermal_core.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -1343,6 +1343,25 @@ int thermal_zone_get_crit_temp(struct th } EXPORT_SYMBOL_GPL(thermal_zone_get_crit_temp); +static int thermal_zone_init_governor(struct thermal_zone_device *tz) +{ + struct thermal_governor *governor; + int ret; + + mutex_lock(&thermal_governor_lock); + + if (tz->tzp) + governor = __find_governor(tz->tzp->governor_name); + else + governor = def_governor; + + ret = thermal_set_governor(tz, governor); + + mutex_unlock(&thermal_governor_lock); + + return ret; +} + static void thermal_zone_init_complete(struct thermal_zone_device *tz) { struct thermal_cooling_device *cdev; @@ -1407,7 +1426,6 @@ thermal_zone_device_register_with_trips( struct thermal_trip_desc *td; int id; int result; - struct thermal_governor *governor; if (!type || strlen(type) == 0) { pr_err("No thermal zone type defined\n"); @@ -1505,21 +1523,9 @@ thermal_zone_device_register_with_trips( if (result) goto release_device; - /* Update 'this' zone's governor information */ - mutex_lock(&thermal_governor_lock); - - if (tz->tzp) - governor = __find_governor(tz->tzp->governor_name); - else - governor = def_governor; - - result = thermal_set_governor(tz, governor); - if (result) { - mutex_unlock(&thermal_governor_lock); + result = thermal_zone_init_governor(tz); + if (result) goto unregister; - } - - mutex_unlock(&thermal_governor_lock); if (!tz->tzp || !tz->tzp->no_hwmon) { result = thermal_add_hwmon_sysfs(tz); From patchwork Thu Oct 10 22:22:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 834420 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEA201BDA9A; Thu, 10 Oct 2024 22:22:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728598957; cv=none; b=UZf12Z/i6PauxMLuj7xU4WxrAXttNmD7HRLKJv6qAOrvdCEBDi3u8sq9daq3GWhxm09v9CkctgjWDMHELiq0XBNYJnImHP45kPcW/bmeshgcoC15P8akDxZrFAvZQQ/jSSv5TzeL6dWRnL4f3yoa78qdIABybeuz2f6n9lPN6pc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728598957; c=relaxed/simple; bh=/ZCMzvsyY8AkHkTgqfvOe0987FpFdTCSBezdckfQuss=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MmSQ9w7al1cxYKaiQ1kVAEINGaNIPO8GzEkashKchuGrX+dx/3mE7yYmKiappdcHY2pFyKVvjhoWV2GEQb4BMvd3H6wvlqtKgK2SQbdvT6CMt5qJOTptWlaJ02qejl83+4nQ5VZr1Nt7Hq07P4FefoDFfaWl5AVg9TAStLlpKFA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=eNapYM1q reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="eNapYM1q" 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 6.2.0) id 92e9b709ea85c6a5; Fri, 11 Oct 2024 00:22:25 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (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 cloudserver094114.home.pl (Postfix) with ESMTPSA id 3507369EF02; Fri, 11 Oct 2024 00:22:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1728598945; bh=/ZCMzvsyY8AkHkTgqfvOe0987FpFdTCSBezdckfQuss=; h=From:Subject:Date; b=eNapYM1qme+moj8TNyhiVf4tEjaInNKOgRCi8MFoH+lGDtX1ZOVkXUqMAAoqyZnfC JbkfRgKN2wxnpWii7oiMEdIhrT/XC9BXR4ck+tGA4Sa2js34kCZh7E6IZh/Glkz5X6 4yi+EHSdr1lfBqjuuST+Rzo3iNOsJ4YLgbv0eL5mZGqM09fCOawRNu/453u8dqU/Ur bjkMLlDp94UDpU3fQMqrlwkHuDWgAx/g1BEpfDIQHOb0PefmEdyVC6+noS5pYEYJIx HI+aq4/LlaT7X15MW5elTWkFd4tsnZ3k6UOrf4X8V/y2eGumVBJG2bILKxeCk1LSkz 7lr0Zgeijvpjw== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Lukasz Luba , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v2 11/11] thermal: core: Manage thermal_governor_lock using a mutex guard Date: Fri, 11 Oct 2024 00:22:09 +0200 Message-ID: <3679429.R56niFO833@rjwysocki.net> In-Reply-To: <4985597.31r3eYUQgx@rjwysocki.net> References: <4985597.31r3eYUQgx@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeeftddrvdefjedguddtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepfeduudeutdeugfelffduieegiedtueefledvjeegffdttefhhffhtefhleejgfetnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpehrjhifsehrjhifhihsohgtkhhirdhnvghtpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtoheprhhuihdriih X-DCC--Metrics: v370.home.net.pl 0; Body=6 Fuz1=6 Fuz2=6 From: Rafael J. Wysocki Switch over the thermal core to using a mutex guard for thermal_governor_lock management. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Lukasz Luba --- This is a resend of https://lore.kernel.org/linux-pm/863177860.0ifERbkFSE@rjwysocki.net/ --- drivers/thermal/thermal_core.c | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -124,7 +124,7 @@ int thermal_register_governor(struct the if (!governor) return -EINVAL; - mutex_lock(&thermal_governor_lock); + guard(mutex)(&thermal_governor_lock); err = -EBUSY; if (!__find_governor(governor->name)) { @@ -163,8 +163,6 @@ int thermal_register_governor(struct the } } - mutex_unlock(&thermal_governor_lock); - return err; } @@ -175,10 +173,10 @@ void thermal_unregister_governor(struct if (!governor) return; - mutex_lock(&thermal_governor_lock); + guard(mutex)(&thermal_governor_lock); if (!__find_governor(governor->name)) - goto exit; + return; list_del(&governor->governor_list); @@ -189,9 +187,6 @@ void thermal_unregister_governor(struct THERMAL_NAME_LENGTH)) thermal_set_governor(pos, NULL); } - -exit: - mutex_unlock(&thermal_governor_lock); } int thermal_zone_device_set_policy(struct thermal_zone_device *tz, @@ -200,16 +195,13 @@ int thermal_zone_device_set_policy(struc struct thermal_governor *gov; int ret = -EINVAL; - mutex_lock(&thermal_governor_lock); - + guard(mutex)(&thermal_governor_lock); guard(thermal_zone)(tz); gov = __find_governor(strim(policy)); if (gov) ret = thermal_set_governor(tz, gov); - mutex_unlock(&thermal_governor_lock); - thermal_notify_tz_gov_change(tz, policy); return ret; @@ -220,15 +212,13 @@ int thermal_build_list_of_policies(char struct thermal_governor *pos; ssize_t count = 0; - mutex_lock(&thermal_governor_lock); + guard(mutex)(&thermal_governor_lock); list_for_each_entry(pos, &thermal_governor_list, governor_list) { count += sysfs_emit_at(buf, count, "%s ", pos->name); } count += sysfs_emit_at(buf, count, "\n"); - mutex_unlock(&thermal_governor_lock); - return count; } @@ -668,17 +658,18 @@ int for_each_thermal_governor(int (*cb)( void *data) { struct thermal_governor *gov; - int ret = 0; - mutex_lock(&thermal_governor_lock); + guard(mutex)(&thermal_governor_lock); + list_for_each_entry(gov, &thermal_governor_list, governor_list) { + int ret; + ret = cb(gov, data); if (ret) - break; + return ret; } - mutex_unlock(&thermal_governor_lock); - return ret; + return 0; } int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *, @@ -1346,20 +1337,15 @@ EXPORT_SYMBOL_GPL(thermal_zone_get_crit_ static int thermal_zone_init_governor(struct thermal_zone_device *tz) { struct thermal_governor *governor; - int ret; - mutex_lock(&thermal_governor_lock); + guard(mutex)(&thermal_governor_lock); if (tz->tzp) governor = __find_governor(tz->tzp->governor_name); else governor = def_governor; - ret = thermal_set_governor(tz, governor); - - mutex_unlock(&thermal_governor_lock); - - return ret; + return thermal_set_governor(tz, governor); } static void thermal_zone_init_complete(struct thermal_zone_device *tz)