Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Jun 2021 02:54:39 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: ddfc9c4c59e2 - main - newbus: Move from bus_child_{pnpinfo, location}_src to bus_child_{pnpinfo, location} with sbuf
Message-ID:  <202106230254.15N2sdov081576@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=ddfc9c4c59e2ea4871100d8c076adffe3af8ff21

commit ddfc9c4c59e2ea4871100d8c076adffe3af8ff21
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2021-06-23 02:27:57 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2021-06-23 02:52:06 +0000

    newbus: Move from bus_child_{pnpinfo,location}_src to bus_child_{pnpinfo,location} with sbuf
    
    Now that the upper layers all go through a layer to tie into these
    information functions that translates an sbuf into char * and len. The
    current interface suffers issues of what to do in cases of truncation,
    etc. Instead, migrate all these functions to using struct sbuf and these
    issues go away. The caller is also in charge of any memory allocation
    and/or expansion that's needed during this process.
    
    Create a bus_generic_child_{pnpinfo,location} and make it default. It
    just returns success. This is for those busses that have no information
    for these items. Migrate the now-empty routines to using this as
    appropriate.
    
    Document these new interfaces with man pages, and oversight from before.
    
    Reviewed by:            jhb, bcr
    Sponsored by:           Netflix
    Differential Revision:  https://reviews.freebsd.org/D29937
---
 share/man/man9/BUS_CHILD_LOCATION.9    |  61 ++++++++++++++++++
 share/man/man9/BUS_CHILD_PNPINFO.9     |  65 +++++++++++++++++++
 share/man/man9/Makefile                |   2 +
 sys/arm/allwinner/a10_ahci.c           |   2 +-
 sys/arm/freescale/imx/imx6_ahci.c      |   2 +-
 sys/arm/nvidia/tegra_ahci.c            |   2 +-
 sys/dev/acpica/acpi.c                  |  36 +++++------
 sys/dev/acpica/acpi_pci.c              |  34 +++++-----
 sys/dev/acpica/acpivar.h               |   6 +-
 sys/dev/ahci/ahci.c                    |   6 +-
 sys/dev/ahci/ahci.h                    |   3 +-
 sys/dev/ahci/ahci_fsl_fdt.c            |   2 +-
 sys/dev/ahci/ahci_generic.c            |   4 +-
 sys/dev/ahci/ahci_mv_fdt.c             |   2 +-
 sys/dev/ahci/ahci_pci.c                |   4 +-
 sys/dev/ata/ata-pci.c                  |   8 +--
 sys/dev/ata/ata-pci.h                  |   5 +-
 sys/dev/ata/chipsets/ata-fsl.c         |   2 +-
 sys/dev/bhnd/bhnd.c                    |  39 ++++--------
 sys/dev/bhnd/bhndb/bhndb.c             |  17 ++---
 sys/dev/bhnd/cores/chipc/chipc.c       |  24 -------
 sys/dev/cxgbe/t4_main.c                |  13 ++--
 sys/dev/fdt/simplebus.c                |   2 +-
 sys/dev/gpio/gpiobus.c                 |  72 ++++++++-------------
 sys/dev/gpio/ofw_gpiobus.c             |   2 +-
 sys/dev/hid/hidbus.c                   |  17 +++--
 sys/dev/hyperv/vmbus/vmbus.c           |  14 ++---
 sys/dev/iicbus/acpi_iicbus.c           |  34 +++-------
 sys/dev/iicbus/iicbus.c                |  16 +++--
 sys/dev/iicbus/iicbus.h                |   6 +-
 sys/dev/iicbus/ofw_iicbus.c            |   2 +-
 sys/dev/mii/mii.c                      |  19 +++---
 sys/dev/mmc/mmc.c                      |  11 ++--
 sys/dev/mvs/mvs_pci.c                  |   8 +--
 sys/dev/mvs/mvs_soc.c                  |   9 ++-
 sys/dev/ntb/ntb.c                      |   6 +-
 sys/dev/ntb/ntb.h                      |   3 +-
 sys/dev/ntb/ntb_hw/ntb_hw_amd.c        |   2 +-
 sys/dev/ntb/ntb_hw/ntb_hw_intel.c      |   2 +-
 sys/dev/ntb/ntb_hw/ntb_hw_plx.c        |   2 +-
 sys/dev/ntb/ntb_transport.c            |   8 +--
 sys/dev/nvdimm/nvdimm_acpi.c           |  13 ++--
 sys/dev/ofw/ofw_bus_subr.h             |   2 +-
 sys/dev/ofw/ofw_cpu.c                  |   2 +-
 sys/dev/ow/ow.c                        |  22 ++-----
 sys/dev/pccard/pccard.c                |  26 +++-----
 sys/dev/pci/pci.c                      |  15 +++--
 sys/dev/pci/pci_private.h              |   8 +--
 sys/dev/puc/puc.c                      |  11 ++--
 sys/dev/puc/puc_bfe.h                  |   4 +-
 sys/dev/puc/puc_pci.c                  |   4 +-
 sys/dev/pwm/ofw_pwmbus.c               |   2 +-
 sys/dev/pwm/pwmbus.c                   |  16 ++---
 sys/dev/siis/siis.c                    |   8 +--
 sys/dev/smbus/smbus.c                  |  12 ++--
 sys/dev/sound/pci/hda/hdaa.c           |  15 ++---
 sys/dev/sound/pci/hda/hdac.c           |  13 ++--
 sys/dev/sound/pci/hda/hdacc.c          |  13 ++--
 sys/dev/spibus/ofw_spibus.c            |   2 +-
 sys/dev/spibus/spibus.c                |  18 ++----
 sys/dev/superio/superio.c              |  15 +++--
 sys/dev/usb/usb_hub.c                  |  38 +++--------
 sys/dev/usb/usb_hub_acpi.c             |  15 ++---
 sys/dev/usb/usb_hub_private.h          |   2 +-
 sys/dev/virtio/mmio/virtio_mmio.c      |   4 +-
 sys/dev/virtio/pci/virtio_pci_legacy.c |   2 +-
 sys/dev/virtio/pci/virtio_pci_modern.c |   2 +-
 sys/dev/virtio/virtio.c                |   5 +-
 sys/dev/virtio/virtio.h                |   3 +-
 sys/isa/isa_common.c                   |  17 +++--
 sys/kern/bus_if.m                      |  28 +++------
 sys/kern/subr_bus.c                    | 112 ++++++++++-----------------------
 sys/powerpc/ofw/ofw_pcibus.c           |  15 +++--
 sys/powerpc/powermac/macgpio.c         |   2 +-
 sys/powerpc/powermac/macio.c           |   2 +-
 sys/powerpc/powermac/smu.c             |   2 +-
 sys/powerpc/powermac/uninorth.c        |   2 +-
 sys/powerpc/powernv/opal_dev.c         |   2 +-
 sys/powerpc/pseries/vdevice.c          |   2 +-
 sys/sys/bus.h                          |   6 +-
 80 files changed, 471 insertions(+), 585 deletions(-)

diff --git a/share/man/man9/BUS_CHILD_LOCATION.9 b/share/man/man9/BUS_CHILD_LOCATION.9
new file mode 100644
index 000000000000..647b942b087a
--- /dev/null
+++ b/share/man/man9/BUS_CHILD_LOCATION.9
@@ -0,0 +1,61 @@
+.\"
+.\" Copyright (c) 2021 Netflix, Inc.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd April 22, 2021
+.Dt BUS_CHILD_LOCATION 9
+.Os
+.Sh NAME
+.Nm BUS_CHILD_LOCATION
+.Nd "obtain the location of a child on the bus."
+.Sh SYNOPSIS
+.In sys/param.h
+.In sys/bus.h
+.In sys/sbuf.h
+.Ft void
+.Fn BUS_CHILD_LOCATION "device_t dev" "device_t child" "struct sbuf *sb"
+.Sh DESCRIPTION
+The
+.Fn BUS_CHILD_LOCATION
+method returns the location of the
+.Dv child
+device.
+This location is a series of key=value pairs.
+The string must be formatted as a space-separated list of key=value pairs.
+Names may only contain alphanumeric characters, underscores ('_') and hyphens ('-').
+Values can contain any non-whitespace characters.
+Values containing whitespace can be quoted with double quotes ('"').
+Double quotes and backslashes in quoted values can be escaped with backslashes ('\').
+.Pp
+The location is defined as a series of characteristics of the
+.Dv child
+device that can be used to locate that device independent of what drivers are
+attached.
+Typically, these are slot numbers, bus addresses, or some topology formation.
+Where possible, buses are encouraged to provide locations that are stable from
+boot to boot and when other devices are added or removed.
+A location is not dependent on the kind of device at that location.
+.Sh SEE ALSO
+.Xr bus 9 ,
+.Xr device 9
diff --git a/share/man/man9/BUS_CHILD_PNPINFO.9 b/share/man/man9/BUS_CHILD_PNPINFO.9
new file mode 100644
index 000000000000..eac9072d0514
--- /dev/null
+++ b/share/man/man9/BUS_CHILD_PNPINFO.9
@@ -0,0 +1,65 @@
+.\"
+.\" Copyright (c) 2021 Netflix, Inc.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd April 22, 2021
+.Dt BUS_CHILD_PNPINFO 9
+.Os
+.Sh NAME
+.Nm BUS_CHILD_PNPINFO
+.Nd "obtain the plug and play information from a device"
+.Sh SYNOPSIS
+.In sys/param.h
+.In sys/bus.h
+.In sys/sbuf.h
+.Ft void
+.Fn BUS_CHILD_PNPINFO "device_t dev" "device_t child" "struct sbuf *sb"
+.Sh DESCRIPTION
+The
+.Fn BUS_CHILD_LOCATION
+method returns the identifying information about the
+.Dv child
+device.
+This information is called the plug and play (pnp) details by some buses.
+This information is a series of key=value pairs.
+The string must be formatted as a space-separated list of key=value pairs.
+Names may only contain alphanumeric characters, underscores ('_') and hyphens ('-').
+Values can contain any non-whitespace characters.
+Values containing whitespace can be quoted with double quotes ('"').
+Double quotes and backslashes in quoted values can be escaped with backslashes ('\').
+.Pp
+The pnpinfo is defined as a series of characteristics of the
+.Dv child
+device that are independent of which drivers are attached, but
+are used to allow drivers to claim a device.
+Typically, plug and play information encodes who made the device, what the model
+number is, and some generic details about the device.
+By convention, only the generic information about the device that's used by
+drivers on that bus to decide on accepting the device is reported.
+Other configuration information (such as the cache burst size) needed for the
+operation of the device, but that doesn't distinguish it broadly from other
+devices is not reported.
+.Sh SEE ALSO
+.Xr bus 9 ,
+.Xr device 9
diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile
index 153870c34af9..19da0a012912 100644
--- a/share/man/man9/Makefile
+++ b/share/man/man9/Makefile
@@ -34,6 +34,8 @@ MAN=	accept_filter.9 \
 	bus_child_present.9 \
 	BUS_CHILD_DELETED.9 \
 	BUS_CHILD_DETACHED.9 \
+	BUS_CHILD_LOCATION.9 \
+	BUS_CHILD_PNPINFO.9 \
 	BUS_CONFIG_INTR.9 \
 	bus_delayed_attach_children.9 \
 	BUS_DESCRIBE_INTR.9 \
diff --git a/sys/arm/allwinner/a10_ahci.c b/sys/arm/allwinner/a10_ahci.c
index 399f17b079ef..5e6f53291394 100644
--- a/sys/arm/allwinner/a10_ahci.c
+++ b/sys/arm/allwinner/a10_ahci.c
@@ -413,7 +413,7 @@ static device_method_t ahci_ata_methods[] = {
 	DEVMETHOD(bus_release_resource,     ahci_release_resource),
 	DEVMETHOD(bus_setup_intr,   ahci_setup_intr),
 	DEVMETHOD(bus_teardown_intr,ahci_teardown_intr),
-	DEVMETHOD(bus_child_location_str, ahci_child_location_str),
+	DEVMETHOD(bus_child_location, ahci_child_location),
 	DEVMETHOD_END
 };
 
diff --git a/sys/arm/freescale/imx/imx6_ahci.c b/sys/arm/freescale/imx/imx6_ahci.c
index 8b49c71c34a0..457966d9b219 100644
--- a/sys/arm/freescale/imx/imx6_ahci.c
+++ b/sys/arm/freescale/imx/imx6_ahci.c
@@ -347,7 +347,7 @@ static device_method_t imx6_ahci_ata_methods[] = {
 	DEVMETHOD(bus_release_resource,   ahci_release_resource),
 	DEVMETHOD(bus_setup_intr,         ahci_setup_intr),
 	DEVMETHOD(bus_teardown_intr,      ahci_teardown_intr),
-	DEVMETHOD(bus_child_location_str, ahci_child_location_str),
+	DEVMETHOD(bus_child_location,	  ahci_child_location),
 
 	DEVMETHOD_END
 };
diff --git a/sys/arm/nvidia/tegra_ahci.c b/sys/arm/nvidia/tegra_ahci.c
index 725fc999a3a3..80416bf3582a 100644
--- a/sys/arm/nvidia/tegra_ahci.c
+++ b/sys/arm/nvidia/tegra_ahci.c
@@ -773,7 +773,7 @@ static device_method_t tegra_ahci_methods[] = {
 	DEVMETHOD(bus_release_resource,	ahci_release_resource),
 	DEVMETHOD(bus_setup_intr,	ahci_setup_intr),
 	DEVMETHOD(bus_teardown_intr,	ahci_teardown_intr),
-	DEVMETHOD(bus_child_location_str, ahci_child_location_str),
+	DEVMETHOD(bus_child_location,	ahci_child_location),
 	DEVMETHOD(bus_get_dma_tag,	ahci_get_dma_tag),
 
 	DEVMETHOD_END
diff --git a/sys/dev/acpica/acpi.c b/sys/dev/acpica/acpi.c
index 18623a6ab240..02358d407c66 100644
--- a/sys/dev/acpica/acpi.c
+++ b/sys/dev/acpica/acpi.c
@@ -177,10 +177,10 @@ static int	acpi_supported_sleep_state_sysctl(SYSCTL_HANDLER_ARGS);
 static int	acpi_sleep_state_sysctl(SYSCTL_HANDLER_ARGS);
 static int	acpi_debug_objects_sysctl(SYSCTL_HANDLER_ARGS);
 static int	acpi_pm_func(u_long cmd, void *arg, ...);
-static int	acpi_child_location_str_method(device_t acdev, device_t child,
-					       char *buf, size_t buflen);
-static int	acpi_child_pnpinfo_str_method(device_t acdev, device_t child,
-					      char *buf, size_t buflen);
+static int	acpi_child_location_method(device_t acdev, device_t child,
+		    struct sbuf *sb);
+static int	acpi_child_pnpinfo_method(device_t acdev, device_t child,
+		    struct sbuf *sb);
 static void	acpi_enable_pcie(void);
 static void	acpi_hint_device_unit(device_t acdev, device_t child,
 		    const char *name, int *unitp);
@@ -210,8 +210,8 @@ static device_method_t acpi_methods[] = {
     DEVMETHOD(bus_adjust_resource,	acpi_adjust_resource),
     DEVMETHOD(bus_release_resource,	acpi_release_resource),
     DEVMETHOD(bus_delete_resource,	acpi_delete_resource),
-    DEVMETHOD(bus_child_pnpinfo_str,	acpi_child_pnpinfo_str_method),
-    DEVMETHOD(bus_child_location_str,	acpi_child_location_str_method),
+    DEVMETHOD(bus_child_pnpinfo,	acpi_child_pnpinfo_method),
+    DEVMETHOD(bus_child_location,	acpi_child_location_method),
     DEVMETHOD(bus_activate_resource,	bus_generic_activate_resource),
     DEVMETHOD(bus_deactivate_resource,	bus_generic_deactivate_resource),
     DEVMETHOD(bus_setup_intr,		bus_generic_setup_intr),
@@ -865,37 +865,32 @@ acpi_driver_added(device_t dev, driver_t *driver)
 
 /* Location hint for devctl(8) */
 static int
-acpi_child_location_str_method(device_t cbdev, device_t child, char *buf,
-    size_t buflen)
+acpi_child_location_method(device_t cbdev, device_t child, struct sbuf *sb)
 {
     struct acpi_device *dinfo = device_get_ivars(child);
-    char buf2[32];
     int pxm;
 
     if (dinfo->ad_handle) {
-        snprintf(buf, buflen, "handle=%s", acpi_name(dinfo->ad_handle));
+        sbuf_printf(sb, "handle=%s", acpi_name(dinfo->ad_handle));
         if (ACPI_SUCCESS(acpi_GetInteger(dinfo->ad_handle, "_PXM", &pxm))) {
-                snprintf(buf2, 32, " _PXM=%d", pxm);
-                strlcat(buf, buf2, buflen);
-        }
-    } else {
-        snprintf(buf, buflen, "");
+            sbuf_printf(sb, " _PXM=%d", pxm);
+	}
     }
     return (0);
 }
 
 /* PnP information for devctl(8) */
 int
-acpi_pnpinfo_str(ACPI_HANDLE handle, char *buf, size_t buflen)
+acpi_pnpinfo(ACPI_HANDLE handle, struct sbuf *sb)
 {
     ACPI_DEVICE_INFO *adinfo;
 
     if (ACPI_FAILURE(AcpiGetObjectInfo(handle, &adinfo))) {
-	snprintf(buf, buflen, "unknown");
+	sbuf_printf(sb, "unknown");
 	return (0);
     }
 
-    snprintf(buf, buflen, "_HID=%s _UID=%lu _CID=%s",
+    sbuf_printf(sb, "_HID=%s _UID=%lu _CID=%s",
 	(adinfo->Valid & ACPI_VALID_HID) ?
 	adinfo->HardwareId.String : "none",
 	(adinfo->Valid & ACPI_VALID_UID) ?
@@ -909,12 +904,11 @@ acpi_pnpinfo_str(ACPI_HANDLE handle, char *buf, size_t buflen)
 }
 
 static int
-acpi_child_pnpinfo_str_method(device_t cbdev, device_t child, char *buf,
-    size_t buflen)
+acpi_child_pnpinfo_method(device_t cbdev, device_t child, struct sbuf *sb)
 {
     struct acpi_device *dinfo = device_get_ivars(child);
 
-    return (acpi_pnpinfo_str(dinfo->ad_handle, buf, buflen));
+    return (acpi_pnpinfo(dinfo->ad_handle, sb));
 }
 
 /*
diff --git a/sys/dev/acpica/acpi_pci.c b/sys/dev/acpica/acpi_pci.c
index c8d37268f466..90618f43bbef 100644
--- a/sys/dev/acpica/acpi_pci.c
+++ b/sys/dev/acpica/acpi_pci.c
@@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/kernel.h>
 #include <sys/malloc.h>
 #include <sys/module.h>
+#include <sys/sbuf.h>
 #include <sys/taskqueue.h>
 #include <sys/tree.h>
 
@@ -78,8 +79,8 @@ CTASSERT(ACPI_STATE_D3 == PCI_POWERSTATE_D3);
 static struct pci_devinfo *acpi_pci_alloc_devinfo(device_t dev);
 static int	acpi_pci_attach(device_t dev);
 static void	acpi_pci_child_deleted(device_t dev, device_t child);
-static int	acpi_pci_child_location_str_method(device_t cbdev,
-		    device_t child, char *buf, size_t buflen);
+static int	acpi_pci_child_location_method(device_t cbdev,
+		    device_t child, struct sbuf *sb);
 static int	acpi_pci_detach(device_t dev);
 static int	acpi_pci_probe(device_t dev);
 static int	acpi_pci_read_ivar(device_t dev, device_t child, int which,
@@ -103,7 +104,7 @@ static device_method_t acpi_pci_methods[] = {
 	DEVMETHOD(bus_read_ivar,	acpi_pci_read_ivar),
 	DEVMETHOD(bus_write_ivar,	acpi_pci_write_ivar),
 	DEVMETHOD(bus_child_deleted,	acpi_pci_child_deleted),
-	DEVMETHOD(bus_child_location_str, acpi_pci_child_location_str_method),
+	DEVMETHOD(bus_child_location,	acpi_pci_child_location_method),
 	DEVMETHOD(bus_get_cpus,		acpi_get_cpus),
 	DEVMETHOD(bus_get_dma_tag,	acpi_pci_get_dma_tag),
 	DEVMETHOD(bus_get_domain,	acpi_get_domain),
@@ -179,25 +180,20 @@ acpi_pci_child_deleted(device_t dev, device_t child)
 }
 
 static int
-acpi_pci_child_location_str_method(device_t cbdev, device_t child, char *buf,
-    size_t buflen)
+acpi_pci_child_location_method(device_t cbdev, device_t child, struct sbuf *sb)
 {
-    struct acpi_pci_devinfo *dinfo = device_get_ivars(child);
-    int pxm;
-    char buf2[32];
-
-    pci_child_location_str_method(cbdev, child, buf, buflen);
+	struct acpi_pci_devinfo *dinfo = device_get_ivars(child);
+	int pxm;
 
-    if (dinfo->ap_handle) {
-        strlcat(buf, " handle=", buflen);
-        strlcat(buf, acpi_name(dinfo->ap_handle), buflen);
+	pci_child_location_method(cbdev, child, sb);
 
-        if (ACPI_SUCCESS(acpi_GetInteger(dinfo->ap_handle, "_PXM", &pxm))) {
-                snprintf(buf2, 32, " _PXM=%d", pxm);
-                strlcat(buf, buf2, buflen);
-        }
-    }
-    return (0);
+	if (dinfo->ap_handle) {
+		sbuf_printf(sb, " handle=%s", acpi_name(dinfo->ap_handle));
+		if (ACPI_SUCCESS(acpi_GetInteger(dinfo->ap_handle, "_PXM", &pxm))) {
+			sbuf_printf(sb, " _PXM=%d", pxm);
+		}
+	}
+	return (0);
 }
 
 /*
diff --git a/sys/dev/acpica/acpivar.h b/sys/dev/acpica/acpivar.h
index fb196c2f4713..980a004e2c35 100644
--- a/sys/dev/acpica/acpivar.h
+++ b/sys/dev/acpica/acpivar.h
@@ -236,8 +236,8 @@ extern int	acpi_quirks;
  * is compatible with ids parameter of ACPI_ID_PROBE bus method.
  *
  * XXX: While ACPI_ID_PROBE matches against _HID and all _CIDs, current
- *      acpi_pnpinfo_str() exports only _HID and first _CID.  That means second
- *      and further _CIDs should be added to both acpi_pnpinfo_str() and
+ *      acpi_pnpinfo() exports only _HID and first _CID.  That means second
+ *      and further _CIDs should be added to both acpi_pnpinfo() and
  *      ACPICOMPAT_PNP_INFO if device matching against them is required.
  */
 #define	ACPICOMPAT_PNP_INFO(t, busname)					\
@@ -490,7 +490,7 @@ int		acpi_wakeup_machdep(struct acpi_softc *sc, int state,
 		    int sleep_result, int intr_enabled);
 int		acpi_table_quirks(int *quirks);
 int		acpi_machdep_quirks(int *quirks);
-int		acpi_pnpinfo_str(ACPI_HANDLE handle, char *buf, size_t buflen);
+int		acpi_pnpinfo(ACPI_HANDLE handle, struct sbuf *sb);
 
 uint32_t	hpet_get_uid(device_t dev);
 
diff --git a/sys/dev/ahci/ahci.c b/sys/dev/ahci/ahci.c
index 8991d9c23fbc..47a5ef455f82 100644
--- a/sys/dev/ahci/ahci.c
+++ b/sys/dev/ahci/ahci.c
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/malloc.h>
 #include <sys/lock.h>
 #include <sys/mutex.h>
+#include <sys/sbuf.h>
 #include <sys/sysctl.h>
 #include <machine/stdarg.h>
 #include <machine/resource.h>
@@ -697,14 +698,13 @@ ahci_print_child(device_t dev, device_t child)
 }
 
 int
-ahci_child_location_str(device_t dev, device_t child, char *buf,
-    size_t buflen)
+ahci_child_location(device_t dev, device_t child, struct sbuf *sb)
 {
 	intptr_t ivars;
 
 	ivars = (intptr_t)device_get_ivars(child);
 	if ((ivars & AHCI_EM_UNIT) == 0)
-		snprintf(buf, buflen, "channel=%d", (int)ivars & AHCI_UNIT);
+		sbuf_printf(sb, "channel=%d", (int)ivars & AHCI_UNIT);
 	return (0);
 }
 
diff --git a/sys/dev/ahci/ahci.h b/sys/dev/ahci/ahci.h
index 472f9845117d..f1d5b18806b3 100644
--- a/sys/dev/ahci/ahci.h
+++ b/sys/dev/ahci/ahci.h
@@ -663,8 +663,7 @@ int ahci_setup_intr(device_t dev, device_t child, struct resource *irq,
     void *argument, void **cookiep);
 int ahci_teardown_intr(device_t dev, device_t child, struct resource *irq,
     void *cookie);
-int ahci_child_location_str(device_t dev, device_t child, char *buf,
-    size_t buflen);
+int ahci_child_location(device_t dev, device_t child, struct sbuf *sb);
 bus_dma_tag_t ahci_get_dma_tag(device_t dev, device_t child);
 int ahci_ctlr_reset(device_t dev);
 int ahci_ctlr_setup(device_t dev);
diff --git a/sys/dev/ahci/ahci_fsl_fdt.c b/sys/dev/ahci/ahci_fsl_fdt.c
index f7491ee9768c..0fda9c28294b 100644
--- a/sys/dev/ahci/ahci_fsl_fdt.c
+++ b/sys/dev/ahci/ahci_fsl_fdt.c
@@ -406,7 +406,7 @@ static const device_method_t ahci_fsl_fdt_methods[] = {
 	DEVMETHOD(bus_setup_intr,   		ahci_setup_intr),
 	DEVMETHOD(bus_teardown_intr,		ahci_teardown_intr),
 	DEVMETHOD(bus_print_child,		ahci_print_child),
-	DEVMETHOD(bus_child_location_str,	ahci_child_location_str),
+	DEVMETHOD(bus_child_location,		ahci_child_location),
 	DEVMETHOD(bus_get_dma_tag,  		ahci_get_dma_tag),
 	DEVMETHOD_END
 };
diff --git a/sys/dev/ahci/ahci_generic.c b/sys/dev/ahci/ahci_generic.c
index 79130e9e9e57..108aaa2adf3a 100644
--- a/sys/dev/ahci/ahci_generic.c
+++ b/sys/dev/ahci/ahci_generic.c
@@ -182,7 +182,7 @@ static device_method_t ahci_fdt_methods[] = {
 	DEVMETHOD(bus_release_resource,     ahci_release_resource),
 	DEVMETHOD(bus_setup_intr,   ahci_setup_intr),
 	DEVMETHOD(bus_teardown_intr,ahci_teardown_intr),
-	DEVMETHOD(bus_child_location_str, ahci_child_location_str),
+	DEVMETHOD(bus_child_location, ahci_child_location),
 	DEVMETHOD(bus_get_dma_tag,  ahci_get_dma_tag),
 	DEVMETHOD_END
 };
@@ -206,7 +206,7 @@ static device_method_t ahci_acpi_methods[] = {
 	DEVMETHOD(bus_release_resource,     ahci_release_resource),
 	DEVMETHOD(bus_setup_intr,   ahci_setup_intr),
 	DEVMETHOD(bus_teardown_intr,ahci_teardown_intr),
-	DEVMETHOD(bus_child_location_str, ahci_child_location_str),
+	DEVMETHOD(bus_child_location, ahci_child_location),
 	DEVMETHOD(bus_get_dma_tag,  ahci_get_dma_tag),
 	DEVMETHOD_END
 };
diff --git a/sys/dev/ahci/ahci_mv_fdt.c b/sys/dev/ahci/ahci_mv_fdt.c
index b88ff2713587..ee08093482c5 100644
--- a/sys/dev/ahci/ahci_mv_fdt.c
+++ b/sys/dev/ahci/ahci_mv_fdt.c
@@ -140,7 +140,7 @@ static device_method_t ahci_methods[] = {
 	DEVMETHOD(bus_setup_intr,   		ahci_setup_intr),
 	DEVMETHOD(bus_teardown_intr,		ahci_teardown_intr),
 	DEVMETHOD(bus_print_child,		ahci_print_child),
-	DEVMETHOD(bus_child_location_str, 	ahci_child_location_str),
+	DEVMETHOD(bus_child_location,	 	ahci_child_location),
 	DEVMETHOD(bus_get_dma_tag,  		ahci_get_dma_tag),
 	DEVMETHOD_END
 };
diff --git a/sys/dev/ahci/ahci_pci.c b/sys/dev/ahci/ahci_pci.c
index ccc107a14bc8..b60119f3ab64 100644
--- a/sys/dev/ahci/ahci_pci.c
+++ b/sys/dev/ahci/ahci_pci.c
@@ -740,7 +740,7 @@ static device_method_t ahci_methods[] = {
 	DEVMETHOD(bus_release_resource,     ahci_release_resource),
 	DEVMETHOD(bus_setup_intr,   ahci_setup_intr),
 	DEVMETHOD(bus_teardown_intr,ahci_teardown_intr),
-	DEVMETHOD(bus_child_location_str, ahci_child_location_str),
+	DEVMETHOD(bus_child_location, ahci_child_location),
 	DEVMETHOD(bus_get_dma_tag,  ahci_get_dma_tag),
 	DEVMETHOD_END
 };
@@ -764,7 +764,7 @@ static device_method_t ahci_ata_methods[] = {
 	DEVMETHOD(bus_release_resource,     ahci_release_resource),
 	DEVMETHOD(bus_setup_intr,   ahci_setup_intr),
 	DEVMETHOD(bus_teardown_intr,ahci_teardown_intr),
-	DEVMETHOD(bus_child_location_str, ahci_child_location_str),
+	DEVMETHOD(bus_child_location, ahci_child_location),
 	DEVMETHOD_END
 };
 static driver_t ahci_ata_driver = {
diff --git a/sys/dev/ata/ata-pci.c b/sys/dev/ata/ata-pci.c
index 578f719f40e4..d8f97158709b 100644
--- a/sys/dev/ata/ata-pci.c
+++ b/sys/dev/ata/ata-pci.c
@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/bus.h>
 #include <sys/conf.h>
 #include <sys/malloc.h>
+#include <sys/sbuf.h>
 #include <sys/sema.h>
 #include <sys/taskqueue.h>
 #include <vm/uma.h>
@@ -558,11 +559,10 @@ ata_pci_print_child(device_t dev, device_t child)
 }
 
 int
-ata_pci_child_location_str(device_t dev, device_t child, char *buf,
-    size_t buflen)
+ata_pci_child_location(device_t dev, device_t child, struct sbuf *sb)
 {
 
-	snprintf(buf, buflen, "channel=%d",
+	sbuf_printf(sb, "channel=%d",
 	    (int)(intptr_t)device_get_ivars(child));
 	return (0);
 }
@@ -595,7 +595,7 @@ static device_method_t ata_pci_methods[] = {
     DEVMETHOD(pci_read_config,		ata_pci_read_config),
     DEVMETHOD(pci_write_config,		ata_pci_write_config),
     DEVMETHOD(bus_print_child,		ata_pci_print_child),
-    DEVMETHOD(bus_child_location_str,	ata_pci_child_location_str),
+    DEVMETHOD(bus_child_location,	ata_pci_child_location),
     DEVMETHOD(bus_get_dma_tag,		ata_pci_get_dma_tag),
 
     DEVMETHOD_END
diff --git a/sys/dev/ata/ata-pci.h b/sys/dev/ata/ata-pci.h
index 2fc8b278d589..ab0e661de29f 100644
--- a/sys/dev/ata/ata-pci.h
+++ b/sys/dev/ata/ata-pci.h
@@ -535,8 +535,7 @@ uint32_t ata_pci_read_config(device_t dev, device_t child, int reg, int width);
 void ata_pci_write_config(device_t dev, device_t child, int reg, 
     uint32_t val, int width);
 int ata_pci_print_child(device_t dev, device_t child);
-int ata_pci_child_location_str(device_t dev, device_t child, char *buf,
-    size_t buflen);
+int ata_pci_child_location(device_t dev, device_t child, struct sbuf *sb);
 struct resource * ata_pci_alloc_resource(device_t dev, device_t child, int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags);
 int ata_pci_release_resource(device_t dev, device_t child, int type, int rid, struct resource *r);
 int ata_pci_setup_intr(device_t dev, device_t child, struct resource *irq, int flags, driver_filter_t *filter, driver_intr_t *function, void *argument, void **cookiep);
@@ -586,7 +585,7 @@ static device_method_t __CONCAT(dname,_methods)[] = { \
     DEVMETHOD(pci_read_config,		ata_pci_read_config), \
     DEVMETHOD(pci_write_config,		ata_pci_write_config), \
     DEVMETHOD(bus_print_child,		ata_pci_print_child), \
-    DEVMETHOD(bus_child_location_str,	ata_pci_child_location_str), \
+    DEVMETHOD(bus_child_location,	ata_pci_child_location), \
     DEVMETHOD_END \
 }; \
 static driver_t __CONCAT(dname,_driver) = { \
diff --git a/sys/dev/ata/chipsets/ata-fsl.c b/sys/dev/ata/chipsets/ata-fsl.c
index f7545e211358..32fe2a04bd19 100644
--- a/sys/dev/ata/chipsets/ata-fsl.c
+++ b/sys/dev/ata/chipsets/ata-fsl.c
@@ -227,7 +227,7 @@ static device_method_t imx_ata_methods[] = {
 	DEVMETHOD(pci_read_config,	ata_pci_read_config),
 	DEVMETHOD(pci_write_config,	ata_pci_write_config),
 	DEVMETHOD(bus_print_child,	ata_pci_print_child),
-	DEVMETHOD(bus_child_location_str, ata_pci_child_location_str),
+	DEVMETHOD(bus_child_location,	ata_pci_child_location),
 	DEVMETHOD_END
 };
 static driver_t imx_ata_driver = {
diff --git a/sys/dev/bhnd/bhnd.c b/sys/dev/bhnd/bhnd.c
index 1ec4cb1ce48d..654f42864233 100644
--- a/sys/dev/bhnd/bhnd.c
+++ b/sys/dev/bhnd/bhnd.c
@@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/kernel.h>
 #include <sys/bus.h>
 #include <sys/module.h>
+#include <sys/sbuf.h>
 #include <sys/systm.h>
 
 #include <machine/bus.h>
@@ -899,48 +900,32 @@ bhnd_generic_probe_nomatch(device_t dev, device_t child)
 	    bhnd_get_core_index(child));
 }
 
-/**
- * Default implementation of BUS_CHILD_PNPINFO_STR().
- */
 static int
-bhnd_child_pnpinfo_str(device_t dev, device_t child, char *buf,
-    size_t buflen)
+bhnd_child_pnpinfo(device_t dev, device_t child, struct sbuf *sb)
 {
-	if (device_get_parent(child) != dev) {
-		return (BUS_CHILD_PNPINFO_STR(device_get_parent(dev), child,
-		    buf, buflen));
-	}
+	if (device_get_parent(child) != dev)
+		return (BUS_CHILD_PNPINFO(device_get_parent(dev), child, sb));
 
-	snprintf(buf, buflen, "vendor=0x%hx device=0x%hx rev=0x%hhx",
+	sbuf_printf(sb, "vendor=0x%hx device=0x%hx rev=0x%hhx",
 	    bhnd_get_vendor(child), bhnd_get_device(child),
 	    bhnd_get_hwrev(child));
 
 	return (0);
 }
 
-/**
- * Default implementation of BUS_CHILD_LOCATION_STR().
- */
 static int
-bhnd_child_location_str(device_t dev, device_t child, char *buf,
-    size_t buflen)
+bhnd_child_location(device_t dev, device_t child, struct sbuf *sb)
 {
 	bhnd_addr_t	addr;
 	bhnd_size_t	size;
 
-	if (device_get_parent(child) != dev) {
-		return (BUS_CHILD_LOCATION_STR(device_get_parent(dev), child,
-		    buf, buflen));
-	}
+	if (device_get_parent(child) != dev)
+		return (BUS_CHILD_LOCATION(device_get_parent(dev), child, sb));
 
-	if (bhnd_get_region_addr(child, BHND_PORT_DEVICE, 0, 0, &addr, &size)) {
-		/* No device default port/region */
-		if (buflen > 0)
-			*buf = '\0';
+	if (bhnd_get_region_addr(child, BHND_PORT_DEVICE, 0, 0, &addr, &size))
 		return (0);
-	}
 
-	snprintf(buf, buflen, "port0.0=0x%llx", (unsigned long long) addr);
+	sbuf_printf(sb, "port0.0=0x%llx", (unsigned long long) addr);
 	return (0);
 }
 
@@ -1104,8 +1089,8 @@ static device_method_t bhnd_methods[] = {
 	DEVMETHOD(bus_child_deleted,		bhnd_generic_child_deleted),
 	DEVMETHOD(bus_probe_nomatch,		bhnd_generic_probe_nomatch),
 	DEVMETHOD(bus_print_child,		bhnd_generic_print_child),
-	DEVMETHOD(bus_child_pnpinfo_str,	bhnd_child_pnpinfo_str),
-	DEVMETHOD(bus_child_location_str,	bhnd_child_location_str),
+	DEVMETHOD(bus_child_pnpinfo,		bhnd_child_pnpinfo),
+	DEVMETHOD(bus_child_location,		bhnd_child_location),
 
 	DEVMETHOD(bus_suspend_child,		bhnd_generic_suspend_child),
 	DEVMETHOD(bus_resume_child,		bhnd_generic_resume_child),
diff --git a/sys/dev/bhnd/bhndb/bhndb.c b/sys/dev/bhnd/bhndb/bhndb.c
index c90ed9abf671..9a2beb50e9bb 100644
--- a/sys/dev/bhnd/bhndb/bhndb.c
+++ b/sys/dev/bhnd/bhndb/bhndb.c
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/kernel.h>
 #include <sys/bus.h>
 #include <sys/module.h>
+#include <sys/sbuf.h>
 #include <sys/systm.h>
 
 #include <machine/bus.h>
@@ -168,22 +169,13 @@ bhndb_print_child(device_t dev, device_t child)
 }
 
 static int
-bhndb_child_pnpinfo_str(device_t bus, device_t child, char *buf,
-    size_t buflen)
-{
-	*buf = '\0';
-	return (0);
-}
-
-static int
-bhndb_child_location_str(device_t dev, device_t child, char *buf,
-    size_t buflen)
+bhndb_child_location(device_t dev, device_t child, struct sbuf *sb)
 {
 	struct bhndb_softc *sc;
 
 	sc = device_get_softc(dev);
 
-	snprintf(buf, buflen, "base=0x%llx",
+	sbuf_printf(sb, "base=0x%llx",
 	    (unsigned long long) sc->chipid.enum_addr);
 	return (0);
 }
@@ -2215,8 +2207,7 @@ static device_method_t bhndb_methods[] = {
 	/* Bus interface */
 	DEVMETHOD(bus_probe_nomatch,		bhndb_probe_nomatch),
 	DEVMETHOD(bus_print_child,		bhndb_print_child),
-	DEVMETHOD(bus_child_pnpinfo_str,	bhndb_child_pnpinfo_str),
-	DEVMETHOD(bus_child_location_str,	bhndb_child_location_str),
+	DEVMETHOD(bus_child_location,		bhndb_child_location),
 	DEVMETHOD(bus_add_child,		bhndb_add_child),
 	DEVMETHOD(bus_child_deleted,		bhndb_child_deleted),
 
diff --git a/sys/dev/bhnd/cores/chipc/chipc.c b/sys/dev/bhnd/cores/chipc/chipc.c
index 1449c3b565dc..314f214d08b1 100644
--- a/sys/dev/bhnd/cores/chipc/chipc.c
+++ b/sys/dev/bhnd/cores/chipc/chipc.c
@@ -596,28 +596,6 @@ chipc_print_child(device_t dev, device_t child)
 	return (retval);
 }
 
-static int
-chipc_child_pnpinfo_str(device_t dev, device_t child, char *buf,
-    size_t buflen)
-{
-	if (buflen == 0)
-		return (EOVERFLOW);
-
-	*buf = '\0';
-	return (0);
-}
-
-static int
-chipc_child_location_str(device_t dev, device_t child, char *buf,
-    size_t buflen)
-{
-	if (buflen == 0)
-		return (EOVERFLOW);
-
-	*buf = '\0';
-	return (ENXIO);
-}
-
 static device_t
 chipc_add_child(device_t dev, u_int order, const char *name, int unit)
 {
@@ -1412,8 +1390,6 @@ static device_method_t chipc_methods[] = {
 	/* Bus interface */
 	DEVMETHOD(bus_probe_nomatch,		chipc_probe_nomatch),
 	DEVMETHOD(bus_print_child,		chipc_print_child),
-	DEVMETHOD(bus_child_pnpinfo_str,	chipc_child_pnpinfo_str),
-	DEVMETHOD(bus_child_location_str,	chipc_child_location_str),
 
 	DEVMETHOD(bus_add_child,		chipc_add_child),
 	DEVMETHOD(bus_child_deleted,		chipc_child_deleted),
diff --git a/sys/dev/cxgbe/t4_main.c b/sys/dev/cxgbe/t4_main.c
index 650300c805a1..c5a3e6dd200e 100644
--- a/sys/dev/cxgbe/t4_main.c
+++ b/sys/dev/cxgbe/t4_main.c
@@ -97,7 +97,7 @@ __FBSDID("$FreeBSD$");
 static int t4_probe(device_t);
 static int t4_attach(device_t);
 static int t4_detach(device_t);
-static int t4_child_location_str(device_t, device_t, char *, size_t);
+static int t4_child_location(device_t, device_t, struct sbuf *);
 static int t4_ready(device_t);
 static int t4_read_port_device(device_t, int, device_t *);
 static int t4_suspend(device_t);
@@ -111,7 +111,7 @@ static device_method_t t4_methods[] = {
 	DEVMETHOD(device_suspend,	t4_suspend),
 	DEVMETHOD(device_resume,	t4_resume),
 
-	DEVMETHOD(bus_child_location_str, t4_child_location_str),
+	DEVMETHOD(bus_child_location,	t4_child_location),
 	DEVMETHOD(bus_reset_prepare, 	t4_reset_prepare),
 	DEVMETHOD(bus_reset_post, 	t4_reset_post),
 
@@ -176,7 +176,7 @@ static device_method_t t5_methods[] = {
 	DEVMETHOD(device_suspend,	t4_suspend),
 	DEVMETHOD(device_resume,	t4_resume),
 
-	DEVMETHOD(bus_child_location_str, t4_child_location_str),
+	DEVMETHOD(bus_child_location,	t4_child_location),
 	DEVMETHOD(bus_reset_prepare, 	t4_reset_prepare),
 	DEVMETHOD(bus_reset_post, 	t4_reset_post),
 
@@ -215,7 +215,7 @@ static device_method_t t6_methods[] = {
 	DEVMETHOD(device_suspend,	t4_suspend),
 	DEVMETHOD(device_resume,	t4_resume),
 
-	DEVMETHOD(bus_child_location_str, t4_child_location_str),
+	DEVMETHOD(bus_child_location,	t4_child_location),
 	DEVMETHOD(bus_reset_prepare, 	t4_reset_prepare),
 	DEVMETHOD(bus_reset_post, 	t4_reset_post),
 
@@ -1572,18 +1572,17 @@ done:
 }
 
 static int
-t4_child_location_str(device_t bus, device_t dev, char *buf, size_t buflen)
+t4_child_location(device_t bus, device_t dev, struct sbuf *sb)
 {
 	struct adapter *sc;
 	struct port_info *pi;
 	int i;
 
 	sc = device_get_softc(bus);
-	buf[0] = '\0';
 	for_each_port(sc, i) {
 		pi = sc->port[i];
 		if (pi != NULL && pi->dev == dev) {
-			snprintf(buf, buflen, "port=%d", pi->port_id);
+			sbuf_printf(sb, "port=%d", pi->port_id);
 			break;
 		}
 	}
diff --git a/sys/dev/fdt/simplebus.c b/sys/dev/fdt/simplebus.c
index 4496d2caaad7..76814ed40b04 100644
--- a/sys/dev/fdt/simplebus.c
+++ b/sys/dev/fdt/simplebus.c
@@ -87,7 +87,7 @@ static device_method_t	simplebus_methods[] = {
 	DEVMETHOD(bus_adjust_resource,	bus_generic_adjust_resource),
 	DEVMETHOD(bus_set_resource,	bus_generic_rl_set_resource),
 	DEVMETHOD(bus_get_resource,	bus_generic_rl_get_resource),
-	DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str),
+	DEVMETHOD(bus_child_pnpinfo,	ofw_bus_gen_child_pnpinfo),
 	DEVMETHOD(bus_get_resource_list, simplebus_get_resource_list),
 
 	/* ofw_bus interface */
diff --git a/sys/dev/gpio/gpiobus.c b/sys/dev/gpio/gpiobus.c
index e1f74d81955e..4ed8e14aedb9 100644
--- a/sys/dev/gpio/gpiobus.c
+++ b/sys/dev/gpio/gpiobus.c
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/kernel.h>
 #include <sys/malloc.h>
 #include <sys/module.h>
+#include <sys/sbuf.h>
 
 #include <dev/gpio/gpiobusvar.h>
 
@@ -51,7 +52,7 @@ __FBSDID("$FreeBSD$");
 #define	dprintf(x, arg...)
 #endif
 
-static void gpiobus_print_pins(struct gpiobus_ivar *, char *, size_t);
+static void gpiobus_print_pins(struct gpiobus_ivar *, struct sbuf *);
 static int gpiobus_parse_pins(struct gpiobus_softc *, device_t, int);
 static int gpiobus_probe(device_t);
 static int gpiobus_attach(device_t);
@@ -60,8 +61,7 @@ static int gpiobus_suspend(device_t);
 static int gpiobus_resume(device_t);
 static void gpiobus_probe_nomatch(device_t, device_t);
 static int gpiobus_print_child(device_t, device_t);
-static int gpiobus_child_location_str(device_t, device_t, char *, size_t);
-static int gpiobus_child_pnpinfo_str(device_t, device_t, char *, size_t);
+static int gpiobus_child_location(device_t, device_t, struct sbuf *);
 static device_t gpiobus_add_child(device_t, u_int, const char *, int);
 static void gpiobus_hinted_child(device_t, const char *, int);
 
@@ -265,9 +265,8 @@ gpio_pin_setflags(gpio_pin_t pin, uint32_t flags)
 }
 
 static void
-gpiobus_print_pins(struct gpiobus_ivar *devi, char *buf, size_t buflen)
+gpiobus_print_pins(struct gpiobus_ivar *devi, struct sbuf *sb)
 {
-	char tmp[128];
 	int i, range_start, range_stop, need_coma;
 
 	if (devi->npins == 0)
@@ -278,16 +277,11 @@ gpiobus_print_pins(struct gpiobus_ivar *devi, char *buf, size_t buflen)
 	for (i = 1; i < devi->npins; i++) {
 		if (devi->pins[i] != (range_stop + 1)) {
 			if (need_coma)
-				strlcat(buf, ",", buflen);
-			memset(tmp, 0, sizeof(tmp));
+				sbuf_cat(sb, ",");
 			if (range_start != range_stop)
-				snprintf(tmp, sizeof(tmp) - 1, "%d-%d",
-				    range_start, range_stop);
+				sbuf_printf(sb, "%d-%d", range_start, range_stop);
 			else
-				snprintf(tmp, sizeof(tmp) - 1, "%d",
-				    range_start);
-			strlcat(buf, tmp, buflen);
-
+				sbuf_printf(sb, "%d", range_start);
 			range_start = range_stop = devi->pins[i];
 			need_coma = 1;
 		}
@@ -296,15 +290,11 @@ gpiobus_print_pins(struct gpiobus_ivar *devi, char *buf, size_t buflen)
 	}
 
 	if (need_coma)
-		strlcat(buf, ",", buflen);
-	memset(tmp, 0, sizeof(tmp));
+		sbuf_cat(sb, ",");
 	if (range_start != range_stop)
-		snprintf(tmp, sizeof(tmp) - 1, "%d-%d",
-		    range_start, range_stop);
+		sbuf_printf(sb, "%d-%d", range_start, range_stop);
 	else
*** 2116 LINES SKIPPED ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202106230254.15N2sdov081576>