Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F159863275
D53918.id167114.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D53918.id167114.diff
View Options
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
@@ -26,7 +26,7 @@
.\" (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
@@ -39,7 +39,7 @@
.Fn device_get_children "device_t dev" "device_t **devlistp" "int *devcountp"
.Sh DESCRIPTION
Retrieve a list of all device instances currently connected to
-.Pa dev
+.Fa dev
and return the list in
.Fa *devlistp
and the count in
@@ -50,8 +50,23 @@
and
.Fa devcountp
are not changed when an error is returned.
+.Pp
+As a special case, if
+.Fa devlistp
+is null, the number of children is returned in
+.Fa devcountp
+and no list is created.
+If
+.Fa devcountp
+is also null,
+.Nm
+returns non-zero if
+.Fa dev
+has at least one child and zero otherwise.
.Sh RETURN VALUES
-Zero is returned on success, otherwise an appropriate error is returned.
+The
+.Nm
+function returns zero on success and an appropriate error otherwise.
.Sh SEE ALSO
.Xr devclass 9 ,
.Xr device 9
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
@@ -1846,6 +1846,8 @@
*
* @retval 0 success
* @retval ENOMEM the array allocation failed
+ * @retval EFAULT the device has at least one child but devcountp
+ * was null
*/
int
device_get_children(device_t dev, device_t **devlistp, int *devcountp)
@@ -1854,10 +1856,19 @@
device_t child;
device_t *list;
+ if (devcountp == NULL) {
+ if (TAILQ_EMPTY(&dev->children))
+ return (0);
+ return (EFAULT);
+ }
count = 0;
TAILQ_FOREACH(child, &dev->children, link) {
count++;
}
+ if (devlistp == NULL) {
+ *devcountp = count;
+ return (0);
+ }
if (count == 0) {
*devlistp = NULL;
*devcountp = 0;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jun 19, 10:10 PM (14 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34099626
Default Alt Text
D53918.id167114.diff (1 KB)
Attached To
Mode
D53918: bus: Add device_has_children predicate
Attached
Detach File
Event Timeline
Log In to Comment