All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yassine Oudjana <yassine.oudjana@gmail.com>
To: Sebastian Reichel <sre@kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Andy Gross <agross@kernel.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Yassine Oudjana <y.oudjana@protonmail.com>,
	Yassine Oudjana <yassine.oudjana@gmail.com>,
	Alejandro Tafalla <atafalla@dnyon.com>,
	Konrad Dybcio <konrad.dybcio@somainline.org>,
	linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	devicetree@vger.kernel.org, phone-devel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 7/8] util_macros.h: Add macro to find closest smaller value in array
Date: Mon,  8 Aug 2022 08:34:58 +0100	[thread overview]
Message-ID: <20220808073459.396278-8-y.oudjana@protonmail.com> (raw)
In-Reply-To: <20220808073459.396278-1-y.oudjana@protonmail.com>

From: Yassine Oudjana <y.oudjana@protonmail.com>

Add a macro to find the value closest to but smaller than a given
value in an array.

Signed-off-by: Yassine Oudjana <y.oudjana@protonmail.com>
---
 include/linux/util_macros.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/include/linux/util_macros.h b/include/linux/util_macros.h
index 72299f261b25..ad0020e7932b 100644
--- a/include/linux/util_macros.h
+++ b/include/linux/util_macros.h
@@ -38,4 +38,26 @@
  */
 #define find_closest_descending(x, a, as) __find_closest(x, a, as, >=)
 
+/**
+ * find_closest_smaller - locate the closest smaller element in a sorted array
+ * @x: The reference value.
+ * @a: The array in which to look for the closest smaller element. Must be
+ *  sorted in ascending order.
+ * @as: Size of 'a'.
+ *
+ * Returns the index of the element closest to and smaller than 'x', or -1
+ * if no element smaller than 'x' exists in the array.
+ */
+#define find_closest_smaller(x, a, as)					\
+({									\
+	typeof(as) __fcs_i;						\
+	typeof(x) __fcs_x = (x);					\
+	typeof(*a) const *__fcs_a = (a);				\
+	for (__fcs_i = 0; __fcs_i < (as); __fcs_i++) {			\
+		if (__fcs_x < __fcs_a[__fcs_i])				\
+			break;						\
+	}								\
+	(__fcs_i - 1);							\
+})
+
 #endif
-- 
2.37.1


  parent reply	other threads:[~2022-08-08  7:37 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-08  7:34 [PATCH 0/8] power: supply: Add driver for Qualcomm SMBCHG Yassine Oudjana
2022-08-08  7:34 ` [PATCH 1/8] dt-bindings: power: supply: Add DT schema " Yassine Oudjana
2022-08-08  8:42   ` Krzysztof Kozlowski
2022-11-20 15:46     ` Yassine Oudjana
2022-11-21  8:26       ` Krzysztof Kozlowski
2022-11-21 10:36         ` Yassine Oudjana
2022-11-21 17:07           ` Krzysztof Kozlowski
2022-11-22 13:30             ` Dmitry Baryshkov
2022-11-28 11:39               ` Krzysztof Kozlowski
2022-11-28 11:52                 ` Dmitry Baryshkov
2022-11-30 16:24   ` Krzysztof Kozlowski
2022-08-08  7:34 ` [PATCH 2/8] arm64: dts: qcom: pmi8994: Add SMBCHG Yassine Oudjana
2022-08-08  7:34 ` [PATCH 3/8] arm64: dts: qcom: pmi8996: " Yassine Oudjana
2022-08-08  7:34 ` [PATCH 5/8] arm64: dts: qcom: msm8996-xiaomi-*: Enable SMBCHG Yassine Oudjana
2022-08-08  7:34 ` [PATCH 6/8] soc: qcom: Add PMIC secure register write helpers Yassine Oudjana
2022-08-08  7:34 ` Yassine Oudjana [this message]
2022-08-08  7:34 ` [PATCH 8/8] power: supply: Add driver for Qualcomm SMBCHG Yassine Oudjana
2022-08-08  8:55   ` Krzysztof Kozlowski
2022-08-08 10:05     ` Yassine Oudjana
2022-08-08 13:42       ` Krzysztof Kozlowski
2022-08-08  8:41 ` [PATCH 0/8] " Krzysztof Kozlowski
2022-08-08  9:39   ` Yassine Oudjana
2022-08-08 13:24     ` Caleb Connolly

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220808073459.396278-8-y.oudjana@protonmail.com \
    --to=yassine.oudjana@gmail.com \
    --cc=agross@kernel.org \
    --cc=atafalla@dnyon.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=konrad.dybcio@somainline.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=phone-devel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=sre@kernel.org \
    --cc=y.oudjana@protonmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.