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

Commit f392ecfa authored by Arjan van de Ven's avatar Arjan van de Ven Committed by Russell King
Browse files

[SERIAL] turn serial semaphores into mutexes



Turn several drivers/serial/ semaphores-used-as-mutex into mutexes

Signed-off-by: default avatarArjan van de Ven <arjan@infradead.org>
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent 593195f9
Loading
Loading
Loading
Loading
+6 −5
Original line number Original line Diff line number Diff line
@@ -41,6 +41,7 @@
#include <linux/serial.h>
#include <linux/serial.h>
#include <linux/serial_8250.h>
#include <linux/serial_8250.h>
#include <linux/nmi.h>
#include <linux/nmi.h>
#include <linux/mutex.h>


#include <asm/io.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/irq.h>
@@ -2467,7 +2468,7 @@ static struct platform_device *serial8250_isa_devs;
 * 16x50 serial ports to be configured at run-time, to support PCMCIA
 * 16x50 serial ports to be configured at run-time, to support PCMCIA
 * modems and PCI multiport cards.
 * modems and PCI multiport cards.
 */
 */
static DECLARE_MUTEX(serial_sem);
static DEFINE_MUTEX(serial_mutex);


static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port *port)
static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port *port)
{
{
@@ -2522,7 +2523,7 @@ int serial8250_register_port(struct uart_port *port)
	if (port->uartclk == 0)
	if (port->uartclk == 0)
		return -EINVAL;
		return -EINVAL;


	down(&serial_sem);
	mutex_lock(&serial_mutex);


	uart = serial8250_find_match_or_unused(port);
	uart = serial8250_find_match_or_unused(port);
	if (uart) {
	if (uart) {
@@ -2544,7 +2545,7 @@ int serial8250_register_port(struct uart_port *port)
		if (ret == 0)
		if (ret == 0)
			ret = uart->port.line;
			ret = uart->port.line;
	}
	}
	up(&serial_sem);
	mutex_unlock(&serial_mutex);


	return ret;
	return ret;
}
}
@@ -2561,7 +2562,7 @@ void serial8250_unregister_port(int line)
{
{
	struct uart_8250_port *uart = &serial8250_ports[line];
	struct uart_8250_port *uart = &serial8250_ports[line];


	down(&serial_sem);
	mutex_lock(&serial_mutex);
	uart_remove_one_port(&serial8250_reg, &uart->port);
	uart_remove_one_port(&serial8250_reg, &uart->port);
	if (serial8250_isa_devs) {
	if (serial8250_isa_devs) {
		uart->port.flags &= ~UPF_BOOT_AUTOCONF;
		uart->port.flags &= ~UPF_BOOT_AUTOCONF;
@@ -2571,7 +2572,7 @@ void serial8250_unregister_port(int line)
	} else {
	} else {
		uart->port.dev = NULL;
		uart->port.dev = NULL;
	}
	}
	up(&serial_sem);
	mutex_unlock(&serial_mutex);
}
}
EXPORT_SYMBOL(serial8250_unregister_port);
EXPORT_SYMBOL(serial8250_unregister_port);


+4 −7
Original line number Original line Diff line number Diff line
@@ -442,6 +442,7 @@ static char *serial_version = "$Revision: 1.25 $";
#include <linux/init.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#include <asm/uaccess.h>
#include <linux/kernel.h>
#include <linux/kernel.h>
#include <linux/mutex.h>


#include <asm/io.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/irq.h>
@@ -1315,11 +1316,7 @@ static const struct control_pins e100_modem_pins[NR_PORTS] =
 * memory if large numbers of serial ports are open.
 * memory if large numbers of serial ports are open.
 */
 */
static unsigned char *tmp_buf;
static unsigned char *tmp_buf;
#ifdef DECLARE_MUTEX
static DEFINE_MUTEX(tmp_buf_mutex);
static DECLARE_MUTEX(tmp_buf_sem);
#else
static struct semaphore tmp_buf_sem = MUTEX;
#endif


/* Calculate the chartime depending on baudrate, numbor of bits etc. */
/* Calculate the chartime depending on baudrate, numbor of bits etc. */
static void update_char_time(struct e100_serial * info)
static void update_char_time(struct e100_serial * info)
@@ -3661,7 +3658,7 @@ rs_raw_write(struct tty_struct * tty, int from_user,
	 * design.
	 * design.
	 */
	 */
	if (from_user) {
	if (from_user) {
		down(&tmp_buf_sem);
		mutex_lock(&tmp_buf_mutex);
		while (1) {
		while (1) {
			int c1;
			int c1;
			c = CIRC_SPACE_TO_END(info->xmit.head,
			c = CIRC_SPACE_TO_END(info->xmit.head,
@@ -3692,7 +3689,7 @@ rs_raw_write(struct tty_struct * tty, int from_user,
			count -= c;
			count -= c;
			ret += c;
			ret += c;
		}
		}
		up(&tmp_buf_sem);
		mutex_unlock(&tmp_buf_mutex);
	} else {
	} else {
		cli();
		cli();
		while (count) {
		while (count) {
+12 −11
Original line number Original line Diff line number Diff line
@@ -60,6 +60,7 @@
#include <linux/pmu.h>
#include <linux/pmu.h>
#include <linux/bitops.h>
#include <linux/bitops.h>
#include <linux/sysrq.h>
#include <linux/sysrq.h>
#include <linux/mutex.h>
#include <asm/sections.h>
#include <asm/sections.h>
#include <asm/io.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/irq.h>
@@ -96,7 +97,7 @@ MODULE_LICENSE("GPL");
 */
 */
static struct uart_pmac_port	pmz_ports[MAX_ZS_PORTS];
static struct uart_pmac_port	pmz_ports[MAX_ZS_PORTS];
static int			pmz_ports_count;
static int			pmz_ports_count;
static DECLARE_MUTEX(pmz_irq_sem);
static DEFINE_MUTEX(pmz_irq_mutex);


static struct uart_driver pmz_uart_reg = {
static struct uart_driver pmz_uart_reg = {
	.owner		=	THIS_MODULE,
	.owner		=	THIS_MODULE,
@@ -922,7 +923,7 @@ static int pmz_startup(struct uart_port *port)
	if (uap->node == NULL)
	if (uap->node == NULL)
		return -ENODEV;
		return -ENODEV;


	down(&pmz_irq_sem);
	mutex_lock(&pmz_irq_mutex);


	uap->flags |= PMACZILOG_FLAG_IS_OPEN;
	uap->flags |= PMACZILOG_FLAG_IS_OPEN;


@@ -940,11 +941,11 @@ static int pmz_startup(struct uart_port *port)
		dev_err(&uap->dev->ofdev.dev,
		dev_err(&uap->dev->ofdev.dev,
			"Unable to register zs interrupt handler.\n");
			"Unable to register zs interrupt handler.\n");
		pmz_set_scc_power(uap, 0);
		pmz_set_scc_power(uap, 0);
		up(&pmz_irq_sem);
		mutex_unlock(&pmz_irq_mutex);
		return -ENXIO;
		return -ENXIO;
	}
	}


	up(&pmz_irq_sem);
	mutex_unlock(&pmz_irq_mutex);


	/* Right now, we deal with delay by blocking here, I'll be
	/* Right now, we deal with delay by blocking here, I'll be
	 * smarter later on
	 * smarter later on
@@ -981,7 +982,7 @@ static void pmz_shutdown(struct uart_port *port)
	if (uap->node == NULL)
	if (uap->node == NULL)
		return;
		return;


	down(&pmz_irq_sem);
	mutex_lock(&pmz_irq_mutex);


	/* Release interrupt handler */
	/* Release interrupt handler */
       	free_irq(uap->port.irq, uap);
       	free_irq(uap->port.irq, uap);
@@ -1002,7 +1003,7 @@ static void pmz_shutdown(struct uart_port *port)


	if (ZS_IS_CONS(uap) || ZS_IS_ASLEEP(uap)) {
	if (ZS_IS_CONS(uap) || ZS_IS_ASLEEP(uap)) {
		spin_unlock_irqrestore(&port->lock, flags);
		spin_unlock_irqrestore(&port->lock, flags);
		up(&pmz_irq_sem);
		mutex_unlock(&pmz_irq_mutex);
		return;
		return;
	}
	}


@@ -1019,7 +1020,7 @@ static void pmz_shutdown(struct uart_port *port)


	spin_unlock_irqrestore(&port->lock, flags);
	spin_unlock_irqrestore(&port->lock, flags);


	up(&pmz_irq_sem);
	mutex_unlock(&pmz_irq_mutex);


	pmz_debug("pmz: shutdown() done.\n");
	pmz_debug("pmz: shutdown() done.\n");
}
}
@@ -1591,7 +1592,7 @@ static int pmz_suspend(struct macio_dev *mdev, pm_message_t pm_state)


	state = pmz_uart_reg.state + uap->port.line;
	state = pmz_uart_reg.state + uap->port.line;


	down(&pmz_irq_sem);
	mutex_lock(&pmz_irq_mutex);
	down(&state->sem);
	down(&state->sem);


	spin_lock_irqsave(&uap->port.lock, flags);
	spin_lock_irqsave(&uap->port.lock, flags);
@@ -1624,7 +1625,7 @@ static int pmz_suspend(struct macio_dev *mdev, pm_message_t pm_state)
	pmz_set_scc_power(uap, 0);
	pmz_set_scc_power(uap, 0);


	up(&state->sem);
	up(&state->sem);
	up(&pmz_irq_sem);
	mutex_unlock(&pmz_irq_mutex);


	pmz_debug("suspend, switching complete\n");
	pmz_debug("suspend, switching complete\n");


@@ -1651,7 +1652,7 @@ static int pmz_resume(struct macio_dev *mdev)


	state = pmz_uart_reg.state + uap->port.line;
	state = pmz_uart_reg.state + uap->port.line;


	down(&pmz_irq_sem);
	mutex_lock(&pmz_irq_mutex);
	down(&state->sem);
	down(&state->sem);


	spin_lock_irqsave(&uap->port.lock, flags);
	spin_lock_irqsave(&uap->port.lock, flags);
@@ -1685,7 +1686,7 @@ static int pmz_resume(struct macio_dev *mdev)


 bail:
 bail:
	up(&state->sem);
	up(&state->sem);
	up(&pmz_irq_sem);
	mutex_unlock(&pmz_irq_mutex);


	/* Right now, we deal with delay by blocking here, I'll be
	/* Right now, we deal with delay by blocking here, I'll be
	 * smarter later on
	 * smarter later on
+8 −7
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@
#include <linux/device.h>
#include <linux/device.h>
#include <linux/serial.h> /* for serial_state and serial_icounter_struct */
#include <linux/serial.h> /* for serial_state and serial_icounter_struct */
#include <linux/delay.h>
#include <linux/delay.h>
#include <linux/mutex.h>


#include <asm/irq.h>
#include <asm/irq.h>
#include <asm/uaccess.h>
#include <asm/uaccess.h>
@@ -47,7 +48,7 @@
/*
/*
 * This is used to lock changes in serial line configuration.
 * This is used to lock changes in serial line configuration.
 */
 */
static DECLARE_MUTEX(port_sem);
static DEFINE_MUTEX(port_mutex);


#define HIGH_BITS_OFFSET	((sizeof(long)-sizeof(int))*8)
#define HIGH_BITS_OFFSET	((sizeof(long)-sizeof(int))*8)


@@ -1472,7 +1473,7 @@ static struct uart_state *uart_get(struct uart_driver *drv, int line)
{
{
	struct uart_state *state;
	struct uart_state *state;


	down(&port_sem);
	mutex_lock(&port_mutex);
	state = drv->state + line;
	state = drv->state + line;
	if (down_interruptible(&state->sem)) {
	if (down_interruptible(&state->sem)) {
		state = ERR_PTR(-ERESTARTSYS);
		state = ERR_PTR(-ERESTARTSYS);
@@ -1509,7 +1510,7 @@ static struct uart_state *uart_get(struct uart_driver *drv, int line)
	}
	}


 out:
 out:
	up(&port_sem);
	mutex_unlock(&port_mutex);
	return state;
	return state;
}
}


@@ -2219,7 +2220,7 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *port)


	state = drv->state + port->line;
	state = drv->state + port->line;


	down(&port_sem);
	mutex_lock(&port_mutex);
	if (state->port) {
	if (state->port) {
		ret = -EINVAL;
		ret = -EINVAL;
		goto out;
		goto out;
@@ -2255,7 +2256,7 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *port)
		register_console(port->cons);
		register_console(port->cons);


 out:
 out:
	up(&port_sem);
	mutex_unlock(&port_mutex);


	return ret;
	return ret;
}
}
@@ -2279,7 +2280,7 @@ int uart_remove_one_port(struct uart_driver *drv, struct uart_port *port)
		printk(KERN_ALERT "Removing wrong port: %p != %p\n",
		printk(KERN_ALERT "Removing wrong port: %p != %p\n",
			state->port, port);
			state->port, port);


	down(&port_sem);
	mutex_lock(&port_mutex);


	/*
	/*
	 * Remove the devices from devfs
	 * Remove the devices from devfs
@@ -2288,7 +2289,7 @@ int uart_remove_one_port(struct uart_driver *drv, struct uart_port *port)


	uart_unconfigure_port(drv, state);
	uart_unconfigure_port(drv, state);
	state->port = NULL;
	state->port = NULL;
	up(&port_sem);
	mutex_unlock(&port_mutex);


	return 0;
	return 0;
}
}
+6 −5
Original line number Original line Diff line number Diff line
@@ -52,6 +52,7 @@
#include <linux/tty_flip.h>
#include <linux/tty_flip.h>
#include <linux/serial_core.h>
#include <linux/serial_core.h>
#include <linux/serial.h>
#include <linux/serial.h>
#include <linux/mutex.h>


#include <asm/io.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/irq.h>
@@ -1018,7 +1019,7 @@ static void serial_txx9_resume_port(int line)
	uart_resume_port(&serial_txx9_reg, &serial_txx9_ports[line].port);
	uart_resume_port(&serial_txx9_reg, &serial_txx9_ports[line].port);
}
}


static DECLARE_MUTEX(serial_txx9_sem);
static DEFINE_MUTEX(serial_txx9_mutex);


/**
/**
 *	serial_txx9_register_port - register a serial port
 *	serial_txx9_register_port - register a serial port
@@ -1037,7 +1038,7 @@ static int __devinit serial_txx9_register_port(struct uart_port *port)
	struct uart_txx9_port *uart;
	struct uart_txx9_port *uart;
	int ret = -ENOSPC;
	int ret = -ENOSPC;


	down(&serial_txx9_sem);
	mutex_lock(&serial_txx9_mutex);
	for (i = 0; i < UART_NR; i++) {
	for (i = 0; i < UART_NR; i++) {
		uart = &serial_txx9_ports[i];
		uart = &serial_txx9_ports[i];
		if (uart->port.type == PORT_UNKNOWN)
		if (uart->port.type == PORT_UNKNOWN)
@@ -1058,7 +1059,7 @@ static int __devinit serial_txx9_register_port(struct uart_port *port)
		if (ret == 0)
		if (ret == 0)
			ret = uart->port.line;
			ret = uart->port.line;
	}
	}
	up(&serial_txx9_sem);
	mutex_unlock(&serial_txx9_mutex);
	return ret;
	return ret;
}
}


@@ -1073,7 +1074,7 @@ static void __devexit serial_txx9_unregister_port(int line)
{
{
	struct uart_txx9_port *uart = &serial_txx9_ports[line];
	struct uart_txx9_port *uart = &serial_txx9_ports[line];


	down(&serial_txx9_sem);
	mutex_lock(&serial_txx9_mutex);
	uart_remove_one_port(&serial_txx9_reg, &uart->port);
	uart_remove_one_port(&serial_txx9_reg, &uart->port);
	uart->port.flags = 0;
	uart->port.flags = 0;
	uart->port.type = PORT_UNKNOWN;
	uart->port.type = PORT_UNKNOWN;
@@ -1082,7 +1083,7 @@ static void __devexit serial_txx9_unregister_port(int line)
	uart->port.membase = 0;
	uart->port.membase = 0;
	uart->port.dev = NULL;
	uart->port.dev = NULL;
	uart_add_one_port(&serial_txx9_reg, &uart->port);
	uart_add_one_port(&serial_txx9_reg, &uart->port);
	up(&serial_txx9_sem);
	mutex_unlock(&serial_txx9_mutex);
}
}


/*
/*