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 38FFA2FFF98 for ; Mon, 16 Feb 2026 13:58:33 +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=1771250315; cv=none; b=Mo5Q0l0N5+Vx8gTbDiGx/plkqMIlwxPGT/nOS0VmuGeBf6FvQoHJ8bGyt7xEFfCg9BBvmLQl7vL+unHk0eQg8j67j+nFIL/JPO+E1tp9sLpAIaI41X4hnJg2FGw5xatBHmmmuRCnrueK6KH0pmlAtCEVfikQJo2wA/Q7Z0dPjGY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771250315; c=relaxed/simple; bh=JudCYDKTAao9yvz1obQeEFLjpJHRjDhkH80IAq3x6uY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=PB/lL7FO1zsGpsfI4jzJoh3ttaBS2Xcp26I2AYVADXuIqWkqKCKcggLl6yTuO0huZyZ2j8t9k/ovkGen4ENMD626AXnZYn1LY6BpktPgMuvunQS7z0bedbIUO2E2QACmVhuMWgleW/LF0EAlJsDv7xqk2OY2PJ/I8ZM8WdCnlgU= 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=Orl3VpCZ; 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="Orl3VpCZ" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-59e6b7b11ebso3553305e87.3 for ; Mon, 16 Feb 2026 05:58:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771250311; x=1771855111; 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=rUcAGLQZkv/PTBs//eYKKwXahaszOterbl1vVyU8vuo=; b=Orl3VpCZVgtxL7MpZh1NnWlx2fyQTWtrIKVH6nsudChRBkNWr52BLzHjewFb5rb7pN HubWuhvIET2AZmou4zCDw210uFqVfcuH209nQuWT3wKo318bb2jWFzmRN/mplBEPQE8O J+AIN3NaN0Tyy9367E9yuKF9bus9tUPDTIZVEsmksjb4WnpF/G1Q6B4JMeRi9E5WLate q1jCL8jtPY1PynwXqrTlDx2HbtzBgR4zc9qSYs8WuWL7bF8b7h/EEXOsuyGuaeRpsLOu 5XTN/OIYNYSllIFsYDHuOGlAVo/ZU5fCcjorQnbtIoLnkcJcu064QyRdIVbpiPGBhK5B IknQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771250311; x=1771855111; 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=rUcAGLQZkv/PTBs//eYKKwXahaszOterbl1vVyU8vuo=; b=a6XKm8VHU0wNifAVCOTjAqzXAVZ3Eix03jGTwSPaC0vUUY2IQk88xB9Nb9I+i4sWF9 11nZ2P+5zonCrkJKTViHARGB9xNa3tJ9Vu3KDmDZbRgHuBEyoQYlygEoKv8PkwkDT+Hj 1dic6y1kr1sErCYI9eUh0770GddDWs8qJ4r15YEoZP6u90kNBb0KGygr6rAltwQT0bGl V2pKrDSztFSX2Ktb4NdWleL79ZYZYKapsHPE0GL+ymlOGOoH5DlfKbd2YPbLj4iuNVWN jC2RecjNgkip8lnx3GW4cxU96OcthlFXb/ZGTgetqyVR9A1+mKETmszMp76EzE7KYpHM AGUw== X-Gm-Message-State: AOJu0Yxmj+PNJBNUDM7hLob9vA7MDnGfdJ2H+9803ZgqpcuwLfMiB+J0 kqqRjYBk8rVIGcvg40OCVAjRHrJ+8EfelkiFbRJBc+4f+VcgAncSkJ8q X-Gm-Gg: AZuq6aK0O1D50kbQaHpnjv0uatt2Lhx0qLgs1GyNzfvuvUSRQW/uhyQEZbTz7cqQUaC 0dj+uDtoFvab2O56y2Atf4HZQjLOJQriKZmaJKClij7NrJ4G3NF/YKS3M9uo2tDVSSc6aYYTw3J ALEj55EZ2hO5yxrwjg2G6DoLstivPrw0HutZVpp1YexS0Gb1A3ysUZdgFON2ay2Nj8/hhxlot5e dPe+nALjqfzCCw66P7zo3mlHrdrOuMAcjV+g/g1pHZbx0WBwQmDFZSQFYeIb8wG0WLVshUblzh6 LGrWSJciDZ9crUdS/8DJzGNDSnpginPODjBa6fHdxdjIrGaO/SXX9KQFDO6k+Ikm1s2ngJr1+y4 iWG0Jgf6McP42g1HoWAzW7q8bY12ieGz+VZznP5vFcmLNRV+GD3EywSfQDUv+pCn3RRhYO0usEO X6iz6GJXzGA4dTNclKYfhsZxbkxKpD7TseaavGlRsCavA= X-Received: by 2002:a05:6512:145a:10b0:59f:6db3:1526 with SMTP id 2adb3069b0e04-59f6db316f1mr1715840e87.10.1771250311130; Mon, 16 Feb 2026 05:58:31 -0800 (PST) Received: from [10.38.18.54] ([213.255.186.37]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59e5f5b2223sm3224103e87.79.2026.02.16.05.58.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Feb 2026 05:58:30 -0800 (PST) Message-ID: <5d889f66-7697-4a39-beed-33ace693a1ef@gmail.com> Date: Mon, 16 Feb 2026 15:58:28 +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: amitsd@google.com, 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> Content-Language: en-US, en-AU, en-GB, en-BW From: Matti Vaittinen In-Reply-To: <20260214-max77759-charger-v6-4-28c09bda74b4@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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. > + * > + * 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 > -- --- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~