svn commit: r301021 - in head/sys/dev/hyperv: include utilities vmbus

Sepherosa Ziehau sephe at FreeBSD.org
Tue May 31 05:44:00 UTC 2016


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);
 


More information about the svn-src-all mailing list