From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f176.google.com (mail-dy1-f176.google.com [74.125.82.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9F5828312D for ; Wed, 18 Feb 2026 01:45:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771379146; cv=none; b=mpj9Q7ATJcYy7uQb1DAGh/ecgPG1+EraOY/kHWqrZ0O5pZa11muF7MMEd41XtJ19n4pvwa0m5O7FgxWUEPb5C6JPdrIGOUFtx3OrVB24t/3swBujbvtDnkcDTbEIy5RzWsDPVtxJ6gSp5jjH7LZBPBv/OGN/l/asF2lTEcLr+WY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771379146; c=relaxed/simple; bh=yQeoW4MqfwzTgrBMlSHdUdLyFckPUP27F2W5vrcbNCg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=S1PrNHMHsJ54YmGXr+AM1/uVSDZ5P4erQgj4fh6x3wpd5Iog1BUu2yd3YA8ymhnmRgHs+rYdEqu2YGFWesCDsSOJNgd3JxbyfZZk8TMPtYeBJR/QlMXoEG9kZx++qZrxy9yjWG2ATmhMnZvtL56y9MQZ9LIXIC7hleL2Ew9vxM0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=deKmsegR; arc=none smtp.client-ip=74.125.82.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="deKmsegR" Received: by mail-dy1-f176.google.com with SMTP id 5a478bee46e88-2ba9c484e5eso4831606eec.1 for ; Tue, 17 Feb 2026 17:45:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771379144; x=1771983944; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=SzRez6id0tGCW3l1fRGMuvRJWCHYhvgSDSCiIHHHPic=; b=deKmsegRLQHlKTeYYjEyqOZDbPT9lm7vvpbOJK0dKQ3JSLSddLlEw9hR7WNK3PnB+S nPQZeipF+m1Tozp8onOYCJC6VqhdPdeNMmwiLNkzK8LiU2sI3D8ZlNySIsJ1Qs3TtxEq PTKwqw/RLTdnZHjvUXUJ4YRmH2yyo6gsVnvsniD5M0BFBb4M9KGx6CfSyCIC8Gr6o4Az NHipjdp+8+odThpoYB/EEyucN+Pj3E/Tfg/cipnbQoavXiD+0EIgDooLWweQNFImS6R1 VrhIxRWUtVWGAOYjXala7kefYl82R9MHK2ArB/PowIPHcSI/RubWYLiYj6vj0P8FPrml m7fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771379144; x=1771983944; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SzRez6id0tGCW3l1fRGMuvRJWCHYhvgSDSCiIHHHPic=; b=oH5Deos6PLYAk+FlGD44FP1bMqWCS06qKhB8Z03DMRCY5hOe2mtr1qp1KOTFjH7/V3 a4iEq4vV3H6Zw+DpCJZSyUS9xU+HngLaIn1k0amwX2mDoZ9NzXrJCsB0D+fE3cdawLDH 27sbSwA76oIVMbB1GLHkII9UgJTQiOuDcObHcMdpg/CTycG4wHLacCuaVndR0z2Apy9y lMIx5XVxt6FbqJS6B3AYD4x12Bu6kd1OLMCTHRY+PRAAx2qb73WIRTjy8PrRQPOkPEMy Hg7KNgese1Sl11posiJGsR/PpcRQeKpALvxtvaxGdQi5WegD8RZNSthvXLJOf0fQPQKq DWvw== X-Gm-Message-State: AOJu0YzjqkS9r00Y98tezqOu7AbSljJpaZHYmsFi+3dYAJ9kBaN6NtiT uz6aeocNyKs/XlhNLff5oBjJgUCAP3JYFvXR2Yu8dtWd9UV29sti2wa8py/pgO8zaA== X-Gm-Gg: AZuq6aIgqM8FfrHuT2l4eUoX6Clwsjqeg74SmFfdL6gx0EYM0dgE4dyQNkQVBLCGFp/ ksHlVm0g7zylkeGmdnOchRO1DJjCt8x9w8gFIMAK5MnYiKlOalQh8G3AML2qgeFVQMsNQsd/93j wN83WnMPuOLXnVvuxnyIRtomtO6K74ET8+nv00gVk/iBix2yHg6QEAak+6UKo95fOte5uEQyN90 b2OBsFWaaplXr489EXfsowG9Nn74xw9TZ+4F1w5Y7Mmf0mX0uSjRB5OLWCr5qyVo6/0UsJzN6Tc 9+pYwaoXp6q6wF8D8XpSLmubTwt3N1sg81FIdu9Ku1FLByO0v/LJeJXWxTvEL4tcegHOz/W13I/ 3ASuMn4qd/gNMtTBb3659G96Am147eqv0uX7sSH/JWig9QP7vwhcllDz8dWquNAp2HkF94+CWsK 0x73CeKBo5R1EA+gOU8j6y8qTY1vU97UKfVYzY2Dg8XsgkD7/bFsI8mvPFR4ojBEY3tVI0HAPTC uGJwIxEl7WHAu35sbDMdVFFPQ== X-Received: by 2002:a05:7301:2b06:b0:2ba:964f:fa67 with SMTP id 5a478bee46e88-2bac97ad329mr5688952eec.24.1771379143326; Tue, 17 Feb 2026 17:45:43 -0800 (PST) Received: from ?IPV6:2a00:79e0:2e7c:8:c8f1:53bf:725c:563b? ([2a00:79e0:2e7c:8:c8f1:53bf:725c:563b]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12742cba192sm15951817c88.13.2026.02.17.17.45.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Feb 2026 17:45:42 -0800 (PST) Message-ID: Date: Tue, 17 Feb 2026 17:45:40 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 4/6] lib/linear_ranges: Add linear_range_get_selector_high_array To: Matti Vaittinen , Sebastian Reichel , Rob Herring , Krzysztof Kozlowski , Conor Dooley , =?UTF-8?Q?Andr=C3=A9_Draszik?= , Lee Jones , Greg Kroah-Hartman , Badhri Jagan Sridharan , Heikki Krogerus , Peter Griffin , Tudor Ambarus , Alim Akhtar , Mark Brown , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, RD Babiera , Kyle Tso References: <20260214-max77759-charger-v6-0-28c09bda74b4@google.com> <20260214-max77759-charger-v6-4-28c09bda74b4@google.com> <5d889f66-7697-4a39-beed-33ace693a1ef@gmail.com> Content-Language: en-US From: Amit Sunil Dhamne In-Reply-To: <5d889f66-7697-4a39-beed-33ace693a1ef@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2/16/26 5:58 AM, Matti Vaittinen wrote: > On 14/02/2026 05:12, Amit Sunil Dhamne via B4 Relay wrote: >> From: Amit Sunil Dhamne >> >> Add a helper function to find the selector for a given value in a linear >> range array. The selector should be such that the value it represents >> should be higher or equal to the given value. >> >> Signed-off-by: Amit Sunil Dhamne >> --- >>   include/linux/linear_range.h |  3 +++ >>   lib/linear_ranges.c          | 36 ++++++++++++++++++++++++++++++++++++ >>   2 files changed, 39 insertions(+) >> >> diff --git a/include/linux/linear_range.h b/include/linux/linear_range.h >> index 2e4f4c3539c0..0f3037f1a94f 100644 >> --- a/include/linux/linear_range.h >> +++ b/include/linux/linear_range.h >> @@ -57,5 +57,8 @@ void linear_range_get_selector_within(const struct >> linear_range *r, >>   int linear_range_get_selector_low_array(const struct linear_range *r, >>                       int ranges, unsigned int val, >>                       unsigned int *selector, bool *found); >> +int linear_range_get_selector_high_array(const struct linear_range *r, >> +                     int ranges, unsigned int val, >> +                     unsigned int *selector, bool *found); >>     #endif >> diff --git a/lib/linear_ranges.c b/lib/linear_ranges.c >> index a1a7dfa881de..c85583678f6b 100644 >> --- a/lib/linear_ranges.c >> +++ b/lib/linear_ranges.c >> @@ -241,6 +241,42 @@ int linear_range_get_selector_high(const struct >> linear_range *r, >>   } >>   EXPORT_SYMBOL_GPL(linear_range_get_selector_high); >>   +/** >> + * linear_range_get_selector_high_array - return linear range >> selector for value >> + * @r:        pointer to array of linear ranges where selector is >> looked from >> + * @ranges:    amount of ranges to scan from array >> + * @val:    value for which the selector is searched >> + * @selector:    address where found selector value is updated >> + * @found:    flag to indicate that given value was in the range >> + * >> + * Scan array of ranges for selector for which range value matches >> given >> + * input value. Value is matching if it is equal or higher than >> given value >> + * If given value is found to be in a range scanning is stopped and >> @found is >> + * set true. If a range with values greater than given value is found >> + * but the range min is being greater than given value, then the >> range's >> + * lowest selector is updated to @selector and scanning is stopped. > > Is there a reason why the scanning is stopped here? What ensures that > the rest of the ranges wouldn't contain a better match? > > The logic is now different from the > linear_range_get_selector_low_array(), and I would like to understand > why? It'd be nice if these APIs were 'symmetric' to avoid confusion. > Hence, I would like to know rationale behind making them different. The rationale for this being asymmetric is to find the tightest upper bound for `value` < minimum value across the linear range array. To better illustrate this with an example. I have 2 entries in the linear range array [ [4, 8], [11, 15] ]. Let's assume I pass a value of "2". Based on my current approach, the call to get_selector_high() would successfully return with `found`=false and a selector value corresponding to "4". However, if I continued to search, I would end up the selector corresponding to "11". A selector corresponding to "4" is much closer/tighter than "2". For values higher than the highest value in any range, this would keep iterating and end up returning an -EINVAL. For in range values this would work as expected. This implementation assumes that the linear ranges are provided in sorted order, an assumption that I believe already underlies the existing *_low_array() logic. Regards, Amit > >> + * >> + * Return: 0 on success, -EINVAL if range array is invalid or does >> not contain >> + * range with a value greater or equal to given value >> + */ >> +int linear_range_get_selector_high_array(const struct linear_range *r, >> +                     int ranges, unsigned int val, >> +                     unsigned int *selector, bool *found) >> +{ >> +    int i; >> +    int ret; >> + >> +    for (i = 0; i < ranges; i++) { >> +        ret = linear_range_get_selector_high(&r[i], val, selector, >> +                             found); >> +        if (!ret) >> +            return 0; >> +    } >> + >> +    return -EINVAL; >> +} >> +EXPORT_SYMBOL_GPL(linear_range_get_selector_high_array); >> + >>   /** >>    * linear_range_get_selector_within - return linear range selector >> for value >>    * @r:        pointer to linear range where selector is looked from >> > >