git: 3083db58304d - stable/12 - random(4): Use ordinary sysctl definitions

From: David E. O'Brien <obrien_at_FreeBSD.org>
Date: Tue, 15 Feb 2022 21:16:27 UTC
The branch stable/12 has been updated by obrien:

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

commit 3083db58304d20ad2f9f613587bb9d9efa0542af
Author:     Conrad Meyer <cem@FreeBSD.org>
AuthorDate: 2019-11-22 20:22:29 +0000
Commit:     David E. O'Brien <obrien@FreeBSD.org>
CommitDate: 2022-02-15 20:18:57 +0000

    random(4): Use ordinary sysctl definitions
    
    There's no need to dynamically populate them; the SYSCTL_ macros take care
    of load/unload appropriately already (and random_harvestq is 'standard' and
    cannot be unloaded anyway).
    
    (cherry picked from commit d7a23f9f6b0d9757116de63a58032f29d3bc02a4)
---
 sys/dev/random/random_harvestq.c | 34 +++++++++++-----------------------
 1 file changed, 11 insertions(+), 23 deletions(-)

diff --git a/sys/dev/random/random_harvestq.c b/sys/dev/random/random_harvestq.c
index f09056aa9424..0c6777ba9d0d 100644
--- a/sys/dev/random/random_harvestq.c
+++ b/sys/dev/random/random_harvestq.c
@@ -69,9 +69,6 @@ static void random_sources_feed(void);
 
 static u_int read_rate;
 
-/* List for the dynamic sysctls */
-static struct sysctl_ctx_list random_clist;
-
 /*
  * How many events to queue up. We create this many items in
  * an 'empty' queue, then transfer them to the 'harvest' queue with
@@ -90,6 +87,9 @@ volatile int random_kthread_control;
  */
 __read_frequently u_int hc_source_mask;
 
+SYSCTL_NODE(_kern_random, OID_AUTO, harvest, CTLFLAG_RW, 0,
+    "Entropy Device Parameters");
+
 /*
  * Put all the harvest queue context stuff in one place.
  * this make is a bit easier to lock and protect.
@@ -273,6 +273,8 @@ random_check_uint_harvestmask(SYSCTL_HANDLER_ARGS)
 	    (orig_value & RANDOM_HARVEST_PURE_MASK);
 	return (0);
 }
+SYSCTL_PROC(_kern_random_harvest, OID_AUTO, mask, CTLTYPE_UINT | CTLFLAG_RW,
+    NULL, 0, random_check_uint_harvestmask, "IU", "Entropy harvesting mask");
 
 /* ARGSUSED */
 static int
@@ -291,6 +293,9 @@ random_print_harvestmask(SYSCTL_HANDLER_ARGS)
 	}
 	return (error);
 }
+SYSCTL_PROC(_kern_random_harvest, OID_AUTO, mask_bin,
+    CTLTYPE_STRING | CTLFLAG_RD, NULL, 0, random_print_harvestmask, "A",
+    "Entropy harvesting mask (printable)");
 
 static const char *random_source_descr[ENTROPYSOURCE] = {
 	[RANDOM_CACHED] = "CACHED",
@@ -348,31 +353,15 @@ random_print_harvestmask_symbolic(SYSCTL_HANDLER_ARGS)
 	}
 	return (error);
 }
+SYSCTL_PROC(_kern_random_harvest, OID_AUTO, mask_symbolic,
+    CTLTYPE_STRING | CTLFLAG_RD, NULL, 0, random_print_harvestmask_symbolic,
+    "A", "Entropy harvesting mask (symbolic)");
 
 /* ARGSUSED */
 static void
 random_harvestq_init(void *unused __unused)
 {
-	struct sysctl_oid *random_sys_o;
-
-	random_sys_o = SYSCTL_ADD_NODE(&random_clist,
-	    SYSCTL_STATIC_CHILDREN(_kern_random),
-	    OID_AUTO, "harvest", CTLFLAG_RW, 0,
-	    "Entropy Device Parameters");
 	hc_source_mask = RANDOM_HARVEST_EVERYTHING_MASK;
-	SYSCTL_ADD_PROC(&random_clist,
-	    SYSCTL_CHILDREN(random_sys_o),
-	    OID_AUTO, "mask", CTLTYPE_UINT | CTLFLAG_RW,
-	    NULL, 0, random_check_uint_harvestmask, "IU",
-	    "Entropy harvesting mask");
-	SYSCTL_ADD_PROC(&random_clist,
-	    SYSCTL_CHILDREN(random_sys_o),
-	    OID_AUTO, "mask_bin", CTLTYPE_STRING | CTLFLAG_RD,
-	    NULL, 0, random_print_harvestmask, "A", "Entropy harvesting mask (printable)");
-	SYSCTL_ADD_PROC(&random_clist,
-	    SYSCTL_CHILDREN(random_sys_o),
-	    OID_AUTO, "mask_symbolic", CTLTYPE_STRING | CTLFLAG_RD,
-	    NULL, 0, random_print_harvestmask_symbolic, "A", "Entropy harvesting mask (symbolic)");
 	RANDOM_HARVEST_INIT_LOCK();
 	harvest_context.hc_entropy_ring.in = harvest_context.hc_entropy_ring.out = 0;
 }
@@ -464,7 +453,6 @@ random_harvestq_deinit(void *unused __unused)
 	random_kthread_control = 0;
 	while (random_kthread_control >= 0)
 		tsleep(&harvest_context.hc_kthread_proc, 0, "harvqterm", hz/5);
-	sysctl_ctx_free(&random_clist);
 }
 SYSUNINIT(random_device_h_init, SI_SUB_RANDOM, SI_ORDER_SECOND, random_harvestq_deinit, NULL);