From patchwork Mon Dec 4 14:50:11 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: 173419 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2814191vqy; Mon, 4 Dec 2023 06:53:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFScXbAU73Ppdqp+8FV4f5zc6+YwCj0rZAX3eZAixd4PmwrTwejQjuxPUfGwh0329bHiBG8 X-Received: by 2002:a05:6a20:914a:b0:18c:95f1:20bf with SMTP id x10-20020a056a20914a00b0018c95f120bfmr5852488pzc.47.1701701589958; Mon, 04 Dec 2023 06:53:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701701589; cv=none; d=google.com; s=arc-20160816; b=n2MR8Ma8iP7yXjK9jCQLkNilOjdjjy0HJIFo4ieya8F35uqHe3m8t378C8iB2BHASg YGpNJRqTfNvzCNCFs9N2wVuOJbsvRRFXIRQQ/tbSCt6umQnEg2EJiChbTp2r5TzCUr49 pAdvmxw36swB8gUvrD1+RG9ejdLDdQFfV15kbn5F7vaYYzyjGKRlTzdGGG4J3eHH3oUU wtI2Ey9clD1e86UXvkfQI1aStb5WBwb8QnCv1Fj3gsQGK6juC90zJ6UgvDIX6txgutck GUOwGowQr1F2uaU0Yno/03FNB5eMgg9dKYj60xI8au0FVUNDSk/f7VMvETUemZaDoFRd Pe1Q== 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=JzHuVGPGwh/6Mg6Sh/SzuThSawHuvp9ZNX1mBxSjfIQ=; fh=nLypB3rvk504GacFIka1NRIrs+dxk/mQtlixTJ9Bzjw=; b=l9lu9enrPQLv5cuJOrxyxOV3GyEXDyjkVhJwnsbJWcp08PXgbQtNv0hlklYRPC2RdU PU4S3Rlson4GlFYL1EB2Wp30ZPVkn3ITDd1d+gM1tqdBh1b+KIolPmTMB3LVeLa3AkzJ izAKUI0J38zY1SIQDeWx3igsgS3NBup3AFZ9kktXWlZ6KcJ2y+Ldpdxe818MWZ3xjrL5 K43FeiCeSQM2fo+7ZAJSdL2klWaAbEJsrqEmeSNYHr6FpsbEeGdNi1Mqp0NtWSmuPAZB iEb8TAAAv/pBFx9dyZ2L05vTgaUdVN/nCsSwW6KB627eS3lNjDMmsK5uJLAC5Sjd3MBe QCcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id y18-20020a056a00191200b006cc0288a7basi7997447pfi.33.2023.12.04.06.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 06:53:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id CD34E80A9933; Mon, 4 Dec 2023 06:53:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346021AbjLDOwz (ORCPT + 99 others); Mon, 4 Dec 2023 09:52:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234481AbjLDOwv (ORCPT ); Mon, 4 Dec 2023 09:52:51 -0500 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6844BB3; Mon, 4 Dec 2023 06:52:56 -0800 (PST) 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.4.0) id c1a7933d2ff66a7c; Mon, 4 Dec 2023 15:52:54 +0100 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 6F9EC66875B; Mon, 4 Dec 2023 15:52:54 +0100 (CET) From: "Rafael J. Wysocki" To: Daniel Lezcano , Lukasz Luba Cc: Linux PM , LKML , Srinivas Pandruvada , Zhang Rui Subject: [PATCH v3 1/2] thermal: sysfs: Rework the handling of trip point updates Date: Mon, 04 Dec 2023 15:50:11 +0100 Message-ID: <4883151.31r3eYUQgx@kreacher> In-Reply-To: <12338384.O9o76ZdvQC@kreacher> References: <12338384.O9o76ZdvQC@kreacher> 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: gggruggvucftvghtrhhoucdtuddrgedvkedrudejiedgjeduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepiedprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehsrhhi nhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtoheprhhuihdriihhrghnghesihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 06:53:08 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784363446293600243 X-GMAIL-MSGID: 1784363446293600243 From: Rafael J. Wysocki Both trip_point_temp_store() and trip_point_hyst_store() use thermal_zone_set_trip() to update a given trip point, but none of them actually needs to change more than one field in struct thermal_trip representing it. However, each of them effectively calls __thermal_zone_get_trip() twice in a row for the same trip index value, once directly and once via thermal_zone_set_trip(), which is not particularly efficient, and the way in which thermal_zone_set_trip() carries out the update is not particularly straightforward. Moreover, input processing need not be done under the thermal zone lock in any of these functions. Rework trip_point_temp_store() and trip_point_hyst_store() to address the above, move the part of thermal_zone_set_trip() that is still useful to a new function called thermal_zone_trip_updated() and drop the rest of it. While at it, make trip_point_hyst_store() reject negative hysteresis values. Signed-off-by: Rafael J. Wysocki --- v2 -> v3: No changes v1 -> v2: Still check device_is_registered() under the zone lock --- drivers/thermal/thermal_core.h | 2 + drivers/thermal/thermal_sysfs.c | 75 ++++++++++++++++++++++++++++------------ drivers/thermal/thermal_trip.c | 45 ++++-------------------- include/linux/thermal.h | 4 -- 4 files changed, 64 insertions(+), 62 deletions(-) Index: linux-pm/drivers/thermal/thermal_sysfs.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_sysfs.c +++ linux-pm/drivers/thermal/thermal_sysfs.c @@ -78,6 +78,19 @@ mode_store(struct device *dev, struct de return count; } +static int check_thermal_zone_and_trip_id(struct device *dev, + struct thermal_zone_device *tz, + int trip_id) +{ + if (!device_is_registered(dev)) + return -ENODEV; + + if (trip_id < 0 || trip_id >= tz->num_trips) + return -EINVAL; + + return 0; +} + static ssize_t trip_point_type_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -120,28 +133,37 @@ trip_point_temp_store(struct device *dev const char *buf, size_t count) { struct thermal_zone_device *tz = to_thermal_zone(dev); - struct thermal_trip trip; + struct thermal_trip *trip; int trip_id, ret; + int temp; + + ret = kstrtoint(buf, 10, &temp); + if (ret) + return -EINVAL; if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip_id) != 1) return -EINVAL; mutex_lock(&tz->lock); - if (!device_is_registered(dev)) { - ret = -ENODEV; - goto unlock; - } - - ret = __thermal_zone_get_trip(tz, trip_id, &trip); + ret = check_thermal_zone_and_trip_id(dev, tz, trip_id); if (ret) goto unlock; - ret = kstrtoint(buf, 10, &trip.temperature); - if (ret) - goto unlock; + trip = &tz->trips[trip_id]; + + if (temp != trip->temperature) { + if (tz->ops->set_trip_temp) { + ret = tz->ops->set_trip_temp(tz, trip_id, temp); + if (ret) + goto unlock; + } + + trip->temperature = temp; + + thermal_zone_trip_updated(tz, trip); + } - ret = thermal_zone_set_trip(tz, trip_id, &trip); unlock: mutex_unlock(&tz->lock); @@ -179,28 +201,37 @@ trip_point_hyst_store(struct device *dev const char *buf, size_t count) { struct thermal_zone_device *tz = to_thermal_zone(dev); - struct thermal_trip trip; + struct thermal_trip *trip; int trip_id, ret; + int hyst; + + ret = kstrtoint(buf, 10, &hyst); + if (ret || hyst < 0) + return -EINVAL; if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip_id) != 1) return -EINVAL; mutex_lock(&tz->lock); - if (!device_is_registered(dev)) { - ret = -ENODEV; - goto unlock; - } - - ret = __thermal_zone_get_trip(tz, trip_id, &trip); + ret = check_thermal_zone_and_trip_id(dev, tz, trip_id); if (ret) goto unlock; - ret = kstrtoint(buf, 10, &trip.hysteresis); - if (ret) - goto unlock; + trip = &tz->trips[trip_id]; + + if (hyst != trip->hysteresis) { + if (tz->ops->set_trip_hyst) { + ret = tz->ops->set_trip_hyst(tz, trip_id, hyst); + if (ret) + goto unlock; + } + + trip->hysteresis = hyst; + + thermal_zone_trip_updated(tz, trip); + } - ret = thermal_zone_set_trip(tz, trip_id, &trip); unlock: mutex_unlock(&tz->lock); Index: linux-pm/drivers/thermal/thermal_core.h =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.h +++ linux-pm/drivers/thermal/thermal_core.h @@ -124,6 +124,8 @@ int __thermal_zone_get_trip(struct therm struct thermal_trip *trip); int thermal_zone_trip_id(struct thermal_zone_device *tz, const struct thermal_trip *trip); +void thermal_zone_trip_updated(struct thermal_zone_device *tz, + const struct thermal_trip *trip); int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp); /* sysfs I/F */ Index: linux-pm/drivers/thermal/thermal_trip.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_trip.c +++ linux-pm/drivers/thermal/thermal_trip.c @@ -147,42 +147,6 @@ int thermal_zone_get_trip(struct thermal } EXPORT_SYMBOL_GPL(thermal_zone_get_trip); -int thermal_zone_set_trip(struct thermal_zone_device *tz, int trip_id, - const struct thermal_trip *trip) -{ - struct thermal_trip t; - int ret; - - ret = __thermal_zone_get_trip(tz, trip_id, &t); - if (ret) - return ret; - - if (t.type != trip->type) - return -EINVAL; - - if (t.temperature != trip->temperature && tz->ops->set_trip_temp) { - ret = tz->ops->set_trip_temp(tz, trip_id, trip->temperature); - if (ret) - return ret; - } - - if (t.hysteresis != trip->hysteresis && tz->ops->set_trip_hyst) { - ret = tz->ops->set_trip_hyst(tz, trip_id, trip->hysteresis); - if (ret) - return ret; - } - - if (tz->trips && (t.temperature != trip->temperature || t.hysteresis != trip->hysteresis)) - tz->trips[trip_id] = *trip; - - thermal_notify_tz_trip_change(tz->id, trip_id, trip->type, - trip->temperature, trip->hysteresis); - - __thermal_zone_device_update(tz, THERMAL_TRIP_CHANGED); - - return 0; -} - int thermal_zone_trip_id(struct thermal_zone_device *tz, const struct thermal_trip *trip) { @@ -192,3 +156,12 @@ int thermal_zone_trip_id(struct thermal_ */ return trip - tz->trips; } + +void thermal_zone_trip_updated(struct thermal_zone_device *tz, + const struct thermal_trip *trip) +{ + thermal_notify_tz_trip_change(tz->id, thermal_zone_trip_id(tz, trip), + trip->type, trip->temperature, + trip->hysteresis); + __thermal_zone_device_update(tz, THERMAL_TRIP_CHANGED); +} Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -282,10 +282,6 @@ int __thermal_zone_get_trip(struct therm struct thermal_trip *trip); int thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, struct thermal_trip *trip); - -int thermal_zone_set_trip(struct thermal_zone_device *tz, int trip_id, - const struct thermal_trip *trip); - int for_each_thermal_trip(struct thermal_zone_device *tz, int (*cb)(struct thermal_trip *, void *), void *data); From patchwork Mon Dec 4 14:52:22 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: 173418 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2814173vqy; Mon, 4 Dec 2023 06:53:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IFHyQzaHZJouhu804y7IHdoF3MaJ8NSnrn3CpO6CfZ0+IcGHlQhZaS8yJ2XHccu9jf6K+OX X-Received: by 2002:a17:90a:72c4:b0:286:6cc0:884c with SMTP id l4-20020a17090a72c400b002866cc0884cmr1597317pjk.57.1701701588297; Mon, 04 Dec 2023 06:53:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701701588; cv=none; d=google.com; s=arc-20160816; b=FTwv5crF9rdURviWjz7c+72zjC8S7eTeQPQOI/SgT5DNlI0zbD0bHoA83gzTsurHHX ayRMYOaP4EPPSV4ZiBZ5I4bVrQDqiRRjgunEKrH4HqLfxAYzlTq2FiH4wl7EjF1D0hH5 XDdi/44/94q3WlCkxsdpymp+Z2BJwi7pwH3+xp21pCVQHMNh2Dlhf2yoGjBL4kVKvfms chTa0108wXLLlkWO7uy6qx1hFKM4YWWVQZXhYIhrO2Yv861cAWil3BOq76jkus1ws4qG 4upNHWhfwZ8r89MT/3KzyYl+NzO4q5qs8EX/AFc1V++sNhZEPATiDa0NSsRq10Fjgz9Z 5ARw== 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=aAM4ppuVcrtxpDvY03fHBEMxU7uZ86eEum/KbivxUZI=; fh=nLypB3rvk504GacFIka1NRIrs+dxk/mQtlixTJ9Bzjw=; b=CqcBYpBgN0AVVcvzBlOx6QDqKQQDPOwRuoUxzfqgfiY28B6RUXX98siKvLFS4l/83K rPFD/AovI/PgifPtzxHRMOGcLX24fY3hVvHymJfMcwSB0lPMNGITVoQ8GogDO/NGPaJe pOqejLGkH35/Z9KLW24hjsr7XGe4Js+ozz4ajnE3bkTcC7Aw0geKz4pN0YpVdlxMXBVq ypues0q5jIa+WeK0EGhjYRf6A9LoDJSQowUdS4Zem2nQKKusGLYLj3qBNRVAKDvYs2vo CwZhPw7PxoducnMzgUTkY2oNrgoM7dTg6IaVJ1OBAmGSphoAMDvjpk+j0yNU2EPCCa2p AnHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id kk17-20020a17090b4a1100b00286bc991cd5si1324403pjb.86.2023.12.04.06.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 06:53:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id EF5A78098808; Mon, 4 Dec 2023 06:53:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346016AbjLDOwx (ORCPT + 99 others); Mon, 4 Dec 2023 09:52:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235899AbjLDOwu (ORCPT ); Mon, 4 Dec 2023 09:52:50 -0500 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BBF3FD; Mon, 4 Dec 2023 06:52:55 -0800 (PST) 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.4.0) id 140b955ce2589623; Mon, 4 Dec 2023 15:52:54 +0100 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 B702766875B; Mon, 4 Dec 2023 15:52:53 +0100 (CET) From: "Rafael J. Wysocki" To: Daniel Lezcano , Lukasz Luba Cc: Linux PM , LKML , Srinivas Pandruvada , Zhang Rui Subject: [PATCH v3 2/2] thermal: sysfs: Rework the reading of trip point attributes Date: Mon, 04 Dec 2023 15:52:22 +0100 Message-ID: <4855368.GXAFRqVoOG@kreacher> In-Reply-To: <12338384.O9o76ZdvQC@kreacher> References: <12338384.O9o76ZdvQC@kreacher> 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: gggruggvucftvghtrhhoucdtuddrgedvkedrudejiedgjeduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepiedprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehsrhhi nhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtoheprhhuihdriihhrghnghesihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 04 Dec 2023 06:53:02 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784363444313033861 X-GMAIL-MSGID: 1784363444313033861 From: Rafael J. Wysocki Rework the _show() callback functions for the trip point temperature, hysteresis and type attributes to avoid copying the values of struct thermal_trip fields that they do not use and to make them carry out validation checks with the help of check_thermal_zone_and_trip_id(), like the corresponding _store() callback functions. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- v2 -> v3: Drop a redundant 'ret' check at the end of trip_point_hyst_show. v1 -> v2: Do not drop thermal zone locking from the _store() callback functions. --- drivers/thermal/thermal_sysfs.c | 55 ++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 27 deletions(-) Index: linux-pm/drivers/thermal/thermal_sysfs.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_sysfs.c +++ linux-pm/drivers/thermal/thermal_sysfs.c @@ -96,25 +96,25 @@ trip_point_type_show(struct device *dev, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); - struct thermal_trip trip; - int trip_id, result; + enum thermal_trip_type type; + int trip_id, ret; if (sscanf(attr->attr.name, "trip_point_%d_type", &trip_id) != 1) return -EINVAL; mutex_lock(&tz->lock); - if (device_is_registered(dev)) - result = __thermal_zone_get_trip(tz, trip_id, &trip); - else - result = -ENODEV; + ret = check_thermal_zone_and_trip_id(dev, tz, trip_id); + if (ret) { + mutex_unlock(&tz->lock); + return ret; + } - mutex_unlock(&tz->lock); + type = tz->trips[trip_id].type; - if (result) - return result; + mutex_unlock(&tz->lock); - switch (trip.type) { + switch (type) { case THERMAL_TRIP_CRITICAL: return sprintf(buf, "critical\n"); case THERMAL_TRIP_HOT: @@ -175,25 +175,24 @@ trip_point_temp_show(struct device *dev, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); - struct thermal_trip trip; - int trip_id, ret; + int trip_id, ret, temp; if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip_id) != 1) return -EINVAL; mutex_lock(&tz->lock); - if (device_is_registered(dev)) - ret = __thermal_zone_get_trip(tz, trip_id, &trip); - else - ret = -ENODEV; + ret = check_thermal_zone_and_trip_id(dev, tz, trip_id); + if (ret) { + mutex_unlock(&tz->lock); + return ret; + } - mutex_unlock(&tz->lock); + temp = tz->trips[trip_id].temperature; - if (ret) - return ret; + mutex_unlock(&tz->lock); - return sprintf(buf, "%d\n", trip.temperature); + return sprintf(buf, "%d\n", temp); } static ssize_t @@ -243,22 +242,24 @@ trip_point_hyst_show(struct device *dev, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); - struct thermal_trip trip; - int trip_id, ret; + int trip_id, ret, hyst; if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip_id) != 1) return -EINVAL; mutex_lock(&tz->lock); - if (device_is_registered(dev)) - ret = __thermal_zone_get_trip(tz, trip_id, &trip); - else - ret = -ENODEV; + ret = check_thermal_zone_and_trip_id(dev, tz, trip_id); + if (ret) { + mutex_unlock(&tz->lock); + return ret; + } + + hyst = tz->trips[trip_id].hysteresis; mutex_unlock(&tz->lock); - return ret ? ret : sprintf(buf, "%d\n", trip.hysteresis); + return sprintf(buf, "%d\n", hyst); } static ssize_t