Index: sys/dev/ccd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ccd.c,v
retrieving revision 1.193
diff -p -u -r1.193 ccd.c
--- sys/dev/ccd.c	17 Aug 2025 22:04:34 -0000	1.193
+++ sys/dev/ccd.c	9 Sep 2025 12:53:34 -0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ccd.c,v 1.193 2025/08/17 22:04:34 mlelstv Exp $	*/
+/*	$NetBSD: ccd.c,v 1.192 2025/01/08 08:24:07 andvar Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 1999, 2007, 2009 The NetBSD Foundation, Inc.
@@ -88,7 +88,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.193 2025/08/17 22:04:34 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.192 2025/01/08 08:24:07 andvar Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1751,17 +1751,17 @@ ccd_units_sysctl(SYSCTLFN_ARGS)
 		LIST_FOREACH(sc, &ccds, sc_link) {
 			if (i >= nccd)
 				break;
-			units[i] = sc->sc_unit;
+			units[i++] = sc->sc_unit;
 		}
+		nccd = i;
 		mutex_exit(&ccd_lock);
 	} else {
 		units = NULL;
-		size = 0;
 	}
 
 	node = *rnode;
 	node.sysctl_data = units;
-	node.sysctl_size = size;
+	node.sysctl_size = nccd * sizeof(*units);
 
 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
 	if (units)
@@ -1777,12 +1777,14 @@ ccd_info_sysctl(SYSCTLFN_ARGS)
 	struct ccd_softc *sc;
 	int unit, error;
 
-	if (newp == NULL || newlen != sizeof(int))
+	if (newp == NULL || newlen != sizeof(unit))
 		return EINVAL;
 
 	error = sysctl_copyin(l, newp, &unit, sizeof unit);
 	if (error)
 		return error;
+	newp = NULL;
+
 	newlen = 0;
 	ccd.ccd_ndisks = ~0;
 	mutex_enter(&ccd_lock);
@@ -1816,13 +1818,15 @@ ccd_components_sysctl(SYSCTLFN_ARGS)
 	char *names, *p, *ep;
 	struct ccd_softc *sc;
 
-	if (newp == NULL || newlen != sizeof(int))
+	if (newp == NULL || newlen != sizeof(unit))
 		return EINVAL;
 
 	size = 0;
-	error = sysctl_copyin(l, newp, &unit, sizeof unit);
+	error = sysctl_copyin(l, newp, &unit, sizeof(unit));
 	if (error)
 		return error;
+	newp = NULL;
+
 	newlen = 0;
 	mutex_enter(&ccd_lock);
 	LIST_FOREACH(sc, &ccds, sc_link)
