Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1164070rdb; Fri, 20 Oct 2023 10:04:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2zSoixTHrDsS+C42z1yhUhD3J+3akUP9GTI4ZuY2hreU3dunqzdrpzv9rmmciCzlQya3k X-Received: by 2002:a17:90a:cc14:b0:27d:57d:dcb8 with SMTP id b20-20020a17090acc1400b0027d057ddcb8mr2738305pju.47.1697821480904; Fri, 20 Oct 2023 10:04:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697821480; cv=none; d=google.com; s=arc-20160816; b=mE822CQ/6xjehgJjKZb72Tnf7Jh0kUD57BssPky+0dTZEnwXVuQgH0g6wqD47+byLM /L9QWE5frEImfDXF1ZzJQIBrz+mSkMhHT4O/1BPe8rXyvtEC0w+eC9QwCm/QJJZ1qVwT y3q2Z+Of8R/QmelrFnIFb09NaAiqI1GcSftARkLmfiXcXvOmrXjkhAd1/aSFtnoxphna A8lLWrhcJT1jZ11rP0/34LxME8Cw1JgfX21r2Z1/YcfT8PbB/7i9+F5bn7zIuxwR2isT ckRHG81KScGayrAtMT3g3TZ3pgOlAOLkMfS24Kd7UEp6QCZrxgtpuPfhNQ7qtYi6c6cn Dcbg== 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=N6OubLG8T5OJUn4UBcfnBrS6QMmAd/2lYzEJz5DtRAM=; fh=RkIex7BMwGHPYYWl8O5R3ZXiNH/X7HGCywQ3lHHavU8=; b=tWfKmSgNP98jck2nQgfovw9nFBTBf9YIJ34ZQe8y7s0C4XiYW1SUauDbCvA7HY5rEw 4LZZ3LNA9eYinUeQzj7Z0x1UqxCGcThX9Vx72jeA7TNDsozAsXMgXz90PFMqJ6IjPto4 jcqYjaDlQ0GMjx8BDnEbTp46dSld8C7DkZPwF1axmP5XaEz9pcPvyzjIC0/sgzL2naut //e7vEFvbt4gta87JFdsIUhcxV0wzm46dwEMEkfSfF/isjDqB18LAxAOd81ZRjJ8k8Pl 1k8HNBMfOsa0GhnJ5tjyGUG9LRlbHwGW3KG/ZNbVNrnLm9Y9nOS1KrNAYadbZwij1BvJ 2Y7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id nu10-20020a17090b1b0a00b002772ff87ee4si5086094pjb.82.2023.10.20.10.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 10:04:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 732A6801B41C; Fri, 20 Oct 2023 10:04:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377497AbjJTREa convert rfc822-to-8bit (ORCPT + 99 others); Fri, 20 Oct 2023 13:04:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229692AbjJTREa (ORCPT ); Fri, 20 Oct 2023 13:04:30 -0400 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F8E1A3; Fri, 20 Oct 2023 10:04:28 -0700 (PDT) Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-57de3096e25so92007eaf.1; Fri, 20 Oct 2023 10:04:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697821468; x=1698426268; 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=0SVQ8l1CCV9qwZQSfGppRIONwDwSIVUsnVYDUHbg5UE=; b=XknaEqI9SKWVs6Sb6yU0YQUcYW6wcwf36f1wgFVk8cOR0VZ/+C4KIe76jnVj6UVlKT iMKkm4LaEW8kW8Uss/VvnyOy3oPenGyS+xK7Fj1hYK5vxk8sN7+02gRFo4dT4s1bBcFz QWwYyLM7huCDOwrlK9NacLgXKmGrWWbxbHVCy3YXqtpN+j/FU3Y8LvSdqU5kKD2Nt9L1 4kOyEJ5ET9LjxefLTkFw/rmILCZzNxjUeAyZu0nEh46l7S4G25dcF9qz4BRqlmvvFkyr cvIquDcEf3fZ/46IUD+mfuAktkfnq19F04WN17Gbf3cJZHCAxS8alLGlEO4AVTPl+SYL r3Zw== X-Gm-Message-State: AOJu0Yw6+IJmkRh/+EN3A/cOptEY7n0la8vSlV7itxCbaPp3pL9UYMfj 5I2t9mRI3LfEHQV5iId7mrW4mIwwGM88j+gxOiI= X-Received: by 2002:a4a:bd18:0:b0:581:e7b8:dd77 with SMTP id n24-20020a4abd18000000b00581e7b8dd77mr2846282oop.1.1697821467835; Fri, 20 Oct 2023 10:04:27 -0700 (PDT) MIME-Version: 1.0 References: <13365827.uLZWGnKmhe@kreacher> <3256881.aeNJFYEL58@kreacher> <430d4342-a2fd-431f-b279-92ea90b83778@arm.com> In-Reply-To: <430d4342-a2fd-431f-b279-92ea90b83778@arm.com> From: "Rafael J. Wysocki" Date: Fri, 20 Oct 2023 19:04:16 +0200 Message-ID: Subject: Re: [PATCH v1 1/6] thermal: trip: Simplify computing trip indices To: Lukasz Luba Cc: "Rafael J. Wysocki" , LKML , Daniel Lezcano , Srinivas Pandruvada , Zhang Rui , Linux PM 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Fri, 20 Oct 2023 10:04:38 -0700 (PDT) On Fri, Oct 20, 2023 at 6:58 PM Lukasz Luba wrote: > > > > 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 Thanks!