Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4162706rdh; Tue, 28 Nov 2023 13:42:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfDGd6DoQf4oK9eTW25Oz8KyMkYxRGtuXCS81mYeFq8je3s4etp3DNrXw1PSt6YabEteGl X-Received: by 2002:a05:6830:44a0:b0:6d8:175a:2890 with SMTP id r32-20020a05683044a000b006d8175a2890mr15362131otv.22.1701207734797; Tue, 28 Nov 2023 13:42:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701207734; cv=none; d=google.com; s=arc-20160816; b=0VnRWp26PIi1cau3KLQ6BfSUl1ew0UEPj6JIZdzyWNVEI+xdRrCAhiKZ2gluFkbVFf sfvIXqNUkoUy4/6jXZP7KLYOoeEq/IRDq4EO31i+HxiYS6PHg28Ob3UApO7GFOav/zxx 2MRHqAOp5A1Vewl2ByaZ223+f/+4CnAmdv4pbJTS+a/GH64KJPMtc5/F3vxqJix3VNqz 5EPG01wJc0WpOOreSQRZSY6XtgNkIGM/b9nSjECyLDoFA8j/XWx/ip51hJuMLKH2OR4Y 7r8unR/OMw8+YolX+VVKAYJ319e16a7D3t4HgNRwrBL5GCc8hyPUPdcdzrworKheze0y 1YGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=d6h9PX6X9RBxIAgjaLl0Z0I2Ocu25NHOWpLzAktnijQ=; fh=Jhb7rxZsQO0DdPOhq7EvFSKoHEjO13TbzKhGE3E43sU=; b=M9O1811cn0S3k6ao+cLj34ofVQeWSV3rO24kjL74k1eegyoMvrYVSZC5zdXYtw9o1W 8uDuLDrWlZ605A5mZn3kbPVpax6I0iXV0vj8si1rcITxtXnpPXfJzpZLtFq30Qb9WSOc YYPLs7Du3jNHKVeHJo/1cOksLE+iZ8QRVmXEL+PZgzf54dhFZvcjbi54baKv8EuBYiYo h8UMdRG0V5E7MhXyFq4z0mSKUC6tTpYDVv6pWZ3LSGzhGuHpD5q0eGk5cVSHVeEMu/Vv k2F3g4JCgggE1whPfz2tNBfraPiVUHVIWYhr3n8mJWjrCqTAVo1m1GAn8U/ZnULnip+Y J1eg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id u2-20020a631402000000b005b9377ee20csi12892426pgl.701.2023.11.28.13.42.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 13:42:14 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id C309A8051A36; Tue, 28 Nov 2023 13:42:11 -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 S229835AbjK1Vl5 (ORCPT + 99 others); Tue, 28 Nov 2023 16:41:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbjK1Vl4 (ORCPT ); Tue, 28 Nov 2023 16:41:56 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4F49D98; Tue, 28 Nov 2023 13:42:02 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 418321FB; Tue, 28 Nov 2023 13:42:49 -0800 (PST) Received: from [10.57.2.117] (unknown [10.57.2.117]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D9ECE3F73F; Tue, 28 Nov 2023 13:42:00 -0800 (PST) Message-ID: <8524d5f3-6204-44a2-aded-694769dfadd2@arm.com> Date: Tue, 28 Nov 2023 21:43:00 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/2] thermal: trip: Rework thermal_zone_set_trip() and its callers Content-Language: en-US To: "Rafael J. Wysocki" Cc: LKML , Linux PM , Daniel Lezcano , Srinivas Pandruvada , Zhang Rui References: <6010559.lOV4Wx5bFT@kreacher> <1887866.tdWV9SEqCh@kreacher> From: Lukasz Luba In-Reply-To: <1887866.tdWV9SEqCh@kreacher> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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]); Tue, 28 Nov 2023 13:42:11 -0800 (PST) On 11/28/23 13:58, Rafael J. Wysocki wrote: > 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, some checks done by them both need not go under the thermal > zone lock and code duplication between them can be reduced quite a bit > by moving the majority of logic into thermal_zone_set_trip(). > > Rework all of the above functions to address the above. > > No intentional functional impact. > > Signed-off-by: Rafael J. Wysocki > --- > > v1 -> v2: > * Fix 2 typos in the changelog (Lukasz). > * Split one change into the [1/2]. > > --- > drivers/thermal/thermal_core.h | 9 ++++++ > drivers/thermal/thermal_sysfs.c | 52 ++++++++-------------------------- > drivers/thermal/thermal_trip.c | 60 +++++++++++++++++++++++++++------------- > include/linux/thermal.h | 3 -- > 4 files changed, 62 insertions(+), 62 deletions(-) > [snip] > Index: linux-pm/drivers/thermal/thermal_trip.c > =================================================================== > --- linux-pm.orig/drivers/thermal/thermal_trip.c > +++ linux-pm/drivers/thermal/thermal_trip.c > @@ -148,39 +148,61 @@ 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) > + enum thermal_set_trip_target what, const char *buf) > { > - struct thermal_trip t; > - int ret; > + struct thermal_trip *trip; > + int val, ret = 0; > > - ret = __thermal_zone_get_trip(tz, trip_id, &t); > + if (trip_id < 0 || trip_id >= tz->num_trips) > + ret = -EINVAL; That shouldn't progress forward IMO, but simply 'return -EINVAL;'... > + > + ret = kstrtoint(buf, 10, &val); > if (ret) > return ret; > > - if (t.type != trip->type) > - return -EINVAL; > + mutex_lock(&tz->lock); > > - 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; > - } > + trip = &tz->trips[trip_id]; ... because here we might get an issue.