From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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 AD7DC30C36D for ; Wed, 18 Feb 2026 08:17:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771402632; cv=none; b=BenRJ80AyVwkSy47Q6hBZW4jblpwAHSc2PQXPr/OqV5m4GHhG7qAq/zomc+gXMWmOZkIobCw3abBJJmoE9Iw8eDw6SNE1ILhxGK1KQl8XGp2hMP1J8eJFXhupxtTbc6EZwP6TL57Mvk/BBBgdgysX/kSI/0dqWpNTLIysbJ8vLY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771402632; c=relaxed/simple; bh=9moeBSWAnG3dtSIbdW4ZnD0x20PyiAy3DOWv8ETJgx0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=qrJaSA02COdny5mHB+EdbCwvfriFMK86MKH81DAazNZ0FVjRW7cHNaqnCC/vGuasBbq08w+jvq+gDkhyC7/mWv+hjg8MEnf+F36jDIcVvh4+A5zAuXazmremCL8q9x1SGpCTZD7pIbD1r8eolsQ52w+u/LvDNMfUFH0V7puc3tI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nTx7qOme; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nTx7qOme" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-59de2d1fc2cso5568733e87.2 for ; Wed, 18 Feb 2026 00:17:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771402629; x=1772007429; 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=5r0xdr1WGpCeGTUqLANRfTri1dCqx5zok5lpbzySRko=; b=nTx7qOmeum236BXFrq/lI95npYcbZdRkmrsYpw6z44rQeeD2T//+MtGlF4miv5w2A3 973XqBQSOtxZaws0YxAmu+XEEJNfeGXkBlZFU5Z+lKYprZhMNfCc/i0gIofqZCTjnUn/ vVKH4KurYSpHbro3gpWg8JEiIu6tPOrKkEyhgu0fVuyXnNMQTtY8kYWz6F7X002VpCx0 VI0Gq1zYb0an31wBKti3j8ihdTIBaDKT6QjtbmQjIBr8z4GPRYyxbPS6qdw/kdbxdOWb Xmwf48ZWRjNGLbJS23hhX4iX20jPRH8xdAg3+1VlzLeqSvVxnb/78oDeP5vADrvsirma BKzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771402629; x=1772007429; 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=5r0xdr1WGpCeGTUqLANRfTri1dCqx5zok5lpbzySRko=; b=h96/WHFxAy963y3Km670gdNrV6lhd7AM5CjBXp3Cn/g5Osc7yrY0oa+4u3jCq8cLGS cIIuFb83eHRDu6VjHyplH8ikmqIr9l6gRCz74GA+mrRX3Z1GgaIjxp816AEyyM7iVC3W ltAo0RD6k7BldULby65faNAXqsrRuvOqL37DFeUeR4LGdn+jcL7/aWy8A6RX1uu1LDP5 pfTBhSU5zug42pfRpOGWqm9fI59JzfOFWeAR1TEyuyddVOkAshLYOmXnvEKJJIUDjZiW vtDqKhOCzm7VYHupHkPcdLLmDmz/nOQmV2GVx+M0qXsW1utXl7dt3I9YV9VOTuHjPI5s u99w== X-Gm-Message-State: AOJu0YxwjJA24J7V4Te5j0dlJuH/b+0SmgxtPgyH/rlkLCIba/9ZJXhX MkkkZT5vLORo++gPhuBIA6R1HLwlwTiUXVnvliXrAWT6B4vdblGOaf8U X-Gm-Gg: AZuq6aJ3zfQn4EtCi5RhWFUjEByv6HM6WgK5sQ9a2EVtzCxlnGR+BzTUKKw1W1t2g0W Et7C/wMl2LFsu2iFLSY0Gh5HIWtH7WyBlC4tRtzIQtlq70WHHcbayFkrIEuefYzBXyZkA2FeHB/ ORkfidh1lL/0oFXNvivrU05H7Cho66kyt6xagAfRBp0jlr56fzjhBJeu9DoDR5eTDkvcWZ/tEAs dPFFDQpp21mFj3t8skPdWQ8AFP8KNuH7fbL2nb/q6nGL+fz9rXmFl8S8/V3e3IfXNT3yd89TFa7 y5cRMsklSdBYIyOkhXMYqzqvCxQakd7ew3ltXnPGaLk7f8D493q+XhHLKEWRAWZLGT0dT5v36x9 6A1J6RXJxNiXgV/RuGnuB0CzYfmiEADfZ7rTbUbESJ3sFxbNiPpDIXqy6VuCe7GpTDp7eF64Ii+ SPh0t+6mp7jDO/qAPr/N7YuUQi9SzBn4EnJdpl7MfRz5XtCIHdNz/x4ck6gO2rAAMTVI+MWAe1W F6gmpVtdXWXCdxiVS8= X-Received: by 2002:a05:6512:1150:b0:59e:6c24:3f91 with SMTP id 2adb3069b0e04-59f83bbcd19mr369556e87.34.1771402628519; Wed, 18 Feb 2026 00:17:08 -0800 (PST) Received: from ?IPV6:2a10:a5c0:800d:dd00:8fdf:935a:2c85:d703? ([2a10:a5c0:800d:dd00:8fdf:935a:2c85:d703]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59e5f56867fsm4391846e87.24.2026.02.18.00.17.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Feb 2026 00:17:07 -0800 (PST) Message-ID: <66dab64b-ca3e-4ae0-81d6-0500899757e5@gmail.com> Date: Wed, 18 Feb 2026 10:17:06 +0200 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: Amit Sunil Dhamne , 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, en-AU, en-GB, en-BW From: Matti Vaittinen In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 18/02/2026 03:45, Amit Sunil Dhamne wrote: > > 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 // snip >>> --- 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. Ah. I think ... I didn't think. :) It definitely makes sense to stop scanning if the range_min already was greater than the given target value. Thanks for the patience and for adding this missing piece :) Reviewed-by: Matti Vaittinen --- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~