Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Aug 2008 18:24:38 GMT
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 147165 for review
Message-ID:  <200808111824.m7BIOc6u056752@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=147165

Change 147165 by hselasky@hselasky_laptop001 on 2008/08/11 18:23:50

	
	Style: This is the first of two patches to remove extra
	indenting level inserted by "indent". Remove the curly
	brackets after all the cases in the switch statements.

Affected files ...

.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_generic.c#17 edit

Differences ...

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_generic.c#17 (text+ko) ====

@@ -1387,13 +1387,30 @@
 static int
 ugen_fs_ioctl(struct usb2_fifo *f, u_long cmd, void *addr, int fflags)
 {
+	struct usb2_config usb2_config[1];
+	struct usb2_device_request req;
+	union {
+		struct usb2_fs_complete *pcomp;
+		struct usb2_fs_start *pstart;
+		struct usb2_fs_stop *pstop;
+		struct usb2_fs_init *pinit;
+		struct usb2_fs_uninit *puninit;
+		struct usb2_fs_open *popen;
+		struct usb2_fs_close *pclose;
+		struct usb2_fs_clear_stall_sync *pstall;
+		void *addr;
+	} u;
+	struct usb2_pipe *pipe;
+	struct usb2_endpoint_descriptor *ed;
 	int error = 0;
+	uint8_t iface_index;
+	uint8_t isread;
+	uint8_t ep_index;
+
+	u.addr = addr;
 
 	switch (cmd) {
-	case USB_FS_COMPLETE:{
-			struct usb2_fs_complete *pd = addr;
-			uint8_t ep_index;
-
+	case USB_FS_COMPLETE:
 			mtx_lock(f->priv_mtx);
 			error = ugen_fs_get_complete(f, &ep_index);
 			mtx_unlock(f->priv_mtx);
@@ -1402,48 +1419,41 @@
 				error = EBUSY;
 				break;
 			}
-			pd->ep_index = ep_index;
-			error = ugen_fs_copy_out(f, pd->ep_index);
+			u.pcomp->ep_index = ep_index;
+			error = ugen_fs_copy_out(f, u.pcomp->ep_index);
 			break;
-		}
 
-	case USB_FS_START:{
-			struct usb2_fs_start *pd = addr;
-
-			error = ugen_fs_copy_in(f, pd->ep_index);
+	case USB_FS_START:
+			error = ugen_fs_copy_in(f, u.pstart->ep_index);
 			if (error) {
 				break;
 			}
 			mtx_lock(f->priv_mtx);
-			usb2_transfer_start(f->fs_xfer[pd->ep_index]);
+			usb2_transfer_start(f->fs_xfer[u.pstart->ep_index]);
 			mtx_unlock(f->priv_mtx);
 			break;
-		}
-	case USB_FS_STOP:{
-			struct usb2_fs_stop *pd = addr;
 
-			if (pd->ep_index >= f->fs_ep_max) {
+	case USB_FS_STOP:
+			if (u.pstop->ep_index >= f->fs_ep_max) {
 				error = EINVAL;
 				break;
 			}
 			mtx_lock(f->priv_mtx);
-			usb2_transfer_stop(f->fs_xfer[pd->ep_index]);
+			usb2_transfer_stop(f->fs_xfer[u.pstop->ep_index]);
 			mtx_unlock(f->priv_mtx);
 			break;
-		}
-	case USB_FS_INIT:{
-			struct usb2_fs_init *pd = addr;
 
+	case USB_FS_INIT:
 			/* verify input parameters */
-			if (pd->pEndpoints == NULL) {
+			if (u.pinit->pEndpoints == NULL) {
 				error = EINVAL;
 				break;
 			}
-			if (pd->ep_index_max > 127) {
+			if (u.pinit->ep_index_max > 127) {
 				error = EINVAL;
 				break;
 			}
-			if (pd->ep_index_max == 0) {
+			if (u.pinit->ep_index_max == 0) {
 				error = EINVAL;
 				break;
 			}
@@ -1463,61 +1473,50 @@
 				error = EBUSY;
 				break;
 			}
-			error = usb2_fifo_alloc_buffer(f, 1, pd->ep_index_max);
+			error = usb2_fifo_alloc_buffer(f, 1, u.pinit->ep_index_max);
 			if (error) {
 				break;
 			}
 			f->fs_xfer = malloc(sizeof(f->fs_xfer[0]) *
-			    pd->ep_index_max, M_USB, M_WAITOK | M_ZERO);
+			    u.pinit->ep_index_max, M_USB, M_WAITOK | M_ZERO);
 			if (f->fs_xfer == NULL) {
 				usb2_fifo_free_buffer(f);
 				error = ENOMEM;
 				break;
 			}
-			f->fs_ep_max = pd->ep_index_max;
-			f->fs_ep_ptr = pd->pEndpoints;
+			f->fs_ep_max = u.pinit->ep_index_max;
+			f->fs_ep_ptr = u.pinit->pEndpoints;
 			break;
-		}
 
-	case USB_FS_UNINIT:{
-			struct usb2_fs_uninit *pd = addr;
-
-			if (pd->dummy != 0) {
+	case USB_FS_UNINIT:
+			if (u.puninit->dummy != 0) {
 				error = EINVAL;
 				break;
 			}
 			error = ugen_fs_uninit(f);
 			break;
-		}
 
-	case USB_FS_OPEN:{
-			struct usb2_config usb2_config[1];
-			struct usb2_fs_open *pd = addr;
-			struct usb2_pipe *pipe;
-			struct usb2_endpoint_descriptor *ed;
-			uint8_t iface_index;
-			uint8_t isread;
-
-			if (pd->ep_index >= f->fs_ep_max) {
+	case USB_FS_OPEN:
+			if (u.popen->ep_index >= f->fs_ep_max) {
 				error = EINVAL;
 				break;
 			}
-			if (f->fs_xfer[pd->ep_index] != NULL) {
+			if (f->fs_xfer[u.popen->ep_index] != NULL) {
 				error = EBUSY;
 				break;
 			}
-			if (pd->max_bufsize > USB_FS_MAX_BUFSIZE) {
-				pd->max_bufsize = USB_FS_MAX_BUFSIZE;
+			if (u.popen->max_bufsize > USB_FS_MAX_BUFSIZE) {
+				u.popen->max_bufsize = USB_FS_MAX_BUFSIZE;
 			}
-			if (pd->max_frames > USB_FS_MAX_FRAMES) {
-				pd->max_frames = USB_FS_MAX_FRAMES;
+			if (u.popen->max_frames > USB_FS_MAX_FRAMES) {
+				u.popen->max_frames = USB_FS_MAX_FRAMES;
 				break;
 			}
-			if (pd->max_frames == 0) {
+			if (u.popen->max_frames == 0) {
 				error = EINVAL;
 				break;
 			}
-			pipe = usb2_get_pipe_by_addr(f->udev, pd->ep_no);
+			pipe = usb2_get_pipe_by_addr(f->udev, u.popen->ep_no);
 			if (pipe == NULL) {
 				error = EINVAL;
 				break;
@@ -1530,7 +1529,7 @@
 			iface_index = pipe->iface_index;
 
 			error = usb2_check_thread_perm(f->udev, curthread, fflags,
-			    iface_index, pd->ep_no);
+			    iface_index, u.popen->ep_no);
 			if (error) {
 				break;
 			}
@@ -1543,8 +1542,8 @@
 			usb2_config[0].mh.flags.proxy_buffer = 1;
 			usb2_config[0].mh.callback = &ugen_default_fs_callback;
 			usb2_config[0].mh.timeout = 0;	/* no timeout */
-			usb2_config[0].mh.frames = pd->max_frames;
-			usb2_config[0].mh.bufsize = pd->max_bufsize;
+			usb2_config[0].mh.frames = u.popen->max_frames;
+			usb2_config[0].mh.bufsize = u.popen->max_bufsize;
 			usb2_config[0].md = usb2_config[0].mh;	/* symmetric config */
 
 			if (usb2_config[0].type == UE_CONTROL) {
@@ -1574,16 +1573,16 @@
 				}
 			}
 			error = usb2_transfer_setup(f->udev, &iface_index,
-			    f->fs_xfer + pd->ep_index, usb2_config, 1,
+			    f->fs_xfer + u.popen->ep_index, usb2_config, 1,
 			    f, f->priv_mtx);
 			if (error == 0) {
 				/* update maximums */
-				pd->max_packet_length =
-				    f->fs_xfer[pd->ep_index]->max_frame_size;
-				pd->max_bufsize =
-				    f->fs_xfer[pd->ep_index]->max_data_length;
-				f->fs_xfer[pd->ep_index]->priv_fifo =
-				    ((uint8_t *)0) + pd->ep_index;
+				u.popen->max_packet_length =
+				    f->fs_xfer[u.popen->ep_index]->max_frame_size;
+				u.popen->max_bufsize =
+				    f->fs_xfer[u.popen->ep_index]->max_data_length;
+				f->fs_xfer[u.popen->ep_index]->priv_fifo =
+				    ((uint8_t *)0) + u.popen->ep_index;
 				/*
 				 * Increase performance by dropping locks we
 				 * don't need:
@@ -1593,33 +1592,25 @@
 				error = ENOMEM;
 			}
 			break;
-		}
 
-	case USB_FS_CLOSE:{
-			struct usb2_fs_close *pd = addr;
-
-			if (pd->ep_index >= f->fs_ep_max) {
+	case USB_FS_CLOSE:
+			if (u.pclose->ep_index >= f->fs_ep_max) {
 				error = EINVAL;
 				break;
 			}
-			if (f->fs_xfer[pd->ep_index] == NULL) {
+			if (f->fs_xfer[u.pclose->ep_index] == NULL) {
 				error = EINVAL;
 				break;
 			}
-			usb2_transfer_unsetup(f->fs_xfer + pd->ep_index, 1);
+			usb2_transfer_unsetup(f->fs_xfer + u.pclose->ep_index, 1);
 			break;
-		}
 
-	case USB_FS_CLEAR_STALL_SYNC:{
-			struct usb2_fs_clear_stall_sync *pd = addr;
-			struct usb2_pipe *pipe;
-			struct usb2_device_request req;
-
-			if (pd->ep_index >= f->fs_ep_max) {
+	case USB_FS_CLEAR_STALL_SYNC:
+			if (u.pstall->ep_index >= f->fs_ep_max) {
 				error = EINVAL;
 				break;
 			}
-			if (f->fs_xfer[pd->ep_index] == NULL) {
+			if (f->fs_xfer[u.pstall->ep_index] == NULL) {
 				error = EINVAL;
 				break;
 			}
@@ -1628,13 +1619,13 @@
 				break;
 			}
 			mtx_lock(f->priv_mtx);
-			error = usb2_transfer_pending(f->fs_xfer[pd->ep_index]);
+			error = usb2_transfer_pending(f->fs_xfer[u.pstall->ep_index]);
 			mtx_unlock(f->priv_mtx);
 
 			if (error) {
 				return (EBUSY);
 			}
-			pipe = f->fs_xfer[pd->ep_index]->pipe;
+			pipe = f->fs_xfer[u.pstall->ep_index]->pipe;
 
 			/* setup a clear-stall packet */
 			req.bmRequestType = UT_WRITE_ENDPOINT;
@@ -1651,7 +1642,6 @@
 				error = ENXIO;
 			}
 			break;
-		}
 
 	default:
 		error = ENOTTY;
@@ -1663,8 +1653,19 @@
 static int
 ugen_iface_ioctl(struct usb2_fifo *f, u_long cmd, void *addr, int fflags)
 {
+	union {
+		struct usb2_interface_descriptor *idesc;
+		struct usb2_endpoint_descriptor *ed;
+		struct usb2_alt_interface *ai;
+		int *pint;
+		void *addr;
+	} u;
+	struct usb2_interface *iface;
+	struct usb2_pipe *pipe;
 	int error = 0;
 
+	u.addr = addr;
+
 	switch (cmd) {
 	case USB_SET_SHORT_XFER:
 		if (f->xfer[0] || f->xfer[1]) {
@@ -1712,50 +1713,39 @@
 		*(int *)addr = f->bufsize;
 		break;
 
-	case USB_GET_INTERFACE_DESC:{
-			struct usb2_interface_descriptor *idesc = addr;
-			struct usb2_interface *iface;
-
+	case USB_GET_INTERFACE_DESC: 
 			iface = usb2_get_iface(f->udev, f->iface_index);
 			if (iface && iface->idesc) {
-				*idesc = *(iface->idesc);
+				*u.idesc = *(iface->idesc);
 			} else {
 				error = EIO;
 				break;
 			}
 			break;
-		}
+
+	case USB_GET_ENDPOINT_DESC:
 
-	case USB_GET_ENDPOINT_DESC:{
-			struct usb2_endpoint_descriptor *ed = addr;
-			struct usb2_pipe *pipe = f->priv_sc0;
+			pipe = f->priv_sc0;
 
 			if (pipe && pipe->edesc) {
-				*ed = *(pipe->edesc);
+				*u.ed = *pipe->edesc;
 			} else {
 				error = EINVAL;
 				break;
 			}
 			break;
-		}
 
-	case USB_SET_RX_STALL_FLAG:{
-			int *pv = addr;
-
-			if ((fflags & FREAD) && (*pv)) {
+	case USB_SET_RX_STALL_FLAG:
+			if ((fflags & FREAD) && (*u.pint)) {
 				f->flag_stall = 1;
 			}
 			break;
-		}
 
-	case USB_SET_TX_STALL_FLAG:{
-			int *pv = addr;
-
-			if ((fflags & FWRITE) && (*pv)) {
+	case USB_SET_TX_STALL_FLAG:
+			if ((fflags & FWRITE) && (*u.pint)) {
 				f->flag_stall = 1;
 			}
 			break;
-		}
 
 	default:
 		error = ENOTTY;
@@ -1767,8 +1757,22 @@
 static int
 ugen_ctrl_ioctl(struct usb2_fifo *f, u_long cmd, void *addr, int fflags)
 {
+	union {
+		struct usb2_interface_descriptor *idesc;
+		struct usb2_alt_interface *ai;
+		struct usb2_device_descriptor *ddesc;
+		struct usb2_config_descriptor *cdesc;
+ 		struct usb2_device_stats *stat;
+		uint32_t *ptime;
+		void *addr;
+	} u;
+	struct usb2_device_descriptor *dtemp;
+	struct usb2_config_descriptor *ctemp;
+	struct usb2_interface *iface;
+	int error = 0;
 	uint8_t n;
-	int error = 0;
+
+	u.addr = addr;
 
 	switch (cmd) {
 	case USB_DISCOVER:
@@ -1795,56 +1799,42 @@
 		error = ugen_set_config(f, *(int *)addr);
 		break;
 
-	case USB_GET_ALTINTERFACE:{
-			struct usb2_alt_interface *ai = addr;
-			struct usb2_interface *iface;
-
+	case USB_GET_ALTINTERFACE:
 			iface = usb2_get_iface(f->udev,
-			    ai->uai_interface_index);
+			    u.ai->uai_interface_index);
 			if (iface && iface->idesc) {
-				ai->uai_alt_index = iface->alt_index;
+				u.ai->uai_alt_index = iface->alt_index;
 			} else {
 				error = EINVAL;
 			}
 			break;
-		}
-	case USB_SET_ALTINTERFACE:{
-			struct usb2_alt_interface *ai = addr;
 
+	case USB_SET_ALTINTERFACE:
 			if (!(fflags & FWRITE)) {
 				error = EPERM;
 				break;
 			}
 			error = ugen_set_interface(f,
-			    ai->uai_interface_index, ai->uai_alt_index);
+			    u.ai->uai_interface_index, u.ai->uai_alt_index);
 			break;
-		}
 
-	case USB_GET_DEVICE_DESC:{
-			struct usb2_device_descriptor *ddesc = addr;
-			struct usb2_device_descriptor *temp;
-
-			temp = usb2_get_device_descriptor(f->udev);
-			if (!temp) {
+	case USB_GET_DEVICE_DESC:
+			dtemp = usb2_get_device_descriptor(f->udev);
+			if (!dtemp) {
 				error = EIO;
 				break;
 			}
-			*ddesc = *temp;
+			*u.ddesc = *dtemp;
 			break;
-		}
 
-	case USB_GET_CONFIG_DESC:{
-			struct usb2_config_descriptor *cdesc = addr;
-			struct usb2_config_descriptor *temp;
-
-			temp = usb2_get_config_descriptor(f->udev);
-			if (!temp) {
+	case USB_GET_CONFIG_DESC:
+			ctemp = usb2_get_config_descriptor(f->udev);
+			if (!ctemp) {
 				error = EIO;
 				break;
 			}
-			*cdesc = *temp;
+			*u.cdesc = *ctemp;
 			break;
-		}
 
 	case USB_GET_FULL_DESC:
 		error = ugen_get_cdesc(f, addr);
@@ -1872,30 +1862,24 @@
 		error = usb2_gen_fill_devicenames(f, addr);
 		break;
 
-	case USB_DEVICESTATS:{
-			struct usb2_device_stats *ustat = addr;
-
+	case USB_DEVICESTATS:
 			for (n = 0; n != 4; n++) {
 
-				ustat->uds_requests_fail[n] =
+				u.stat->uds_requests_fail[n] =
 				    f->udev->bus->stats_err.uds_requests[n];
 
-				ustat->uds_requests_ok[n] =
+				u.stat->uds_requests_ok[n] =
 				    f->udev->bus->stats_ok.uds_requests[n];
 			}
 			break;
-		}
 
 	case USB_DEVICEENUMERATE:
 		error = ugen_re_enumerate(f);
 		break;
 
-	case USB_GET_PLUGTIME:{
-			uint32_t *ptime = addr;
-
-			*ptime = f->udev->plugtime;
+	case USB_GET_PLUGTIME:
+			*u.ptime = f->udev->plugtime;
 			break;
-		}
 
 		/* ... more IOCTL's to come ! ... --hps */
 



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