[PATCH 1/2][HIRSUTE] UBUNTU: SAUCE: xr-usb-serial: clean up indentation

Colin King colin.king at canonical.com
Fri Mar 26 16:54:40 UTC 2021


From: Colin Ian King <colin.king at canonical.com>

Cosmetic changes, clean up indentation to make the code easier
to read.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 ubuntu/xr-usb-serial/xr_usb_serial_common.c | 202 +++++++++-----------
 1 file changed, 93 insertions(+), 109 deletions(-)

diff --git a/ubuntu/xr-usb-serial/xr_usb_serial_common.c b/ubuntu/xr-usb-serial/xr_usb_serial_common.c
index d16f072613b1..791cdb74cc41 100644
--- a/ubuntu/xr-usb-serial/xr_usb_serial_common.c
+++ b/ubuntu/xr-usb-serial/xr_usb_serial_common.c
@@ -13,7 +13,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
- 
+
   /*
  * Copyright (c) 2015 Exar Corporation, Inc.
  *
@@ -23,8 +23,8 @@
  *	XR21B1420/1422/1424
  *	XR22801/802/804
  *
- * The driver has been tested on various kernel versions from 3.6.x to 3.17.x.  
- * This driver may work on newer versions as well.  There is a different driver available 
+ * The driver has been tested on various kernel versions from 3.6.x to 3.17.x.
+ * This driver may work on newer versions as well.  There is a different driver available
  * from www.exar.com that will work with kernel versions 2.6.18 to 3.4.x.
  *
  * ChangeLog:
@@ -305,14 +305,12 @@ static void xr_usb_serial_ctrl_irq(struct urb *urb)
 	int status = urb->status;
 	int i;
 	unsigned char *p;
-		
+
 	switch (status) {
 	case 0:
 		p = (unsigned char *)(urb->transfer_buffer);
-		for(i=0;i<urb->actual_length;i++)
-	    {
-          dev_dbg(&xr_usb_serial->control->dev,"0x%02x\n",p[i]);
-	    }
+		for (i=0;i<urb->actual_length;i++)
+			dev_dbg(&xr_usb_serial->control->dev,"0x%02x\n",p[i]);
 		/* success */
 		break;
 	case -ECONNRESET:
@@ -340,18 +338,17 @@ static void xr_usb_serial_ctrl_irq(struct urb *urb)
 		break;
 
 	case USB_CDC_NOTIFY_SERIAL_STATE:
-#if LINUX_VERSION_CODE > KERNEL_VERSION(3, 9, 0)		
+#if LINUX_VERSION_CODE > KERNEL_VERSION(3, 9, 0)
 		newctrl = get_unaligned_le16(data);
-    	if (!xr_usb_serial->clocal && (xr_usb_serial->ctrlin & ~newctrl & XR_USB_SERIAL_CTRL_DCD)) {
+		if (!xr_usb_serial->clocal && (xr_usb_serial->ctrlin & ~newctrl & XR_USB_SERIAL_CTRL_DCD)) {
 			dev_dbg(&xr_usb_serial->control->dev, "%s - calling hangup\n",
 					__func__);
 			tty_port_tty_hangup(&xr_usb_serial->port, false);
 		}
-#else		
+#else
 		tty = tty_port_tty_get(&xr_usb_serial->port);
-        newctrl = get_unaligned_le16(data);
-		if (tty)
-		{
+		newctrl = get_unaligned_le16(data);
+		if (tty) {
 			if (!xr_usb_serial->clocal &&
 				(xr_usb_serial->ctrlin & ~newctrl & XR_USB_SERIAL_CTRL_DCD)) {
 				dev_dbg(&xr_usb_serial->control->dev,
@@ -430,15 +427,15 @@ static int xr_usb_serial_submit_read_urbs(struct xr_usb_serial *xr_usb_serial, g
 }
 static void xr_usb_serial_process_read_urb(struct xr_usb_serial *xr_usb_serial, struct urb *urb)
 {
-    struct tty_struct *tty;
+	struct tty_struct *tty;
 	if (!urb->actual_length)
 		return;
-#if LINUX_VERSION_CODE > KERNEL_VERSION(3, 9, 0)    
+#if LINUX_VERSION_CODE > KERNEL_VERSION(3, 9, 0)
 	tty_insert_flip_string(&xr_usb_serial->port, urb->transfer_buffer,
 			urb->actual_length);
 	tty_flip_buffer_push(&xr_usb_serial->port);
 #else
-    tty = tty_port_tty_get(&xr_usb_serial->port);
+	tty = tty_port_tty_get(&xr_usb_serial->port);
 	if (!tty)
 		return;
 	tty_insert_flip_string(tty, urb->transfer_buffer, urb->actual_length);
@@ -505,18 +502,18 @@ static void xr_usb_serial_write_bulk(struct urb *urb)
 static void xr_usb_serial_softint(struct work_struct *work)
 {
 	struct xr_usb_serial *xr_usb_serial = container_of(work, struct xr_usb_serial, work);
-    struct tty_struct *tty;
-	
+	struct tty_struct *tty;
+
 	dev_vdbg(&xr_usb_serial->data->dev, "%s\n", __func__);
 #if LINUX_VERSION_CODE > KERNEL_VERSION(3, 9, 0)
 	tty_port_tty_wakeup(&xr_usb_serial->port);
-#else	
+#else
 	tty = tty_port_tty_get(&xr_usb_serial->port);
 	if (!tty)
 		return;
 	tty_wakeup(tty);
 	tty_kref_put(tty);
-#endif	
+#endif
 }
 
 /*
@@ -625,9 +622,9 @@ static void xr_usb_serial_port_destruct(struct tty_port *port)
 	struct xr_usb_serial *xr_usb_serial = container_of(port, struct xr_usb_serial, port);
 
 	dev_dbg(&xr_usb_serial->control->dev, "%s\n", __func__);
-    #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
 	tty_unregister_device(xr_usb_serial_tty_driver, xr_usb_serial->minor);
-	#endif
+#endif
 	xr_usb_serial_release_minor(xr_usb_serial);
 	usb_put_intf(xr_usb_serial->control);
 	kfree(xr_usb_serial->country_codes);
@@ -794,8 +791,7 @@ static int xr_usb_serial_tty_tiocmget(struct tty_struct *tty)
 {
 	struct xr_usb_serial *xr_usb_serial = tty->driver_data;
 	dev_dbg(&xr_usb_serial->control->dev, "xr_usb_serial_tty_tiocmget\n");
-    return xr_usb_serial_tiocmget(xr_usb_serial);
-
+	return xr_usb_serial_tiocmget(xr_usb_serial);
 }
 
 static int xr_usb_serial_tty_tiocmset(struct tty_struct *tty,
@@ -803,8 +799,7 @@ static int xr_usb_serial_tty_tiocmset(struct tty_struct *tty,
 {
 	struct xr_usb_serial *xr_usb_serial = tty->driver_data;
 	dev_dbg(&xr_usb_serial->control->dev, "xr_usb_serial_tty_tiocmset set=0x%x clear=0x%x\n",set,clear);
-    return xr_usb_serial_tiocmset(xr_usb_serial,set,clear);
-
+	return xr_usb_serial_tiocmset(xr_usb_serial,set,clear);
 }
 
 static int get_serial_info(struct xr_usb_serial *xr_usb_serial, struct serial_struct __user *info)
@@ -865,9 +860,9 @@ static int xr_usb_serial_tty_ioctl(struct tty_struct *tty,
 {
 	struct xr_usb_serial *xr_usb_serial = tty->driver_data;
 	int rv = -ENOIOCTLCMD;
-    unsigned int  channel, reg, val;
+	unsigned int channel, reg, val;
+	short *data;
 
-    short	*data;
 	switch (cmd) {
 	case TIOCGSERIAL: /* gets serial port data */
 		rv = get_serial_info(xr_usb_serial, (struct serial_struct __user *) arg);
@@ -875,7 +870,7 @@ static int xr_usb_serial_tty_ioctl(struct tty_struct *tty,
 	case TIOCSSERIAL:
 		rv = set_serial_info(xr_usb_serial, (struct serial_struct __user *) arg);
 		break;
-    case XR_USB_SERIAL_GET_REG:
+	case XR_USB_SERIAL_GET_REG:
                 if (get_user(channel, (int __user *)arg))
                         return -EFAULT;
                 if (get_user(reg, (int __user *)(arg + sizeof(int))))
@@ -886,31 +881,27 @@ static int xr_usb_serial_tty_ioctl(struct tty_struct *tty,
                         dev_err(&xr_usb_serial->control->dev, "%s - Cannot allocate USB buffer.\n", __func__);
                         return -ENOMEM;
 		}
-        			
-		        if (channel == -1)
-		        {
-		          rv = xr_usb_serial_get_reg(xr_usb_serial,reg, data);
-		        }
-				else
-				{
-			  	  rv = xr_usb_serial_get_reg_ext(xr_usb_serial,channel,reg, data);
-				}
+
+		if (channel == -1) {
+		         rv = xr_usb_serial_get_reg(xr_usb_serial,reg, data);
+		} else {
+			rv = xr_usb_serial_get_reg_ext(xr_usb_serial,channel,reg, data);
+		}
                 if (rv != 1) {
                         dev_err(&xr_usb_serial->control->dev, "Cannot get register (%d)\n", rv);
                         kfree(data);
                         return -EFAULT;
                 }
-				if (put_user(le16_to_cpu(*data), (int __user *)(arg + 2 * sizeof(int))))
-              	{
-                   dev_err(&xr_usb_serial->control->dev, "Cannot put user result\n");
-                   kfree(data);
-                   return -EFAULT;
+		if (put_user(le16_to_cpu(*data), (int __user *)(arg + 2 * sizeof(int)))) {
+			dev_err(&xr_usb_serial->control->dev, "Cannot put user result\n");
+			kfree(data);
+			return -EFAULT;
                 }
                 rv = 0;
                 kfree(data);
                 break;
 
-      case XR_USB_SERIAL_SET_REG:
+	case XR_USB_SERIAL_SET_REG:
                 if (get_user(channel, (int __user *)arg))
                         return -EFAULT;
                 if (get_user(reg, (int __user *)(arg + sizeof(int))))
@@ -918,30 +909,25 @@ static int xr_usb_serial_tty_ioctl(struct tty_struct *tty,
                 if (get_user(val, (int __user *)(arg + 2 * sizeof(int))))
                         return -EFAULT;
 
-			if (channel == -1)
-			{
-				rv = xr_usb_serial_set_reg(xr_usb_serial,reg, val);
-			}
-			else
-			{
-			 	rv = xr_usb_serial_set_reg_ext(xr_usb_serial,channel,reg, val);
-				
-			}
-		    if (rv < 0)
-               return -EFAULT;  
-			rv = 0;
-            break;
+		if (channel == -1) {
+			rv = xr_usb_serial_set_reg(xr_usb_serial,reg, val);
+		} else {
+			rv = xr_usb_serial_set_reg_ext(xr_usb_serial,channel,reg, val);
+		}
+		if (rv < 0)
+			return -EFAULT;
+		rv = 0;
+		break;
 	case XR_USB_SERIAL_LOOPBACK:
-		     if (get_user(channel, (int __user *)arg))
-                        return -EFAULT;
-		     if (channel == -1)
-			   channel = xr_usb_serial->channel;
-			 rv = xr_usb_serial_set_loopback(xr_usb_serial,channel);
-			 if (rv < 0)
-               return -EFAULT;
-			 rv = 0;
-		     break;
-		
+		if (get_user(channel, (int __user *)arg))
+			return -EFAULT;
+		if (channel == -1)
+			channel = xr_usb_serial->channel;
+		rv = xr_usb_serial_set_loopback(xr_usb_serial,channel);
+		if (rv < 0)
+			return -EFAULT;
+		rv = 0;
+		break;
 	}
 
 	return rv;
@@ -951,15 +937,15 @@ static void xr_usb_serial_tty_set_termios(struct tty_struct *tty,
 						struct ktermios *termios_old)
 {
 	struct xr_usb_serial *xr_usb_serial = tty->driver_data;
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)	
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
 	struct ktermios *termios = tty->termios;
 #else
-    struct ktermios *termios = &tty->termios;
+	struct ktermios *termios = &tty->termios;
 #endif
 	unsigned int   cflag = termios->c_cflag;
 	struct usb_cdc_line_coding newline;
 	int newctrl = xr_usb_serial->ctrlout;
-    xr_usb_serial_disable(xr_usb_serial);
+	xr_usb_serial_disable(xr_usb_serial);
 	newline.dwDTERate = cpu_to_le32(tty_get_baud_rate(tty));
 	newline.bCharFormat = termios->c_cflag & CSTOPB ? 1 : 0;
 	newline.bParityType = termios->c_cflag & PARENB ?
@@ -991,11 +977,10 @@ static void xr_usb_serial_tty_set_termios(struct tty_struct *tty,
 
 	if (newctrl != xr_usb_serial->ctrlout)
 		xr_usb_serial_set_control(xr_usb_serial, xr_usb_serial->ctrlout = newctrl);
-	
-    xr_usb_serial_set_flow_mode(xr_usb_serial,tty,cflag);/*set the serial flow mode*/
-	 	
-	if (memcmp(&xr_usb_serial->line, &newline, sizeof newline))
-	{
+
+	xr_usb_serial_set_flow_mode(xr_usb_serial,tty,cflag);/*set the serial flow mode*/
+
+	if (memcmp(&xr_usb_serial->line, &newline, sizeof newline)) {
 		memcpy(&xr_usb_serial->line, &newline, sizeof newline);
 		dev_dbg(&xr_usb_serial->control->dev, "%s - set line: %d %d %d %d\n",
 			__func__,
@@ -1095,9 +1080,9 @@ static int xr_usb_serial_probe(struct usb_interface *intf,
 		return -ENODEV;
 
 	num_rx_buf = (quirks == SINGLE_RX_URB) ? 1 : XR_USB_SERIAL_NR;
-	
-    dev_dbg(&intf->dev, "USB_device_id idVendor:%04x, idProduct %04x\n",id->idVendor,id->idProduct);
-	
+
+	dev_dbg(&intf->dev, "USB_device_id idVendor:%04x, idProduct %04x\n",id->idVendor,id->idProduct);
+
 	/* handle quirks deadly to normal probing*/
 	if (quirks == NO_UNION_NORMAL) {
 		data_interface = usb_ifnum_to_if(usb_dev, 1);
@@ -1322,23 +1307,20 @@ static int xr_usb_serial_probe(struct usb_interface *intf,
 	xr_usb_serial->port.ops = &xr_usb_serial_port_ops;
 	xr_usb_serial->DeviceVendor = id->idVendor;
 	xr_usb_serial->DeviceProduct = id->idProduct;
-	#if 0
-	if((xr_usb_serial->DeviceProduct&0xfff0) == 0x1410)
-	{//map the serial port A B C D to blocknum 0 1 2 3 for the xr21v141x device
-	    xr_usb_serial->channel = epwrite->bEndpointAddress - 1;
-	}
-	else if((xr_usb_serial->DeviceProduct&0xfff0) == 0x1420)
-	{//map the serial port A B C D to blocknum 0 2 4 6 for the xr21B142x device
-	    xr_usb_serial->channel = (epwrite->bEndpointAddress - 4)*2;
-	}
-	else
-	{
-	   xr_usb_serial->channel = epwrite->bEndpointAddress;
+#if 0
+	if ((xr_usb_serial->DeviceProduct&0xfff0) == 0x1410) {
+		//map the serial port A B C D to blocknum 0 1 2 3 for the xr21v141x device
+		xr_usb_serial->channel = epwrite->bEndpointAddress - 1;
+	} else if ((xr_usb_serial->DeviceProduct&0xfff0) == 0x1420) {
+		//map the serial port A B C D to blocknum 0 2 4 6 for the xr21B142x device
+		xr_usb_serial->channel = (epwrite->bEndpointAddress - 4)*2;
+	} else {
+		xr_usb_serial->channel = epwrite->bEndpointAddress;
 	}
-	#else
+#else
 	xr_usb_serial->channel = epwrite->bEndpointAddress;
 	dev_dbg(&intf->dev, "epwrite->bEndpointAddress =%d\n",epwrite->bEndpointAddress);
-	#endif
+#endif
 	buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &xr_usb_serial->ctrl_dma);
 	if (!buf) {
 		dev_err(&intf->dev, "out of memory (ctrl buffer alloc)\n");
@@ -1408,16 +1390,18 @@ static int xr_usb_serial_probe(struct usb_interface *intf,
 
 		if (usb_endpoint_xfer_int(epwrite))
 			usb_fill_int_urb(snd->urb, usb_dev,
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)			
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
 				usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),
 #else
-                usb_sndintpipe(usb_dev, epwrite->bEndpointAddress),
+			usb_sndintpipe(usb_dev, epwrite->bEndpointAddress),
 #endif
-				NULL, xr_usb_serial->writesize, xr_usb_serial_write_bulk, snd, epwrite->bInterval);
+				NULL, xr_usb_serial->writesize,
+				xr_usb_serial_write_bulk, snd, epwrite->bInterval);
 		else
 			usb_fill_bulk_urb(snd->urb, usb_dev,
 				usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),
-				NULL, xr_usb_serial->writesize, xr_usb_serial_write_bulk, snd);
+				NULL, xr_usb_serial->writesize,
+				xr_usb_serial_write_bulk, snd);
 		snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
 		snd->instance = xr_usb_serial;
 	}
@@ -1471,15 +1455,15 @@ static int xr_usb_serial_probe(struct usb_interface *intf,
 	xr_usb_serial->ctrlurb->transfer_dma = xr_usb_serial->ctrl_dma;
 
 	dev_info(&intf->dev, "ttyXR_USB_SERIAL%d: USB XR_USB_SERIAL device\n", minor);
-	
-    xr_usb_serial_pre_setup(xr_usb_serial);
-	
+
+	xr_usb_serial_pre_setup(xr_usb_serial);
+
 	xr_usb_serial_set_control(xr_usb_serial, xr_usb_serial->ctrlout);
 
 	xr_usb_serial->line.dwDTERate = cpu_to_le32(9600);
 	xr_usb_serial->line.bDataBits = 8;
 	xr_usb_serial_set_line(xr_usb_serial, &xr_usb_serial->line);
-    
+
 	usb_driver_claim_interface(&xr_usb_serial_driver, data_interface, xr_usb_serial);
 	usb_set_intfdata(data_interface, xr_usb_serial);
 
@@ -1493,7 +1477,7 @@ static int xr_usb_serial_probe(struct usb_interface *intf,
 		rv = PTR_ERR(tty_dev);
 		goto alloc_fail9;
 	}
-#endif	
+#endif
 
 	return 0;
 alloc_fail9:
@@ -1670,9 +1654,9 @@ static int xr_usb_serial_resume(struct usb_interface *intf)
 static int xr_usb_serial_reset_resume(struct usb_interface *intf)
 {
 	struct xr_usb_serial *xr_usb_serial = usb_get_intfdata(intf);
-    struct tty_struct *tty;
+	struct tty_struct *tty;
 	if (test_bit(ASYNCB_INITIALIZED, &xr_usb_serial->port.flags)){
-#if LINUX_VERSION_CODE > KERNEL_VERSION(3, 9, 0)	
+#if LINUX_VERSION_CODE > KERNEL_VERSION(3, 9, 0)
 	tty_port_tty_hangup(&xr_usb_serial->port, false);
 #else
  	tty = tty_port_tty_get(&xr_usb_serial->port);
@@ -1692,17 +1676,17 @@ static int xr_usb_serial_reset_resume(struct usb_interface *intf)
  */
 static const struct usb_device_id xr_usb_serial_ids[] = {
 	{ USB_DEVICE(0x04e2, 0x1410)},
-    { USB_DEVICE(0x04e2, 0x1411)},
+	{ USB_DEVICE(0x04e2, 0x1411)},
 	{ USB_DEVICE(0x04e2, 0x1412)},
 	{ USB_DEVICE(0x04e2, 0x1414)},
 	{ USB_DEVICE(0x04e2, 0x1420)},
-    { USB_DEVICE(0x04e2, 0x1421)},
+	{ USB_DEVICE(0x04e2, 0x1421)},
 	{ USB_DEVICE(0x04e2, 0x1422)},
 	{ USB_DEVICE(0x04e2, 0x1424)},
 	{ USB_DEVICE(0x04e2, 0x1400)},
-    { USB_DEVICE(0x04e2, 0x1401)},
-    { USB_DEVICE(0x04e2, 0x1402)},
-    { USB_DEVICE(0x04e2, 0x1403)},
+	{ USB_DEVICE(0x04e2, 0x1401)},
+	{ USB_DEVICE(0x04e2, 0x1402)},
+	{ USB_DEVICE(0x04e2, 0x1403)},
 	{ }
 };
 
-- 
2.30.2




More information about the kernel-team mailing list