Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2876034rdb; Mon, 4 Dec 2023 09:47:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFt/MaDy2jc3RtUII+mzyC5EDADDnDWVfoLbj8Qjd4N4I9Cm/xYd9cNrfY8IeSZM4YCcz4i X-Received: by 2002:a05:6a20:2450:b0:18b:92b3:7c80 with SMTP id t16-20020a056a20245000b0018b92b37c80mr6066839pzc.22.1701712051574; Mon, 04 Dec 2023 09:47:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701712051; cv=none; d=google.com; s=arc-20160816; b=02CgHpR65Gxod15wjLn9TGLnnbLuYZQQtss5+UWYaiPagZP4AQdP3d2oIZ0XxdJPhq zAsCWOcsamjlVZXqUc06BLz8/FPhvG6gYNkellvHsxf3P5HdtKt/CT0B4H48BnWndyCm 1g2yt93iX9zlKErTur71iIsepZ+3331o42iRTiZb0llzMw4aTATIma/qUyL2kpbnvCaJ c2Ni3/3tJM1qoEkCgcF75U3n/IfMPnbKYJR7reYDcpZklbl7ZKAgkIm/feTSD9yfWF5S 9Jd5RpTvCv9n7JNoR31zPxWv1XQkP9tE4NQTa/Q/aTouf77CJQ+IP62vTp4NIgZjetcp JVww== 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=H+sEQOj8vGuDT5fA36fqlYjcd8jGZg9Xn4ddpHU+XP0=; fh=0IF0yWUuItGhVBH4/nwTp4ZXaScWJj0Dvu5mJepibYc=; b=W0538cJrimNm568D7MTrIB+Mn0GbT8soNV7I5q0AX9z8mVrvD8MRbbmS7qFAXqikKA JHRT7sKmjHj3YVVE89MgfEotN2vr2qLZm0XxNLh07Ff7Cy2i2H/f4uQfvJqALNqaSMM3 UdY5cPdO137g4RyRj4/31pgbTltdAJKB52g6lYfvfryhAgVIR5xaLMXdim3X2bHvUnuk hsgxDxm91LwHugjiLSSvnlkS/Q7rFdrozmw9zBVLM6t0mB+Zw4ZQn0SwlEANiMTeQ0qW oYPr7lcdkYwNDQ+X28bjzjSZ4EI1o6XsC/ssT4860qIpcyqQULNuFAgBXDWfKnXTdtYC PW7A== 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 p6-20020a634206000000b005be00714949si8160012pga.222.2023.12.04.09.47.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:47:31 -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 7071880413AE; Mon, 4 Dec 2023 09:47:27 -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 S229586AbjLDRrL convert rfc822-to-8bit (ORCPT + 99 others); Mon, 4 Dec 2023 12:47:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbjLDRrK (ORCPT ); Mon, 4 Dec 2023 12:47:10 -0500 Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 702D4F3; Mon, 4 Dec 2023 09:47:16 -0800 (PST) Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-1fb1620a00eso575917fac.1; Mon, 04 Dec 2023 09:47:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701712035; x=1702316835; 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=YLxhbHxHs0yyW58U+USrAp9QZYXyCCBbOT0f2qo1Lmw=; b=Scj0c0/PQKWNuW9DfEoB5V+mrGtkuR4dZzpmVETXHLKLjFJF1PPr8XqdzpVqMgY5Aa 06kStxIrvvqdhBjyRmwS4AAFj36+wvlIbkC+5k1LqD2pnaWSNlPkbV9xKweLqeQIaFCz cq8lptJ1/cbwzOyrgg+Msl2vCqTA61MOOkoNik0cW7+Kb+39y/oVPFKCJ5f1YmrmcHPB zSwuFEI46FaypSqsGkn85hsuuBmMA/s5/EofjX0plNbCfhw0NX54UwP3AwEHTfjzgHp/ jAgUtOOTvePyhFkwOeXmEYU3wnpjfr3iB0gFOGikx+mKpwhLluhpZgd/fgCXKkqz69u+ hF+A== X-Gm-Message-State: AOJu0YzK0oFP9HK8vvp+/IJ6GcfUU+TkgX4Ra/qv3kw2hk7vjoNDi5CM Zfj0aRoW55ME1tjzWvGYeNym4Sf3e7KNs3MigzA= X-Received: by 2002:a05:6870:e38a:b0:1fb:25fb:fabc with SMTP id x10-20020a056870e38a00b001fb25fbfabcmr6338860oad.5.1701712035690; Mon, 04 Dec 2023 09:47:15 -0800 (PST) MIME-Version: 1.0 References: <12338384.O9o76ZdvQC@kreacher> <4883151.31r3eYUQgx@kreacher> In-Reply-To: From: "Rafael J. Wysocki" Date: Mon, 4 Dec 2023 18:47:04 +0100 Message-ID: Subject: Re: [PATCH v3 1/2] thermal: sysfs: Rework the handling of trip point updates To: Daniel Lezcano Cc: "Rafael J. Wysocki" , Lukasz Luba , Linux PM , LKML , 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]); Mon, 04 Dec 2023 09:47:27 -0800 (PST) Hi Daniel, On Mon, Dec 4, 2023 at 5:55 PM Daniel Lezcano wrote: > > > Hi Rafael, > > On 04/12/2023 15:50, 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, 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; > > I'm not sure if this check is useful. The function is called from > trip_point_*_store() which is providing the trip id from the file name > parsing which is in turn built from an existing trip id. There is no > reason the trip id is going to be wrong. I can drop the check just fine. Do you have any other comments on this patch?