Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 269500
b: refs/heads/master
c: ba538cd
h: refs/heads/master
v: v3
  • Loading branch information
Dmitry Torokhov committed Oct 11, 2011
1 parent ce93644 commit 3ececa8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 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: b5d21704361eefe337a36ebbb57a1d9927132511
refs/heads/master: ba538cd2a83f3556448759283d2330a603005afe
28 changes: 13 additions & 15 deletions trunk/drivers/input/serio/serio_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* the Free Software Foundation.
*/

#include <linux/kref.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/poll.h>
Expand All @@ -33,7 +34,7 @@ struct serio_raw {
unsigned int tail, head;

char name[16];
unsigned int refcnt;
struct kref kref;
struct serio *serio;
struct miscdevice dev;
wait_queue_head_t wait;
Expand Down Expand Up @@ -104,25 +105,22 @@ static int serio_raw_open(struct inode *inode, struct file *file)
list->serio_raw = serio_raw;
file->private_data = list;

serio_raw->refcnt++;
kref_get(&serio_raw->kref);
list_add_tail(&list->node, &serio_raw->list);

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

static int serio_raw_cleanup(struct serio_raw *serio_raw)
static void serio_raw_cleanup(struct kref *kref)
{
if (--serio_raw->refcnt == 0) {
misc_deregister(&serio_raw->dev);
list_del_init(&serio_raw->node);
kfree(serio_raw);
struct serio_raw *serio_raw =
container_of(kref, struct serio_raw, kref);

return 1;
}

return 0;
misc_deregister(&serio_raw->dev);
list_del_init(&serio_raw->node);
kfree(serio_raw);
}

static int serio_raw_release(struct inode *inode, struct file *file)
Expand All @@ -132,7 +130,7 @@ static int serio_raw_release(struct inode *inode, struct file *file)

mutex_lock(&serio_raw_mutex);

serio_raw_cleanup(serio_raw);
kref_put(&serio_raw->kref, serio_raw_cleanup);

mutex_unlock(&serio_raw_mutex);
return 0;
Expand Down Expand Up @@ -283,7 +281,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
mutex_lock(&serio_raw_mutex);

snprintf(serio_raw->name, sizeof(serio_raw->name), "serio_raw%d", serio_raw_no++);
serio_raw->refcnt = 1;
kref_init(&serio_raw->kref);
serio_raw->serio = serio;
INIT_LIST_HEAD(&serio_raw->list);
init_waitqueue_head(&serio_raw->wait);
Expand Down Expand Up @@ -357,8 +355,8 @@ static void serio_raw_disconnect(struct serio *serio)
serio_set_drvdata(serio, NULL);

serio_raw->serio = NULL;
if (!serio_raw_cleanup(serio_raw))
wake_up_interruptible(&serio_raw->wait);
wake_up_interruptible(&serio_raw->wait);
kref_put(&serio_raw->kref, serio_raw_cleanup);

mutex_unlock(&serio_raw_mutex);
}
Expand Down

0 comments on commit 3ececa8

Please sign in to comment.