Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4532752rdh; Wed, 29 Nov 2023 04:17:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IH19o36L7MNkyJIK+76CFUL2sB4uLldls3eIJQ68mJjN9CLNAGxbeHcINJWIuqClTLib0M+ X-Received: by 2002:a17:90b:1b4b:b0:285:b1b8:e29c with SMTP id nv11-20020a17090b1b4b00b00285b1b8e29cmr12570580pjb.12.1701260245557; Wed, 29 Nov 2023 04:17:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701260245; cv=none; d=google.com; s=arc-20160816; b=N775FwwQjAhoQfwex23I6YB/5TD/FBDmp98czHKhglnyqJM40A9H5EPLTA1Fl0wUI+ V4Pogdfrz+zDuApfOMUlIDAlegjHnTb56joXiahEFKTdYiZQh2pVrrlOa9DeJ3dy/qK7 7iwqiVhc6zIhOgaDQ6G8OlLFQQj0GP4fzaMZT5QYTlKpNL0El1T5CvvbpbnLuUjS1QS7 8SpJ9rwBVe14xDqsm8JOP7APj2q5UunmRrcjIO1EeVKOL3kPv6HDHKqph+J6ME3SsWVI NkKiH7hDBkXeNi6DY+b/aev+DNcZuBCjKg+R9abU9+NGqz7bp5ZmDgUJPnpHq1y7Edjo m+HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=IPI+PyJuhoDAPV4O7TWPe9yTeoTEQL4EkcPpeoe8bPI=; fh=0cpBOKuWf+FfnPJZG/zhkSBJdPvgX7kxtRw/of8L22s=; b=rXC1Pd06eYtPhZvX62PMhZIvSwEuiGnDlMcopxhb8TS6zm6CwzsIAdXsKJzw2GRIPH F/HuXrDk3sA6Nq5ORP6z7Zyud0ctAJpfCKnhbHQzgQQ7eZ1T73knItwhRnWpQm8olqIe O+7V4ffwaCL2S5s1WL0Z2upnhithFxpHbBAZSFqnK9sRkxUmyvJRwHisrSYWhwfahfZn uDlaN+hPQI+y+hvzBv8zpifB5kJH6DfpfsyMzJucSKqHWo3N+GreLUp0WxLUSAvgk2u1 ikrSR5KBC8MJgZGIFDSdPv0HehPp0VWH1hKvQlLOsA0W187DRIk6Epqo4weT/QvLfGHU SZtw== 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:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id ju4-20020a170903428400b001cf570ea116si9146884plb.353.2023.11.29.04.17.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 04:17:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 16B28804C23D; Wed, 29 Nov 2023 04:17:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233250AbjK2MQ7 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 29 Nov 2023 07:16:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232531AbjK2MQ6 (ORCPT ); Wed, 29 Nov 2023 07:16:58 -0500 Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D821C1; Wed, 29 Nov 2023 04:17:04 -0800 (PST) Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-6d8572850d3so2502a34.0; Wed, 29 Nov 2023 04:17:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701260224; x=1701865024; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pvwOohdASXCmhvC8e8r/93X0bNZ1/T9LRttQJCmrblQ=; b=X5q/4OdQrRRowSA/Mh5F3OIWqZmhOdNq0eKTixv4lJM6ezZ9euWHy+kBwHaIr5O5D3 nL3PhcDYctxSbzZq0PqeMELKeMfGKNPfvncjwbcoS+oBHVQLWxbck+K9pYolr969VVxJ dDnW7JeqLveYxGo3XPS6iyLUJ6Wnxzl0ibmjg0fpT9xRYDQcIbybmFlXqPkDcF7FRkKZ BkXTmbOiEIYJ1FLqFv0GSPHvojzO6TXJU14XO5qzG45TWPopa/paCNZ/5Ib/bvin4do/ LJBUKFNgH9aWmKZ7mCOBdtaj4YO+7IEDa4hLRbmJxTbbthu8puWWVEIr29Mcaky/nDcQ Cr2g== X-Gm-Message-State: AOJu0Yw0LiXBaQfOT757GergN3QDQ8mljih37E+rMuhBJ+vkxuonpSkK 8QCYX78JqUBRXCcSODRs0glQEF0L2/yERvUM4ehGfWOR X-Received: by 2002:a4a:e89b:0:b0:58d:8879:7005 with SMTP id g27-20020a4ae89b000000b0058d88797005mr9041459ooe.0.1701260223539; Wed, 29 Nov 2023 04:17:03 -0800 (PST) MIME-Version: 1.0 References: <6010559.lOV4Wx5bFT@kreacher> <1887866.tdWV9SEqCh@kreacher> <8524d5f3-6204-44a2-aded-694769dfadd2@arm.com> In-Reply-To: <8524d5f3-6204-44a2-aded-694769dfadd2@arm.com> From: "Rafael J. Wysocki" Date: Wed, 29 Nov 2023 13:16:51 +0100 Message-ID: Subject: Re: [PATCH v2 2/2] thermal: trip: Rework thermal_zone_set_trip() and its callers To: Lukasz Luba Cc: "Rafael J. Wysocki" , LKML , Linux PM , Daniel Lezcano , Srinivas Pandruvada , Zhang Rui Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=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 pete.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 (pete.vger.email [0.0.0.0]); Wed, 29 Nov 2023 04:17:19 -0800 (PST) On Tue, Nov 28, 2023 at 10:42 PM Lukasz Luba wrote: > > > > 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;'... Good catch, thank you! > > + > > + 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. Right.