Page MenuHomeFreeBSD

D53918.id167112.diff
No OneTemporary

D53918.id167112.diff

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
@@ -1854,10 +1854,19 @@
device_t child;
device_t *list;
+ if (devcountp == NULL) {
+ if (TAILQ_EMPTY(&dev->children))
+ return (0);
+ return (EADDR);
+ }
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

Mime Type
text/plain
Expires
Sat, Mar 28, 8:23 AM (17 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30465371
Default Alt Text
D53918.id167112.diff (1 KB)

Event Timeline