Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 25051
b: refs/heads/master
c: c4e32e9
h: refs/heads/master
i:
  25049: 7f5589b
  25047: 2584988
v: v3
  • Loading branch information
Arjan van de Ven authored and Dmitry Torokhov committed Feb 19, 2006
1 parent 3650ae5 commit 75ad077
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 44 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e676c232e670e27d8b3783e1167f34288e17c83f
refs/heads/master: c4e32e9faaaa83340dbbc00e07c48d38f032b7dc
10 changes: 5 additions & 5 deletions trunk/drivers/input/serio/libps2.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout)
maxbytes = sizeof(ps2dev->cmdbuf);
}

down(&ps2dev->cmd_sem);
mutex_lock(&ps2dev->cmd_mutex);

serio_pause_rx(ps2dev->serio);
ps2dev->flags = PS2_FLAG_CMD;
Expand All @@ -94,7 +94,7 @@ void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout)
wait_event_timeout(ps2dev->wait,
!(ps2dev->flags & PS2_FLAG_CMD),
msecs_to_jiffies(timeout));
up(&ps2dev->cmd_sem);
mutex_unlock(&ps2dev->cmd_mutex);
}

/*
Expand Down Expand Up @@ -177,7 +177,7 @@ int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command)
return -1;
}

down(&ps2dev->cmd_sem);
mutex_lock(&ps2dev->cmd_mutex);

serio_pause_rx(ps2dev->serio);
ps2dev->flags = command == PS2_CMD_GETID ? PS2_FLAG_WAITID : 0;
Expand Down Expand Up @@ -229,7 +229,7 @@ int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command)
ps2dev->flags = 0;
serio_continue_rx(ps2dev->serio);

up(&ps2dev->cmd_sem);
mutex_unlock(&ps2dev->cmd_mutex);
return rc;
}

Expand Down Expand Up @@ -281,7 +281,7 @@ int ps2_schedule_command(struct ps2dev *ps2dev, unsigned char *param, int comman

void ps2_init(struct ps2dev *ps2dev, struct serio *serio)
{
init_MUTEX(&ps2dev->cmd_sem);
mutex_init(&ps2dev->cmd_mutex);
init_waitqueue_head(&ps2dev->wait);
ps2dev->serio = serio;
}
Expand Down
45 changes: 23 additions & 22 deletions trunk/drivers/input/serio/serio.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/kthread.h>
#include <linux/mutex.h>

MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
MODULE_DESCRIPTION("Serio abstraction core");
Expand All @@ -52,10 +53,10 @@ EXPORT_SYMBOL(serio_rescan);
EXPORT_SYMBOL(serio_reconnect);

/*
* serio_sem protects entire serio subsystem and is taken every time
* serio_mutex protects entire serio subsystem and is taken every time
* serio port or driver registrered or unregistered.
*/
static DECLARE_MUTEX(serio_sem);
static DEFINE_MUTEX(serio_mutex);

static LIST_HEAD(serio_list);

Expand All @@ -70,9 +71,9 @@ static int serio_connect_driver(struct serio *serio, struct serio_driver *drv)
{
int retval;

down(&serio->drv_sem);
mutex_lock(&serio->drv_mutex);
retval = drv->connect(serio, drv);
up(&serio->drv_sem);
mutex_unlock(&serio->drv_mutex);

return retval;
}
Expand All @@ -81,20 +82,20 @@ static int serio_reconnect_driver(struct serio *serio)
{
int retval = -1;

down(&serio->drv_sem);
mutex_lock(&serio->drv_mutex);
if (serio->drv && serio->drv->reconnect)
retval = serio->drv->reconnect(serio);
up(&serio->drv_sem);
mutex_unlock(&serio->drv_mutex);

return retval;
}

static void serio_disconnect_driver(struct serio *serio)
{
down(&serio->drv_sem);
mutex_lock(&serio->drv_mutex);
if (serio->drv)
serio->drv->disconnect(serio);
up(&serio->drv_sem);
mutex_unlock(&serio->drv_mutex);
}

static int serio_match_port(const struct serio_device_id *ids, struct serio *serio)
Expand Down Expand Up @@ -272,7 +273,7 @@ static void serio_handle_event(void)
struct serio_event *event;
struct serio_driver *serio_drv;

down(&serio_sem);
mutex_lock(&serio_mutex);

/*
* Note that we handle only one event here to give swsusp
Expand Down Expand Up @@ -314,7 +315,7 @@ static void serio_handle_event(void)
serio_free_event(event);
}

up(&serio_sem);
mutex_unlock(&serio_mutex);
}

/*
Expand Down Expand Up @@ -449,7 +450,7 @@ static ssize_t serio_rebind_driver(struct device *dev, struct device_attribute *
struct device_driver *drv;
int retval;

retval = down_interruptible(&serio_sem);
retval = mutex_lock_interruptible(&serio_mutex);
if (retval)
return retval;

Expand All @@ -469,7 +470,7 @@ static ssize_t serio_rebind_driver(struct device *dev, struct device_attribute *
retval = -EINVAL;
}

up(&serio_sem);
mutex_unlock(&serio_mutex);

return retval;
}
Expand Down Expand Up @@ -524,7 +525,7 @@ static void serio_init_port(struct serio *serio)
__module_get(THIS_MODULE);

spin_lock_init(&serio->lock);
init_MUTEX(&serio->drv_sem);
mutex_init(&serio->drv_mutex);
device_initialize(&serio->dev);
snprintf(serio->dev.bus_id, sizeof(serio->dev.bus_id),
"serio%ld", (long)atomic_inc_return(&serio_no) - 1);
Expand Down Expand Up @@ -661,28 +662,28 @@ void __serio_register_port(struct serio *serio, struct module *owner)
*/
void serio_unregister_port(struct serio *serio)
{
down(&serio_sem);
mutex_lock(&serio_mutex);
serio_disconnect_port(serio);
serio_destroy_port(serio);
up(&serio_sem);
mutex_unlock(&serio_mutex);
}

/*
* Safely unregisters child port if one is present.
*/
void serio_unregister_child_port(struct serio *serio)
{
down(&serio_sem);
mutex_lock(&serio_mutex);
if (serio->child) {
serio_disconnect_port(serio->child);
serio_destroy_port(serio->child);
}
up(&serio_sem);
mutex_unlock(&serio_mutex);
}

/*
* Submits register request to kseriod for subsequent execution.
* Can be used when it is not obvious whether the serio_sem is
* Can be used when it is not obvious whether the serio_mutex is
* taken or not and when delayed execution is feasible.
*/
void __serio_unregister_port_delayed(struct serio *serio, struct module *owner)
Expand Down Expand Up @@ -765,7 +766,7 @@ void serio_unregister_driver(struct serio_driver *drv)
{
struct serio *serio;

down(&serio_sem);
mutex_lock(&serio_mutex);
drv->manual_bind = 1; /* so serio_find_driver ignores it */

start_over:
Expand All @@ -779,7 +780,7 @@ void serio_unregister_driver(struct serio_driver *drv)
}

driver_unregister(&drv->driver);
up(&serio_sem);
mutex_unlock(&serio_mutex);
}

static void serio_set_drv(struct serio *serio, struct serio_driver *drv)
Expand Down Expand Up @@ -858,7 +859,7 @@ static int serio_resume(struct device *dev)
return 0;
}

/* called from serio_driver->connect/disconnect methods under serio_sem */
/* called from serio_driver->connect/disconnect methods under serio_mutex */
int serio_open(struct serio *serio, struct serio_driver *drv)
{
serio_set_drv(serio, drv);
Expand All @@ -870,7 +871,7 @@ int serio_open(struct serio *serio, struct serio_driver *drv)
return 0;
}

/* called from serio_driver->connect/disconnect methods under serio_sem */
/* called from serio_driver->connect/disconnect methods under serio_mutex */
void serio_close(struct serio *serio)
{
if (serio->close)
Expand Down
23 changes: 12 additions & 11 deletions trunk/drivers/input/serio/serio_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <linux/devfs_fs_kernel.h>
#include <linux/miscdevice.h>
#include <linux/wait.h>
#include <linux/mutex.h>

#define DRIVER_DESC "Raw serio driver"

Expand Down Expand Up @@ -46,7 +47,7 @@ struct serio_raw_list {
struct list_head node;
};

static DECLARE_MUTEX(serio_raw_sem);
static DEFINE_MUTEX(serio_raw_mutex);
static LIST_HEAD(serio_raw_list);
static unsigned int serio_raw_no;

Expand Down Expand Up @@ -81,7 +82,7 @@ static int serio_raw_open(struct inode *inode, struct file *file)
struct serio_raw_list *list;
int retval = 0;

retval = down_interruptible(&serio_raw_sem);
retval = mutex_lock_interruptible(&serio_raw_mutex);
if (retval)
return retval;

Expand All @@ -108,7 +109,7 @@ static int serio_raw_open(struct inode *inode, struct file *file)
list_add_tail(&list->node, &serio_raw->list);

out:
up(&serio_raw_sem);
mutex_unlock(&serio_raw_mutex);
return retval;
}

Expand All @@ -130,12 +131,12 @@ static int serio_raw_release(struct inode *inode, struct file *file)
struct serio_raw_list *list = file->private_data;
struct serio_raw *serio_raw = list->serio_raw;

down(&serio_raw_sem);
mutex_lock(&serio_raw_mutex);

serio_raw_fasync(-1, file, 0);
serio_raw_cleanup(serio_raw);

up(&serio_raw_sem);
mutex_unlock(&serio_raw_mutex);
return 0;
}

Expand Down Expand Up @@ -194,7 +195,7 @@ static ssize_t serio_raw_write(struct file *file, const char __user *buffer, siz
int retval;
unsigned char c;

retval = down_interruptible(&serio_raw_sem);
retval = mutex_lock_interruptible(&serio_raw_mutex);
if (retval)
return retval;

Expand All @@ -219,7 +220,7 @@ static ssize_t serio_raw_write(struct file *file, const char __user *buffer, siz
};

out:
up(&serio_raw_sem);
mutex_unlock(&serio_raw_mutex);
return written;
}

Expand Down Expand Up @@ -280,7 +281,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
return -ENOMEM;
}

down(&serio_raw_sem);
mutex_lock(&serio_raw_mutex);

memset(serio_raw, 0, sizeof(struct serio_raw));
snprintf(serio_raw->name, sizeof(serio_raw->name), "serio_raw%d", serio_raw_no++);
Expand Down Expand Up @@ -325,7 +326,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
serio_set_drvdata(serio, NULL);
kfree(serio_raw);
out:
up(&serio_raw_sem);
mutex_unlock(&serio_raw_mutex);
return err;
}

Expand All @@ -350,7 +351,7 @@ static void serio_raw_disconnect(struct serio *serio)
{
struct serio_raw *serio_raw;

down(&serio_raw_sem);
mutex_lock(&serio_raw_mutex);

serio_raw = serio_get_drvdata(serio);

Expand All @@ -361,7 +362,7 @@ static void serio_raw_disconnect(struct serio *serio)
if (!serio_raw_cleanup(serio_raw))
wake_up_interruptible(&serio_raw->wait);

up(&serio_raw_sem);
mutex_unlock(&serio_raw_mutex);
}

static struct serio_device_id serio_raw_serio_ids[] = {
Expand Down
2 changes: 1 addition & 1 deletion trunk/include/linux/libps2.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct ps2dev {
struct serio *serio;

/* Ensures that only one command is executing at a time */
struct semaphore cmd_sem;
struct mutex cmd_mutex;

/* Used to signal completion from interrupt handler */
wait_queue_head_t wait;
Expand Down
9 changes: 5 additions & 4 deletions trunk/include/linux/serio.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <linux/interrupt.h>
#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/device.h>
#include <linux/mod_devicetable.h>

Expand All @@ -42,7 +43,7 @@ struct serio {
struct serio *parent, *child;

struct serio_driver *drv; /* accessed from interrupt, must be protected by serio->lock and serio->sem */
struct semaphore drv_sem; /* protects serio->drv so attributes can pin driver */
struct mutex drv_mutex; /* protects serio->drv so attributes can pin driver */

struct device dev;
unsigned int registered; /* port has been fully registered with driver core */
Expand Down Expand Up @@ -151,17 +152,17 @@ static inline void serio_continue_rx(struct serio *serio)
*/
static inline int serio_pin_driver(struct serio *serio)
{
return down_interruptible(&serio->drv_sem);
return mutex_lock_interruptible(&serio->drv_mutex);
}

static inline void serio_pin_driver_uninterruptible(struct serio *serio)
{
down(&serio->drv_sem);
mutex_lock(&serio->drv_mutex);
}

static inline void serio_unpin_driver(struct serio *serio)
{
up(&serio->drv_sem);
mutex_unlock(&serio->drv_mutex);
}


Expand Down

0 comments on commit 75ad077

Please sign in to comment.