Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 3522
b: refs/heads/master
c: 0fbf87c
h: refs/heads/master
v: v3
  • Loading branch information
Dmitry Torokhov committed May 29, 2005
1 parent 419cf3b commit 9d900ba
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 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: 58a007765bb5f16020e6000ecbdc5bcc6e54a147
refs/heads/master: 0fbf87caf70acec0c435233fbc39c7bd0aca3ca6
33 changes: 28 additions & 5 deletions trunk/drivers/input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,24 @@ void input_release_device(struct input_handle *handle)

int input_open_device(struct input_handle *handle)
{
struct input_dev *dev = handle->dev;
int err;

err = down_interruptible(&dev->sem);
if (err)
return err;

handle->open++;
if (handle->dev->open)
return handle->dev->open(handle->dev);
return 0;

if (!dev->users++ && dev->open)
err = dev->open(dev);

if (err)
handle->open--;

up(&dev->sem);

return err;
}

int input_flush_device(struct input_handle* handle, struct file* file)
Expand All @@ -235,10 +249,17 @@ int input_flush_device(struct input_handle* handle, struct file* file)

void input_close_device(struct input_handle *handle)
{
struct input_dev *dev = handle->dev;

input_release_device(handle);
if (handle->dev->close)
handle->dev->close(handle->dev);

down(&dev->sem);

if (!--dev->users && dev->close)
dev->close(dev);
handle->open--;

up(&dev->sem);
}

static void input_link_handle(struct input_handle *handle)
Expand Down Expand Up @@ -415,6 +436,8 @@ void input_register_device(struct input_dev *dev)

set_bit(EV_SYN, dev->evbit);

init_MUTEX(&dev->sem);

/*
* If delay and period are pre-set by the driver, then autorepeating
* is handled by the driver itself and we don't do it in input.c.
Expand Down
4 changes: 4 additions & 0 deletions trunk/include/linux/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,10 @@ struct input_dev {
int (*erase_effect)(struct input_dev *dev, int effect_id);

struct input_handle *grab;

struct semaphore sem; /* serializes open and close operations */
unsigned int users;

struct device *dev;

struct list_head h_list;
Expand Down

0 comments on commit 9d900ba

Please sign in to comment.