Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a8d6f0a9 authored by Alan Cox's avatar Alan Cox Committed by Linus Torvalds
Browse files

usb-serial: Coding style

parent d60d4396
Loading
Loading
Loading
Loading
+164 −140
Original line number Diff line number Diff line
@@ -12,7 +12,8 @@
 * This driver was originally based on the ACM driver by Armin Fuerst (which was
 * based on a driver by Brad Keryan)
 *
 * See Documentation/usb/usb-serial.txt for more information on using this driver
 * See Documentation/usb/usb-serial.txt for more information on using this
 * driver
 *
 */

@@ -28,7 +29,7 @@
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/list.h>
#include <asm/uaccess.h>
#include <linux/uaccess.h>
#include <linux/usb.h>
#include <linux/usb/serial.h>
#include "pl2303.h"
@@ -59,7 +60,8 @@ static struct usb_driver usb_serial_driver = {
*/

static int debug;
static struct usb_serial *serial_table[SERIAL_TTY_MINORS];	/* initially all NULL */
/* initially all NULL */
static struct usb_serial *serial_table[SERIAL_TTY_MINORS];
static DEFINE_MUTEX(table_lock);
static LIST_HEAD(usb_serial_driver_list);

@@ -76,7 +78,8 @@ struct usb_serial *usb_serial_get_by_index(unsigned index)
	return serial;
}

static struct usb_serial *get_free_serial (struct usb_serial *serial, int num_ports, unsigned int *minor)
static struct usb_serial *get_free_serial(struct usb_serial *serial,
					int num_ports, unsigned int *minor)
{
	unsigned int i, j;
	int good_spot;
@@ -122,10 +125,9 @@ static void return_serial(struct usb_serial *serial)
	if (serial == NULL)
		return;

	for (i = 0; i < serial->num_ports; ++i) {
	for (i = 0; i < serial->num_ports; ++i)
		serial_table[serial->minor + i] = NULL;
}
}

static void destroy_serial(struct kref *kref)
{
@@ -156,7 +158,8 @@ static void destroy_serial(struct kref *kref)
	 * not get cleaned up in port_release() as it was never registered with
	 * the driver core */
	if (serial->num_ports < serial->num_port_pointers) {
		for (i = serial->num_ports; i < serial->num_port_pointers; ++i) {
		for (i = serial->num_ports;
					i < serial->num_port_pointers; ++i) {
			port = serial->port[i];
			if (!port)
				continue;
@@ -294,7 +297,8 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
	usb_serial_put(port->serial);
}

static int serial_write (struct tty_struct * tty, const unsigned char *buf, int count)
static int serial_write(struct tty_struct *tty, const unsigned char *buf,
								int count)
{
	struct usb_serial_port *port = tty->driver_data;
	int retval = -ENODEV;
@@ -356,7 +360,8 @@ static void serial_unthrottle (struct tty_struct * tty)
		port->serial->type->unthrottle(tty);
}

static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg)
static int serial_ioctl(struct tty_struct *tty, struct file *file,
					unsigned int cmd, unsigned long arg)
{
	struct usb_serial_port *port = tty->driver_data;
	int retval = -ENODEV;
@@ -365,13 +370,13 @@ static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned in

	WARN_ON(!port->port.count);

	/* pass on to the driver specific version of this function if it is available */
	/* pass on to the driver specific version of this function
	   if it is available */
	if (port->serial->type->ioctl) {
		lock_kernel();
		retval = port->serial->type->ioctl(tty, file, cmd, arg);
		unlock_kernel();
	}
	else
	} else
		retval = -ENOIOCTLCMD;
	return retval;
}
@@ -382,7 +387,8 @@ static void serial_set_termios (struct tty_struct *tty, struct ktermios * old)
	dbg("%s - port %d", __func__, port->number);

	WARN_ON(!port->port.count);
	/* pass on to the driver specific version of this function if it is available */
	/* pass on to the driver specific version of this function
	   if it is available */
	if (port->serial->type->set_termios)
		port->serial->type->set_termios(tty, port, old);
	else
@@ -396,7 +402,8 @@ static void serial_break (struct tty_struct *tty, int break_state)
	dbg("%s - port %d", __func__, port->number);

	WARN_ON(!port->port.count);
	/* pass on to the driver specific version of this function if it is available */
	/* pass on to the driver specific version of this function
	   if it is available */
	if (port->serial->type->break_ctl) {
		lock_kernel();
		port->serial->type->break_ctl(tty, break_state);
@@ -404,7 +411,8 @@ static void serial_break (struct tty_struct *tty, int break_state)
	}
}

static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data)
static int serial_read_proc(char *page, char **start, off_t off, int count,
							int *eof, void *data)
{
	struct usb_serial *serial;
	int length = 0;
@@ -421,14 +429,17 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int

		length += sprintf(page+length, "%d:", i);
		if (serial->type->driver.owner)
			length += sprintf (page+length, " module:%s", module_name(serial->type->driver.owner));
		length += sprintf (page+length, " name:\"%s\"", serial->type->description);
			length += sprintf(page+length, " module:%s",
				module_name(serial->type->driver.owner));
		length += sprintf(page+length, " name:\"%s\"",
				serial->type->description);
		length += sprintf(page+length, " vendor:%04x product:%04x",
			le16_to_cpu(serial->dev->descriptor.idVendor),
			le16_to_cpu(serial->dev->descriptor.idProduct));
		length += sprintf (page+length, " num_ports:%d", serial->num_ports);
		length += sprintf (page+length, " port:%d", i - serial->minor + 1);

		length += sprintf(page+length, " num_ports:%d",
							serial->num_ports);
		length += sprintf(page+length, " port:%d",
							i - serial->minor + 1);
		usb_make_path(serial->dev, tmp, sizeof(tmp));
		length += sprintf(page+length, " path:%s", tmp);

@@ -448,7 +459,7 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int
	if (off >= (length + begin))
		return 0;
	*start = page + (off-begin);
	return ((count < begin+length-off) ? count : begin+length-off);
	return (count < begin+length-off) ? count : begin+length-off;
}

static int serial_tiocmget(struct tty_struct *tty, struct file *file)
@@ -485,6 +496,7 @@ void usb_serial_port_softint(struct usb_serial_port *port)
{
	schedule_work(&port->work);
}
EXPORT_SYMBOL_GPL(usb_serial_port_softint);

static void usb_serial_port_work(struct work_struct *work)
{
@@ -599,7 +611,8 @@ static const struct usb_device_id *get_iface_id(struct usb_serial_driver *drv,
	return id;
}

static struct usb_serial_driver *search_serial_device(struct usb_interface *iface)
static struct usb_serial_driver *search_serial_device(
					struct usb_interface *iface)
{
	const struct usb_device_id *id;
	struct usb_serial_driver *drv;
@@ -659,7 +672,8 @@ int usb_serial_probe(struct usb_interface *interface,

		if (!try_module_get(type->driver.owner)) {
			unlock_kernel();
			dev_err(&interface->dev, "module get failed, exiting\n");
			dev_err(&interface->dev,
				"module get failed, exiting\n");
			kfree(serial);
			return -EIO;
		}
@@ -753,7 +767,8 @@ int usb_serial_probe(struct usb_interface *interface,
		num_ports = num_bulk_out;
		if (num_ports == 0) {
			unlock_kernel();
			dev_err(&interface->dev, "Generic device with no bulk out, not allowed.\n");
			dev_err(&interface->dev,
			    "Generic device with no bulk out, not allowed.\n");
			kfree(serial);
			return -EIO;
		}
@@ -764,7 +779,8 @@ int usb_serial_probe(struct usb_interface *interface,
		if (type->calc_num_ports) {
			if (!try_module_get(type->driver.owner)) {
				unlock_kernel();
				dev_err(&interface->dev, "module get failed, exiting\n");
				dev_err(&interface->dev,
					"module get failed, exiting\n");
				kfree(serial);
				return -EIO;
			}
@@ -786,7 +802,8 @@ int usb_serial_probe(struct usb_interface *interface,
			type->description);

	/* create our ports, we need as many as the max endpoints */
	/* we don't use num_ports here cauz some devices have more endpoint pairs than ports */
	/* we don't use num_ports here because some devices have more
	   endpoint pairs than ports */
	max_endpoints = max(num_bulk_in, num_bulk_out);
	max_endpoints = max(max_endpoints, num_interrupt_in);
	max_endpoints = max(max_endpoints, num_interrupt_out);
@@ -794,7 +811,8 @@ int usb_serial_probe(struct usb_interface *interface,
	serial->num_port_pointers = max_endpoints;
	unlock_kernel();

	dbg("%s - setting up %d port structures for this device", __func__, max_endpoints);
	dbg("%s - setting up %d port structures for this device",
						__func__, max_endpoints);
	for (i = 0; i < max_endpoints; ++i) {
		port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL);
		if (!port)
@@ -820,15 +838,15 @@ int usb_serial_probe(struct usb_interface *interface,
		port->bulk_in_endpointAddress = endpoint->bEndpointAddress;
		port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
		if (!port->bulk_in_buffer) {
			dev_err(&interface->dev, "Couldn't allocate bulk_in_buffer\n");
			dev_err(&interface->dev,
					"Couldn't allocate bulk_in_buffer\n");
			goto probe_error;
		}
		usb_fill_bulk_urb(port->read_urb, dev,
				usb_rcvbulkpipe(dev,
						endpoint->bEndpointAddress),
				port->bulk_in_buffer, buffer_size,
				   serial->type->read_bulk_callback,
				   port);
				serial->type->read_bulk_callback, port);
	}

	for (i = 0; i < num_bulk_out; ++i) {
@@ -844,15 +862,15 @@ int usb_serial_probe(struct usb_interface *interface,
		port->bulk_out_endpointAddress = endpoint->bEndpointAddress;
		port->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
		if (!port->bulk_out_buffer) {
			dev_err(&interface->dev, "Couldn't allocate bulk_out_buffer\n");
			dev_err(&interface->dev,
					"Couldn't allocate bulk_out_buffer\n");
			goto probe_error;
		}
		usb_fill_bulk_urb(port->write_urb, dev,
				usb_sndbulkpipe(dev,
					endpoint->bEndpointAddress),
				port->bulk_out_buffer, buffer_size,
				   serial->type->write_bulk_callback,
				   port);
				serial->type->write_bulk_callback, port);
	}

	if (serial->type->read_int_callback) {
@@ -861,14 +879,18 @@ int usb_serial_probe(struct usb_interface *interface,
			port = serial->port[i];
			port->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
			if (!port->interrupt_in_urb) {
				dev_err(&interface->dev, "No free urbs available\n");
				dev_err(&interface->dev,
						"No free urbs available\n");
				goto probe_error;
			}
			buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
			port->interrupt_in_endpointAddress = endpoint->bEndpointAddress;
			port->interrupt_in_buffer = kmalloc (buffer_size, GFP_KERNEL);
			port->interrupt_in_endpointAddress =
						endpoint->bEndpointAddress;
			port->interrupt_in_buffer = kmalloc(buffer_size,
								GFP_KERNEL);
			if (!port->interrupt_in_buffer) {
				dev_err(&interface->dev, "Couldn't allocate interrupt_in_buffer\n");
				dev_err(&interface->dev,
				    "Couldn't allocate interrupt_in_buffer\n");
				goto probe_error;
			}
			usb_fill_int_urb(port->interrupt_in_urb, dev,
@@ -888,15 +910,19 @@ int usb_serial_probe(struct usb_interface *interface,
			port = serial->port[i];
			port->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
			if (!port->interrupt_out_urb) {
				dev_err(&interface->dev, "No free urbs available\n");
				dev_err(&interface->dev,
						"No free urbs available\n");
				goto probe_error;
			}
			buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
			port->interrupt_out_size = buffer_size;
			port->interrupt_out_endpointAddress = endpoint->bEndpointAddress;
			port->interrupt_out_buffer = kmalloc (buffer_size, GFP_KERNEL);
			port->interrupt_out_endpointAddress =
						endpoint->bEndpointAddress;
			port->interrupt_out_buffer = kmalloc(buffer_size,
								GFP_KERNEL);
			if (!port->interrupt_out_buffer) {
				dev_err(&interface->dev, "Couldn't allocate interrupt_out_buffer\n");
				dev_err(&interface->dev,
				  "Couldn't allocate interrupt_out_buffer\n");
				goto probe_error;
			}
			usb_fill_int_urb(port->interrupt_out_urb, dev,
@@ -913,7 +939,8 @@ int usb_serial_probe(struct usb_interface *interface,
	/* if this device type has an attach function, call it */
	if (type->attach) {
		if (!try_module_get(type->driver.owner)) {
			dev_err(&interface->dev, "module get failed, exiting\n");
			dev_err(&interface->dev,
					"module get failed, exiting\n");
			goto probe_error;
		}
		retval = type->attach(serial);
@@ -921,8 +948,8 @@ int usb_serial_probe(struct usb_interface *interface,
		if (retval < 0)
			goto probe_error;
		if (retval > 0) {
			/* quietly accept this device, but don't bind to a serial port
			 * as it's about to disappear */
			/* quietly accept this device, but don't bind to a
			   serial port as it's about to disappear */
			goto exit;
		}
	}
@@ -992,6 +1019,7 @@ int usb_serial_probe(struct usb_interface *interface,
	kfree(serial);
	return -EIO;
}
EXPORT_SYMBOL_GPL(usb_serial_probe);

void usb_serial_disconnect(struct usb_interface *interface)
{
@@ -1021,6 +1049,7 @@ void usb_serial_disconnect(struct usb_interface *interface)
	usb_serial_put(serial);
	dev_info(dev, "device disconnected\n");
}
EXPORT_SYMBOL_GPL(usb_serial_disconnect);

int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
{
@@ -1079,9 +1108,8 @@ static int __init usb_serial_init(void)
		return -ENOMEM;

	/* Initialize our global data */
	for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
	for (i = 0; i < SERIAL_TTY_MINORS; ++i)
		serial_table[i] = NULL;
	}

	result = bus_register(&usb_serial_bus_type);
	if (result) {
@@ -1096,9 +1124,11 @@ static int __init usb_serial_init(void)
	usb_serial_tty_driver->minor_start = 0;
	usb_serial_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
	usb_serial_tty_driver->subtype = SERIAL_TYPE_NORMAL;
	usb_serial_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
	usb_serial_tty_driver->flags = TTY_DRIVER_REAL_RAW |
						TTY_DRIVER_DYNAMIC_DEV;
	usb_serial_tty_driver->init_termios = tty_std_termios;
	usb_serial_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
	usb_serial_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD
							| HUPCL | CLOCAL;
	usb_serial_tty_driver->init_termios.c_ispeed = 9600;
	usb_serial_tty_driver->init_termios.c_ospeed = 9600;
	tty_set_operations(usb_serial_tty_driver, &serial_ops);
@@ -1180,8 +1210,9 @@ static void fixup_generic(struct usb_serial_driver *device)
	set_to_generic_if_null(device, resume);
}

int usb_serial_register(struct usb_serial_driver *driver) /* must be called with BKL held */
int usb_serial_register(struct usb_serial_driver *driver)
{
	/* must be called with BKL held */
	int retval;

	fixup_generic(driver);
@@ -1194,33 +1225,26 @@ int usb_serial_register(struct usb_serial_driver *driver) /* must be called with

	retval = usb_serial_bus_register(driver);
	if (retval) {
		err("problem %d when registering driver %s", retval, driver->description);
		err("problem %d when registering driver %s",
						retval, driver->description);
		list_del(&driver->driver_list);
	}
	else
		info("USB Serial support registered for %s", driver->description);
	} else
		info("USB Serial support registered for %s",
						driver->description);

	return retval;
}
EXPORT_SYMBOL_GPL(usb_serial_register);


void usb_serial_deregister(struct usb_serial_driver *device) /* must be called with BKL held */
void usb_serial_deregister(struct usb_serial_driver *device)
{
	/* must be called with BKL held */
	info("USB Serial deregistering driver %s", device->description);
	list_del(&device->driver_list);
	usb_serial_bus_deregister(device);
}



/* If the usb-serial core is built into the core, the usb-serial drivers
   need these symbols to load properly as modules. */
EXPORT_SYMBOL_GPL(usb_serial_register);
EXPORT_SYMBOL_GPL(usb_serial_deregister);
EXPORT_SYMBOL_GPL(usb_serial_probe);
EXPORT_SYMBOL_GPL(usb_serial_disconnect);
EXPORT_SYMBOL_GPL(usb_serial_port_softint);


/* Module information */
MODULE_AUTHOR(DRIVER_AUTHOR);