Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys driver(9): New device_set_private.



details:   https://anonhg.NetBSD.org/src/rev/a537652b89ba
branches:  trunk
changeset: 362580:a537652b89ba
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Mar 03 06:25:46 2022 +0000

description:
driver(9): New device_set_private.

Used to initialize a device_t's private pointer at most once.  Only
for drivers with zero cfattach size so autoconf doesn't preallocate;
KASSERT checks for this mistake.

diffstat:

 sys/kern/subr_device.c |  15 +++++++++++++--
 sys/sys/device.h       |   3 ++-
 2 files changed, 15 insertions(+), 3 deletions(-)

diffs (53 lines):

diff -r 8524071b0400 -r a537652b89ba sys/kern/subr_device.c
--- a/sys/kern/subr_device.c    Thu Mar 03 06:23:25 2022 +0000
+++ b/sys/kern/subr_device.c    Thu Mar 03 06:25:46 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_device.c,v 1.11 2022/01/22 11:58:15 thorpej Exp $ */
+/*     $NetBSD: subr_device.c,v 1.12 2022/03/03 06:25:46 riastradh Exp $       */
 
 /*
  * Copyright (c) 2006, 2021 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_device.c,v 1.11 2022/01/22 11:58:15 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_device.c,v 1.12 2022/03/03 06:25:46 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -278,6 +278,17 @@
        return dev == NULL ? NULL : dev->dv_private;
 }
 
+void
+device_set_private(device_t dev, void *private)
+{
+
+       KASSERTMSG(dev->dv_private == NULL, "device_set_private(%p, %p):"
+           " device %s already has private set to %p",
+           dev, private, device_xname(dev), device_private(dev));
+       KASSERT(private != NULL);
+       dev->dv_private = private;
+}
+
 prop_dictionary_t
 device_properties(device_t dev)
 {
diff -r 8524071b0400 -r a537652b89ba sys/sys/device.h
--- a/sys/sys/device.h  Thu Mar 03 06:23:25 2022 +0000
+++ b/sys/sys/device.h  Thu Mar 03 06:25:46 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.178 2022/01/22 11:58:15 thorpej Exp $ */
+/* $NetBSD: device.h,v 1.179 2022/03/03 06:25:46 riastradh Exp $ */
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -667,6 +667,7 @@
 bool           device_has_power(device_t);
 int            device_locator(device_t, u_int);
 void           *device_private(device_t);
+void           device_set_private(device_t, void *);
 prop_dictionary_t device_properties(device_t);
 void           device_set_handle(device_t, devhandle_t);
 devhandle_t    device_handle(device_t);



Home | Main Index | Thread Index | Old Index