From owner-svn-src-head@freebsd.org Thu May 31 02:58:06 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A3D5EEFAE3C; Thu, 31 May 2018 02:58:06 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id DAD946AA45; Thu, 31 May 2018 02:58:04 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 57FEA14396; Thu, 31 May 2018 02:58:04 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w4V2w4Y2073394; Thu, 31 May 2018 02:58:04 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w4V2w3Mk073392; Thu, 31 May 2018 02:58:03 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201805310258.w4V2w3Mk073392@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Thu, 31 May 2018 02:58:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334415 - head/lib/libdevinfo X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/lib/libdevinfo X-SVN-Commit-Revision: 334415 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 May 2018 02:58:07 -0000 Author: imp Date: Thu May 31 02:58:03 2018 New Revision: 334415 URL: https://svnweb.freebsd.org/changeset/base/334415 Log: Update to device enumeration protocol 2 The new protocol from the kernel encodes things as a string table, extract it into fields. strdup the strings, and free them when we're done. Differential Revision: https://reviews.freebsd.org/D15629 Modified: head/lib/libdevinfo/devinfo.c head/lib/libdevinfo/devinfo_var.h Modified: head/lib/libdevinfo/devinfo.c ============================================================================== --- head/lib/libdevinfo/devinfo.c Thu May 31 02:57:58 2018 (r334414) +++ head/lib/libdevinfo/devinfo.c Thu May 31 02:58:03 2018 (r334415) @@ -175,7 +175,7 @@ devinfo_init_devices(int generation) int name2oid[2]; int oid[CTL_MAXNAME + 12]; size_t oidlen, rlen; - char *name; + char *name, *walker, *ep; int error; /* @@ -229,22 +229,31 @@ devinfo_init_devices(int generation) return(ENOMEM); dd->dd_dev.dd_handle = udev.dv_handle; dd->dd_dev.dd_parent = udev.dv_parent; - snprintf(dd->dd_name, sizeof(dd->dd_name), "%s", udev.dv_name); - dd->dd_dev.dd_name = &dd->dd_name[0]; - snprintf(dd->dd_desc, sizeof(dd->dd_desc), "%s", udev.dv_desc); - dd->dd_dev.dd_desc = &dd->dd_desc[0]; - snprintf(dd->dd_drivername, sizeof(dd->dd_drivername), "%s", - udev.dv_drivername); - dd->dd_dev.dd_drivername = &dd->dd_drivername[0]; - snprintf(dd->dd_pnpinfo, sizeof(dd->dd_pnpinfo), "%s", - udev.dv_pnpinfo); - dd->dd_dev.dd_pnpinfo = &dd->dd_pnpinfo[0]; - snprintf(dd->dd_location, sizeof(dd->dd_location), "%s", - udev.dv_location); - dd->dd_dev.dd_location = &dd->dd_location[0]; dd->dd_dev.dd_devflags = udev.dv_devflags; dd->dd_dev.dd_flags = udev.dv_flags; dd->dd_dev.dd_state = udev.dv_state; + + walker = udev.dv_fields; + ep = walker + sizeof(udev.dv_fields); + dd->dd_name = NULL; + dd->dd_desc = NULL; + dd->dd_drivername = NULL; + dd->dd_pnpinfo = NULL; + dd->dd_location = NULL; +#define UNPACK(x) \ + dd->dd_dev.x = dd->x = strdup(walker); \ + if (dd->x == NULL) \ + return(ENOMEM); \ + if (walker + strnlen(walker, ep - walker) >= ep) \ + return(EINVAL); \ + walker += strlen(walker) + 1; + + UNPACK(dd_name); + UNPACK(dd_desc); + UNPACK(dd_drivername); + UNPACK(dd_pnpinfo); + UNPACK(dd_location); +#undef UNPACK TAILQ_INSERT_TAIL(&devinfo_dev, dd, dd_link); } debug("fetched %d devices", dev_idx); @@ -367,6 +376,11 @@ devinfo_free(void) while ((dd = TAILQ_FIRST(&devinfo_dev)) != NULL) { TAILQ_REMOVE(&devinfo_dev, dd, dd_link); + free(dd->dd_name); + free(dd->dd_desc); + free(dd->dd_drivername); + free(dd->dd_pnpinfo); + free(dd->dd_location); free(dd); } while ((dm = TAILQ_FIRST(&devinfo_rman)) != NULL) { Modified: head/lib/libdevinfo/devinfo_var.h ============================================================================== --- head/lib/libdevinfo/devinfo_var.h Thu May 31 02:57:58 2018 (r334414) +++ head/lib/libdevinfo/devinfo_var.h Thu May 31 02:58:03 2018 (r334415) @@ -45,11 +45,11 @@ */ struct devinfo_i_dev { struct devinfo_dev dd_dev; - char dd_name[DEVINFO_STRLEN]; - char dd_desc[DEVINFO_STRLEN]; - char dd_drivername[DEVINFO_STRLEN]; - char dd_pnpinfo[DEVINFO_STRLEN * 4]; - char dd_location[DEVINFO_STRLEN * 4]; + char *dd_name; + char *dd_desc; + char *dd_drivername; + char *dd_pnpinfo; + char *dd_location; uint32_t dd_devflags; uint16_t dd_flags; device_state_t dd_state;