Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Feb 2024 21:33:03 GMT
From:      Vladimir Kondratyev <wulf@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: fcfc3fe00d32 - stable/14 - LinuxKPI: Add ida_alloc_min()
Message-ID:  <202402172133.41HLX3tH020905@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=fcfc3fe00d32c6beb228a13294c8e8288a776ad0

commit fcfc3fe00d32c6beb228a13294c8e8288a776ad0
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2023-12-24 08:19:59 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2024-02-17 20:58:38 +0000

    LinuxKPI: Add ida_alloc_min()
    
    ida_alloc_min() allocates an unused ID. between min and INT_MAX.
    
    While here allow end parameter of ida_simple_get() be larger than
    INT_MAX. Linux caps the value to INT_MAX.
    
    Sponsored by:   Serenity Cyber Security, LLC
    Reviewers:      manu, bz
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D42806
    
    (cherry picked from commit c7312643b7e5f01adc2a3094c5139f5dcab5f0a4)
---
 sys/compat/linuxkpi/common/include/linux/idr.h | 7 +++++++
 sys/compat/linuxkpi/common/src/linux_idr.c     | 5 ++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/idr.h b/sys/compat/linuxkpi/common/include/linux/idr.h
index 2fb2e1734878..ca3f8171ff44 100644
--- a/sys/compat/linuxkpi/common/include/linux/idr.h
+++ b/sys/compat/linuxkpi/common/include/linux/idr.h
@@ -31,6 +31,7 @@
 
 #include <sys/param.h>
 #include <sys/lock.h>
+#include <sys/limits.h>
 #include <sys/mutex.h>
 
 #include <linux/types.h>
@@ -131,6 +132,12 @@ ida_get_new(struct ida *ida, int *p_id)
 	return (ida_get_new_above(ida, 0, p_id));
 }
 
+static inline int
+ida_alloc_min(struct ida *ida, unsigned int min, gfp_t gfp)
+{
+	return (ida_simple_get(ida, min, UINT_MAX, gfp));
+}
+
 static inline int
 ida_alloc_max(struct ida *ida, unsigned int max, gfp_t gfp)
 {
diff --git a/sys/compat/linuxkpi/common/src/linux_idr.c b/sys/compat/linuxkpi/common/src/linux_idr.c
index a484a16e2862..657d85606f50 100644
--- a/sys/compat/linuxkpi/common/src/linux_idr.c
+++ b/sys/compat/linuxkpi/common/src/linux_idr.c
@@ -755,10 +755,9 @@ ida_simple_get(struct ida *ida, unsigned int start, unsigned int end,
 	unsigned int max;
 
 	MPASS((int)start >= 0);
-	MPASS((int)end >= 0);
 
-	if (end == 0)
-		max = 0x80000000;
+	if ((int)end <= 0)
+		max = INT_MAX;
 	else {
 		MPASS(end > start);
 		max = end - 1;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202402172133.41HLX3tH020905>