Commit b58f7086 authored by Henrik Rydberg's avatar Henrik Rydberg Committed by Dmitry Torokhov

Input: evdev - convert to dynamic event buffer

Allocate the event buffer dynamically, and prepare to compute the
buffer size in a separate function. This patch defines the size
computation to be identical to the current code, and does not contain
any logical changes.
Signed-off-by: default avatarHenrik Rydberg <rydberg@euromail.se>
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent 4aaf5046
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#define EVDEV_MINOR_BASE 64 #define EVDEV_MINOR_BASE 64
#define EVDEV_MINORS 32 #define EVDEV_MINORS 32
#define EVDEV_BUFFER_SIZE 64 #define EVDEV_MIN_BUFFER_SIZE 64
#include <linux/poll.h> #include <linux/poll.h>
#include <linux/sched.h> #include <linux/sched.h>
...@@ -36,13 +36,14 @@ struct evdev { ...@@ -36,13 +36,14 @@ struct evdev {
}; };
struct evdev_client { struct evdev_client {
struct input_event buffer[EVDEV_BUFFER_SIZE];
int head; int head;
int tail; int tail;
spinlock_t buffer_lock; /* protects access to buffer, head and tail */ spinlock_t buffer_lock; /* protects access to buffer, head and tail */
struct fasync_struct *fasync; struct fasync_struct *fasync;
struct evdev *evdev; struct evdev *evdev;
struct list_head node; struct list_head node;
int bufsize;
struct input_event buffer[];
}; };
static struct evdev *evdev_table[EVDEV_MINORS]; static struct evdev *evdev_table[EVDEV_MINORS];
...@@ -56,7 +57,7 @@ static void evdev_pass_event(struct evdev_client *client, ...@@ -56,7 +57,7 @@ static void evdev_pass_event(struct evdev_client *client,
*/ */
spin_lock(&client->buffer_lock); spin_lock(&client->buffer_lock);
client->buffer[client->head++] = *event; client->buffer[client->head++] = *event;
client->head &= EVDEV_BUFFER_SIZE - 1; client->head &= client->bufsize - 1;
spin_unlock(&client->buffer_lock); spin_unlock(&client->buffer_lock);
if (event->type == EV_SYN) if (event->type == EV_SYN)
...@@ -242,11 +243,17 @@ static int evdev_release(struct inode *inode, struct file *file) ...@@ -242,11 +243,17 @@ static int evdev_release(struct inode *inode, struct file *file)
return 0; return 0;
} }
static unsigned int evdev_compute_buffer_size(struct input_dev *dev)
{
return EVDEV_MIN_BUFFER_SIZE;
}
static int evdev_open(struct inode *inode, struct file *file) static int evdev_open(struct inode *inode, struct file *file)
{ {
struct evdev *evdev; struct evdev *evdev;
struct evdev_client *client; struct evdev_client *client;
int i = iminor(inode) - EVDEV_MINOR_BASE; int i = iminor(inode) - EVDEV_MINOR_BASE;
unsigned int bufsize;
int error; int error;
if (i >= EVDEV_MINORS) if (i >= EVDEV_MINORS)
...@@ -263,12 +270,17 @@ static int evdev_open(struct inode *inode, struct file *file) ...@@ -263,12 +270,17 @@ static int evdev_open(struct inode *inode, struct file *file)
if (!evdev) if (!evdev)
return -ENODEV; return -ENODEV;
client = kzalloc(sizeof(struct evdev_client), GFP_KERNEL); bufsize = evdev_compute_buffer_size(evdev->handle.dev);
client = kzalloc(sizeof(struct evdev_client) +
bufsize * sizeof(struct input_event),
GFP_KERNEL);
if (!client) { if (!client) {
error = -ENOMEM; error = -ENOMEM;
goto err_put_evdev; goto err_put_evdev;
} }
client->bufsize = bufsize;
spin_lock_init(&client->buffer_lock); spin_lock_init(&client->buffer_lock);
client->evdev = evdev; client->evdev = evdev;
evdev_attach_client(evdev, client); evdev_attach_client(evdev, client);
...@@ -334,7 +346,7 @@ static int evdev_fetch_next_event(struct evdev_client *client, ...@@ -334,7 +346,7 @@ static int evdev_fetch_next_event(struct evdev_client *client,
have_event = client->head != client->tail; have_event = client->head != client->tail;
if (have_event) { if (have_event) {
*event = client->buffer[client->tail++]; *event = client->buffer[client->tail++];
client->tail &= EVDEV_BUFFER_SIZE - 1; client->tail &= client->bufsize - 1;
} }
spin_unlock_irq(&client->buffer_lock); spin_unlock_irq(&client->buffer_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment