Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F149810121
D53918.id167169.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D53918.id167169.diff
View Options
diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile
--- a/share/man/man9/Makefile
+++ b/share/man/man9/Makefile
@@ -1040,6 +1040,7 @@
MLINKS+=device_add_child.9 device_add_child_ordered.9
MLINKS+=device_enable.9 device_disable.9 \
device_enable.9 device_is_enabled.9
+MLINKS+=device_get_children.9 device_has_children.9
MLINKS+=device_get_ivars.9 device_set_ivars.9
MLINKS+=device_get_name.9 device_get_nameunit.9
MLINKS+=device_get_state.9 device_busy.9 \
diff --git a/share/man/man9/device_get_children.9 b/share/man/man9/device_get_children.9
--- a/share/man/man9/device_get_children.9
+++ b/share/man/man9/device_get_children.9
@@ -1,6 +1,7 @@
.\" -*- nroff -*-
.\"
.\" Copyright (c) 1998 Doug Rabson
+.\" Copyright (c) 2025 Dag-Erling Smørgrav <des@FreeBSD.org>
.\"
.\" All rights reserved.
.\"
@@ -26,21 +27,27 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd August 23, 2008
+.Dd November 26, 2025
.Dt DEVICE_GET_CHILDREN 9
.Os
.Sh NAME
-.Nm device_get_children
-.Nd get a list of devices connected to a device
+.Nm device_get_children ,
+.Nm device_has_children
+.Nd examine devices connected to a device
.Sh SYNOPSIS
.In sys/param.h
.In sys/bus.h
.Ft int
.Fn device_get_children "device_t dev" "device_t **devlistp" "int *devcountp"
+.Ft bool
+.Fn device_has_children "device_t dev"
.Sh DESCRIPTION
-Retrieve a list of all device instances currently connected to
-.Pa dev
-and return the list in
+The
+.Nm device_get_children
+function retrieves a list of all device instances currently connected
+to
+.Fa dev .
+It returns the list in
.Fa *devlistp
and the count in
.Fa *devcountp .
@@ -50,11 +57,35 @@
and
.Fa devcountp
are not changed when an error is returned.
+.Pp
+As a special case, if
+.Fa devlistp
+is null, no memory is allocated but the count is still returned in
+.Fa *devcountp .
+.Pp
+The
+.Nm device_has_children
+function returns
+.Dv true
+if
+.Fa dev
+has at least one child and
+.Dv false
+if does not have any.
.Sh RETURN VALUES
-Zero is returned on success, otherwise an appropriate error is returned.
+The
+.Nm device_get_children
+function returns zero on success and an appropriate error otherwise.
+The
+.Nm device_has_children
+function returns true if the specified device has at least one child
+and false otherwise.
.Sh SEE ALSO
.Xr devclass 9 ,
.Xr device 9
.Sh AUTHORS
+.An -nosplit
This manual page was written by
-.An Doug Rabson .
+.An Doug Rabson Aq Mt dfr@FreeBSD.org
+and
+.An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org .
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -1831,6 +1831,20 @@
return (dev->parent);
}
+/**
+ * @brief Check if a device has children
+ *
+ * @param dev the device to examine
+ *
+ * @rerval true the device has at least one child
+ * @retval false the device has no children
+ */
+bool
+device_has_children(device_t dev)
+{
+ return (!TAILQ_EMPTY(&dev->children));
+}
+
/**
* @brief Get a list of children of a device
*
@@ -1858,6 +1872,10 @@
TAILQ_FOREACH(child, &dev->children, link) {
count++;
}
+ if (devlistp == NULL) {
+ *devcountp = count;
+ return (0);
+ }
if (count == 0) {
*devlistp = NULL;
*devcountp = 0;
diff --git a/sys/sys/bus.h b/sys/sys/bus.h
--- a/sys/sys/bus.h
+++ b/sys/sys/bus.h
@@ -703,6 +703,7 @@
driver_t *device_get_driver(device_t dev);
u_int32_t device_get_flags(device_t dev);
device_t device_get_parent(device_t dev);
+bool device_has_children(device_t dev);
int device_get_children(device_t dev, device_t **listp, int *countp);
void *device_get_ivars(device_t dev);
void device_set_ivars(device_t dev, void *ivars);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 28, 6:44 AM (15 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30461953
Default Alt Text
D53918.id167169.diff (3 KB)
Attached To
Mode
D53918: bus: Add device_has_children predicate
Attached
Detach File
Event Timeline
Log In to Comment