[PATCH v3 01/13] common/rc: Add _min() and _max() helpers

Ojaswin Mujoo posted 13 patches 2 months, 3 weeks ago
There is a newer version of this series
[PATCH v3 01/13] common/rc: Add _min() and _max() helpers
Posted by Ojaswin Mujoo 2 months, 3 weeks ago
Many programs open code these functionalities so add it as a generic helper
in common/rc

Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
---
 common/rc | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/common/rc b/common/rc
index f71cc8f0..9a9d3cc8 100644
--- a/common/rc
+++ b/common/rc
@@ -5817,6 +5817,28 @@ _require_program() {
 	_have_program "$1" || _notrun "$tag required"
 }
 
+_min() {
+	local ret
+
+	for arg in "$@"; do
+		if [ -z "$ret" ] || (( $arg < $ret )); then
+			ret="$arg"
+		fi
+	done
+	echo $ret
+}
+
+_max() {
+	local ret
+
+	for arg in "$@"; do
+		if [ -z "$ret" ] || (( $arg > $ret )); then
+			ret="$arg"
+		fi
+	done
+	echo $ret
+}
+
 ################################################################################
 # make sure this script returns success
 /bin/true
-- 
2.49.0
Re: [PATCH v3 01/13] common/rc: Add _min() and _max() helpers
Posted by Darrick J. Wong 2 months, 3 weeks ago
On Sat, Jul 12, 2025 at 07:42:43PM +0530, Ojaswin Mujoo wrote:
> Many programs open code these functionalities so add it as a generic helper
> in common/rc
> 
> Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>

Looks decent,
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> ---
>  common/rc | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/common/rc b/common/rc
> index f71cc8f0..9a9d3cc8 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -5817,6 +5817,28 @@ _require_program() {
>  	_have_program "$1" || _notrun "$tag required"
>  }
>  
> +_min() {
> +	local ret
> +
> +	for arg in "$@"; do
> +		if [ -z "$ret" ] || (( $arg < $ret )); then
> +			ret="$arg"
> +		fi
> +	done
> +	echo $ret
> +}
> +
> +_max() {
> +	local ret
> +
> +	for arg in "$@"; do
> +		if [ -z "$ret" ] || (( $arg > $ret )); then
> +			ret="$arg"
> +		fi
> +	done
> +	echo $ret
> +}
> +
>  ################################################################################
>  # make sure this script returns success
>  /bin/true
> -- 
> 2.49.0
> 
>