From owner-svn-src-head@freebsd.org Tue May 31 05:44:00 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A7AE5B55EBC; Tue, 31 May 2016 05:44:00 +0000 (UTC) (envelope-from sephe@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 mx1.freebsd.org (Postfix) with ESMTPS id 667CE1C65; Tue, 31 May 2016 05:44:00 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4V5hxhf056705; Tue, 31 May 2016 05:43:59 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4V5hxYB056701; Tue, 31 May 2016 05:43:59 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201605310543.u4V5hxYB056701@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Tue, 31 May 2016 05:43:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r301021 - in head/sys/dev/hyperv: include utilities vmbus X-SVN-Group: head 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.22 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: Tue, 31 May 2016 05:44:00 -0000 Author: sephe Date: Tue May 31 05:43:59 2016 New Revision: 301021 URL: https://svnweb.freebsd.org/changeset/base/301021 Log: hyperv: Move guid2str from vmbus file to hyperv file - Use uint8_t for GUID byte array. - Define GUID string length. - Break long lines. - Nuke unnecessary stack variable. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6640 Modified: head/sys/dev/hyperv/include/hyperv.h head/sys/dev/hyperv/utilities/hv_kvp.c head/sys/dev/hyperv/vmbus/hv_hv.c head/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Modified: head/sys/dev/hyperv/include/hyperv.h ============================================================================== --- head/sys/dev/hyperv/include/hyperv.h Tue May 31 05:34:46 2016 (r301020) +++ head/sys/dev/hyperv/include/hyperv.h Tue May 31 05:43:59 2016 (r301021) @@ -121,10 +121,12 @@ typedef uint8_t hv_bool_uint8_t; HV_ALIGN_DOWN(addr, PAGE_SIZE)) >> PAGE_SHIFT ) typedef struct hv_guid { - unsigned char data[16]; + uint8_t data[16]; } __packed hv_guid; -int snprintf_hv_guid(char *, size_t, const hv_guid *); +#define HYPERV_GUID_STRLEN 40 + +int hyperv_guid2str(const struct hv_guid *, char *, size_t); #define HV_NIC_GUID \ .data = {0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46, \ Modified: head/sys/dev/hyperv/utilities/hv_kvp.c ============================================================================== --- head/sys/dev/hyperv/utilities/hv_kvp.c Tue May 31 05:34:46 2016 (r301020) +++ head/sys/dev/hyperv/utilities/hv_kvp.c Tue May 31 05:43:59 2016 (r301021) @@ -307,7 +307,7 @@ hv_kvp_convert_utf16_ipinfo_to_utf8(stru struct hv_device *hv_dev; /* GUID Data Structure */ hn_softc_t *sc; /* hn softc structure */ char if_name[4]; - char buf[39]; + char buf[HYPERV_GUID_STRLEN]; device_t *devs; int devcnt; @@ -335,10 +335,11 @@ hv_kvp_convert_utf16_ipinfo_to_utf8(stru /* Trying to find GUID of Network Device */ hv_dev = sc->hn_dev_obj; - snprintf_hv_guid(buf, sizeof(buf), &hv_dev->device_id); + hyperv_guid2str(&hv_dev->device_id, buf, sizeof(buf)); sprintf(if_name, "%s%d", "hn", device_get_unit(devs[devcnt])); - if (strncmp(buf, (char *)umsg->body.kvp_ip_val.adapter_id, 39) == 0) { + if (strncmp(buf, (char *)umsg->body.kvp_ip_val.adapter_id, + HYPERV_GUID_STRLEN - 1) == 0) { strcpy((char *)umsg->body.kvp_ip_val.adapter_id, if_name); break; } Modified: head/sys/dev/hyperv/vmbus/hv_hv.c ============================================================================== --- head/sys/dev/hyperv/vmbus/hv_hv.c Tue May 31 05:34:46 2016 (r301020) +++ head/sys/dev/hyperv/vmbus/hv_hv.c Tue May 31 05:43:59 2016 (r301021) @@ -202,6 +202,18 @@ hv_vmbus_signal_event(void *con_id) return (status); } +int +hyperv_guid2str(const struct hv_guid *guid, char *buf, size_t sz) +{ + const uint8_t *d = guid->data; + + return snprintf(buf, sz, "%02x%02x%02x%02x-" + "%02x%02x-%02x%02x-%02x%02x-" + "%02x%02x%02x%02x%02x%02x", + d[3], d[2], d[1], d[0], + d[5], d[4], d[7], d[6], d[8], d[9], + d[10], d[11], d[12], d[13], d[14], d[15]); +} static bool hyperv_identify(void) Modified: head/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- head/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Tue May 31 05:34:46 2016 (r301020) +++ head/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Tue May 31 05:43:59 2016 (r301021) @@ -490,18 +490,18 @@ vmbus_write_ivar(device_t dev, device_t static int vmbus_child_pnpinfo_str(device_t dev, device_t child, char *buf, size_t buflen) { - char guidbuf[40]; struct hv_device *dev_ctx = device_get_ivars(child); + char guidbuf[HYPERV_GUID_STRLEN]; if (dev_ctx == NULL) return (0); strlcat(buf, "classid=", buflen); - snprintf_hv_guid(guidbuf, sizeof(guidbuf), &dev_ctx->class_id); + hyperv_guid2str(&dev_ctx->class_id, guidbuf, sizeof(guidbuf)); strlcat(buf, guidbuf, buflen); strlcat(buf, " deviceid=", buflen); - snprintf_hv_guid(guidbuf, sizeof(guidbuf), &dev_ctx->device_id); + hyperv_guid2str(&dev_ctx->device_id, guidbuf, sizeof(guidbuf)); strlcat(buf, guidbuf, buflen); return (0); @@ -526,30 +526,19 @@ hv_vmbus_child_device_create(hv_guid typ } int -snprintf_hv_guid(char *buf, size_t sz, const hv_guid *guid) -{ - int cnt; - const unsigned char *d = guid->data; - - cnt = snprintf(buf, sz, - "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", - d[3], d[2], d[1], d[0], d[5], d[4], d[7], d[6], - d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]); - return (cnt); -} - -int hv_vmbus_child_device_register(struct hv_device *child_dev) { - device_t child; + device_t child, parent; + parent = vmbus_get_device(); if (bootverbose) { - char name[40]; - snprintf_hv_guid(name, sizeof(name), &child_dev->class_id); - printf("VMBUS: Class ID: %s\n", name); + char name[HYPERV_GUID_STRLEN]; + + hyperv_guid2str(&child_dev->class_id, name, sizeof(name)); + device_printf(parent, "add device, classid: %s\n", name); } - child = device_add_child(vmbus_get_device(), NULL, -1); + child = device_add_child(parent, NULL, -1); child_dev->device = child; device_set_ivars(child, child_dev);