From nobody Thu Apr 2 23:55:27 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A50729AB02; Sat, 14 Feb 2026 03:13:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771038831; cv=none; b=lSx0Y6COwEjifdF4PqjapshPBfj4BLafbzGZ2LyzzFBDdPmspAyCvC8ugGBqou/vA6wQG63o8yiZVmTez1d1wuPirDkjb9WgSlntADRxguwDl3GDa8/dZByRuhKeLn6wY+QrmXRg8XQJvX5dvf2P9VKVx1VIYjaJisL8HhnAku0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771038831; c=relaxed/simple; bh=NEX6wiIU0Pu9wCjwqFxlx1o3cZBcQ0jou3x+WtZcdW8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RFg0VZylwRHchdIE7xV2le0awo1GE4NIns02nI22FYc/daaZrUpCuI1P8whg4dutxtmY8zvtlhw6mRPhcPF5/ZcdZx482HE3qQR8Kfztq/u6+BVHFXMXgaf+ZjnFtuX7aQh1lKS9TvamIiOYUJsftzk6LTlxktIZOSYhNTYQU04= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dVCGP2zC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dVCGP2zC" Received: by smtp.kernel.org (Postfix) with ESMTPS id 4E4FFC2BC87; Sat, 14 Feb 2026 03:13:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771038831; bh=NEX6wiIU0Pu9wCjwqFxlx1o3cZBcQ0jou3x+WtZcdW8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=dVCGP2zCdcB6PXkidzvipJQ6CUz6bJC6P9hxkFXeTeSHZTAU1pC191aCORag5yFyP I49idaudZK6rL3mZZXsV1E3hRHmny0QS/cQ7Pdh54X0yahMTz+RUxhw64nRS6z1mc/ mA3puT8Oh1vR3NZN1tHGDlwZCDmJCyDFc58dL1CgbKZe6qGu94Rs90/UVUxNanmix0 1tttebO7VxJ4IO5shGn9R3aWe+ANxAZN95hC6izfYSRJMmr+MAujkjGYfqCzICAzBi ibvz5ZW6zjer+gl2vnTAjOGeNtLfcfjXASwgndZ22OApp7EyNFsf340lDnRVr5DYGB z5nDFj+EG3vbw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40659EF99F3; Sat, 14 Feb 2026 03:13:51 +0000 (UTC) From: Amit Sunil Dhamne via B4 Relay Date: Sat, 14 Feb 2026 03:12:40 +0000 Subject: [PATCH v6 4/6] lib/linear_ranges: Add linear_range_get_selector_high_array Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260214-max77759-charger-v6-4-28c09bda74b4@google.com> References: <20260214-max77759-charger-v6-0-28c09bda74b4@google.com> In-Reply-To: <20260214-max77759-charger-v6-0-28c09bda74b4@google.com> To: 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 , Matti Vaittinen , 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 , Amit Sunil Dhamne X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1771038829; l=2903; i=amitsd@google.com; s=20241031; h=from:subject:message-id; bh=h/h1RxmtgZ8cYlZDWufw7EoQID32BVVp1LlJ3v3N0UU=; b=RVqxcTavOqnvmDC5ffcWhKUukC/ahcX0DQO5rw03LALrucXeDLBYkxAEg+hEcEboMceLw4SAc WG0Fyb3J9GkAbqMzD2j6nYgzqrXSpj7uRZpj2I4/Dw837V1NXtKMAJZ X-Developer-Key: i=amitsd@google.com; a=ed25519; pk=wD+XZSST4dmnNZf62/lqJpLm7fiyT8iv462zmQ3H6bI= X-Endpoint-Received: by B4 Relay for amitsd@google.com/20241031 with auth_id=262 X-Original-From: Amit Sunil Dhamne Reply-To: amitsd@google.com 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 Reviewed-by: Matti Vaittinen --- 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); =20 #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); =20 +/** + * 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. + * + * Return: 0 on success, -EINVAL if range array is invalid or does not con= tain + * 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 =3D 0; i < ranges; i++) { + ret =3D 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 val= ue * @r: pointer to linear range where selector is looked from --=20 2.53.0.273.g2a3d683680-goog