git: 3e0270c52875 - stable/15 - kern: osd: abstract away the math for locating a slot method

Kyle Evans <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a75395a.3be07.189c82dd__32445.0294299581$1786067372$gmane$org@gitrepo.freebsd.org>
The branch stable/15 has been updated by kevans:

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

commit 3e0270c52875faefad6ddce7285f8c8047d423ef
Author:     Kyle Evans <[email protected]>
AuthorDate: 2026-06-25 03:08:05 +0000
Commit:     Kyle Evans <[email protected]>
CommitDate: 2026-08-06 23:35:54 +0000

    kern: osd: abstract away the math for locating a slot method
    
    It's relatively simple, but we'll do it a couple of times; pull it
    out into a macro.
    
    Reviewed by:    imp (previous version), jamie
    
    (cherry picked from commit 72ebcfae48c42cb28ab6142980416082f8d70abc)
---
 sys/kern/kern_osd.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/sys/kern/kern_osd.c b/sys/kern/kern_osd.c
index 93809ccab8e5..b64735e7f93a 100644
--- a/sys/kern/kern_osd.c
+++ b/sys/kern/kern_osd.c
@@ -73,6 +73,9 @@ SYSCTL_INT(_debug, OID_AUTO, osd, CTLFLAG_RWTUN, &osd_debug, 0, "OSD debug level
 	}								\
 } while (0)
 
+#define	OSD_METHOD(osdm, slot, method)	\
+    ((osdm).osd_methods[((slot) - 1) * (osdm).osd_nmethods + (method)])
+
 static void do_osd_del(u_int type, struct osd *osd, u_int slot,
     int list_locked);
 
@@ -139,8 +142,8 @@ osd_register(u_int type, osd_destructor_t destructor, const osd_method_t *method
 	osdm[type].osd_destructors[i] = destructor;
 	if (osdm[type].osd_nmethods != 0) {
 		for (m = 0; m < osdm[type].osd_nmethods; m++)
-			osdm[type].osd_methods[i * osdm[type].osd_nmethods + m]
-			    = methods != NULL ? methods[m] : NULL;
+			OSD_METHOD(osdm[type], i + 1, m) =
+			    methods != NULL ? methods[m] : NULL;
 	}
 	sx_xunlock(&osdm[type].osd_module_lock);
 	return (i + 1);
@@ -391,8 +394,7 @@ osd_call(u_int type, u_int method, void *obj, void *data)
 		/* Hole in the slot map; avoid dereferencing. */
 		if (osdm[type].osd_destructors[i] == NULL)
 			continue;
-		methodfun = osdm[type].osd_methods[i * osdm[type].osd_nmethods +
-		    method];
+		methodfun = OSD_METHOD(osdm[type], i + 1, method);
 		if (methodfun != NULL && (error = methodfun(obj, data)) != 0)
 			break;
 	}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.