Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1159282rdb; Fri, 20 Oct 2023 09:58:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGU3FFEtYMz8ZjYjHbdMWr5Jd4L0uUu1p2718mJd3BWlxR7yrbsWF5TTGpgTLyUoWTo59Wl X-Received: by 2002:a9d:7754:0:b0:6bc:fdbd:ccb8 with SMTP id t20-20020a9d7754000000b006bcfdbdccb8mr2742151otl.13.1697821108527; Fri, 20 Oct 2023 09:58:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697821108; cv=none; d=google.com; s=arc-20160816; b=rPYRGcnQT2fAwqoNu93uhLBoz8B1dDrU/O4HzOYtZGXZwOcmWwZG4C5Ms1spwplv70 B114zbE9pd3pbmdmtX6Ccqo827TTtYL91Vc1hUsr6IX6kl0jXeaoSaiQC77WroSMe3M9 B2k3+DQHwWp69eYSCvoz3NNuPA7NEJmxPLDs0pZbwlseBWxCGxqXFkWrUk1sCfPu/Otw tLt86G3yFMpQd1VOsjfjYkKYM0LrH7qI/QWoe8WHsONz4x2diN4YjB5wiWYJJyhe+/ho PbTKkoJW83cwVj/7EXQP6O+rgAT2H5V2+dI0S/QQgCDZzuhdGxZKIdLBZcq0hSyqKwFR jCVA== 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=OxSZm3Q9RRO2sCv8wfwGdlUINTbsKoGfww+TLSTAcc0=; fh=Ti+l9dN1V1s4/No4+jOTAJr69T5zUPbby9cCUyZHH/o=; b=CwylQ+Pjb/fIWAQ1k5uWkvkumTyestNSkZVvrUGw3jJRFZp2OlI329Q1bUTINmmHZ/ M4tIz2+baLd5RmykDvi2pEyQsPgT6zU3RL2w6QxhIzg7Pbm+i0X11eaOMg3FcVcvmup9 pMjlOVCEdFsqySa895rb8rm2WsDf8U6cR+3ZaXj/Pz+WQB2JdjHhxMJCc5AJa2dLpYnR nVmJ4ELlNam8Z+WdkemceVOGrREemwDkfUFL0fKGPlmDkN5VHwV221d74S3lph8Y5jqS B+Ss2zgqzoSl6CEccNJqPEt9sf/Pfn90Px9plkez9uZsvcvV+rWtzU1NmRbfrqCx+WRv ZKKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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. [23.128.96.35]) by mx.google.com with ESMTPS id u14-20020a056a00098e00b006bddac4b018si2445734pfg.107.2023.10.20.09.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 09:58:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 282E18304EDC; Fri, 20 Oct 2023 09:58:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229817AbjJTQ6G (ORCPT + 99 others); Fri, 20 Oct 2023 12:58:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229692AbjJTQ6E (ORCPT ); Fri, 20 Oct 2023 12:58:04 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5A0269E; Fri, 20 Oct 2023 09:58:03 -0700 (PDT) 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 00A76143D; Fri, 20 Oct 2023 09:58:44 -0700 (PDT) Received: from [10.57.82.142] (unknown [10.57.82.142]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F2D733F5A1; Fri, 20 Oct 2023 09:58:01 -0700 (PDT) Message-ID: <430d4342-a2fd-431f-b279-92ea90b83778@arm.com> Date: Fri, 20 Oct 2023 17:58:51 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 1/6] thermal: trip: Simplify computing trip indices Content-Language: en-US To: "Rafael J. Wysocki" Cc: LKML , Daniel Lezcano , Srinivas Pandruvada , Zhang Rui , Linux PM References: <13365827.uLZWGnKmhe@kreacher> <3256881.aeNJFYEL58@kreacher> From: Lukasz Luba In-Reply-To: <3256881.aeNJFYEL58@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 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]); Fri, 20 Oct 2023 09:58:26 -0700 (PDT) On 10/6/23 18:40, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > A trip index can be computed right away as a difference between the > value of a trip pointer pointing to the given trip object and the > start of the trips[] table in the thermal zone containing the trip, so > change thermal_zone_trip_id() accordingly. > > No intentional functional impact (except for some speedup). > > Signed-off-by: Rafael J. Wysocki > --- > drivers/thermal/thermal_trip.c | 13 +++++-------- > 1 file changed, 5 insertions(+), 8 deletions(-) > > Index: linux-pm/drivers/thermal/thermal_trip.c > =================================================================== > --- linux-pm.orig/drivers/thermal/thermal_trip.c > +++ linux-pm/drivers/thermal/thermal_trip.c > @@ -175,14 +175,11 @@ int thermal_zone_set_trip(struct thermal > int thermal_zone_trip_id(struct thermal_zone_device *tz, > const struct thermal_trip *trip) > { > - int i; > - > lockdep_assert_held(&tz->lock); > > - for (i = 0; i < tz->num_trips; i++) { > - if (&tz->trips[i] == trip) > - return i; > - } > - > - return -ENODATA; > + /* > + * Assume the trip to be located within the bounds of the thermal > + * zone's trips[] table. > + */ > + return trip - tz->trips; > } > > > I agree wit hthe comment, we should be safe here, since we control that array. I could be a bit picky about this 'int' return in that function on 64bit kernels, were we have also ptrdiff_t set to long IIRC. But this particular usage should be handled properly in all our cases, so: Reviewed-by: Lukasz Luba Tested-by: Lukasz Luba