From: "Henrik Rydberg" <rydberg@euromail.se>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
Jiri Kosina <jkosina@suse.cz>, Ping Cheng <pingc@wacom.com>,
Benjamin Tissoires <tissoire@cena.fr>,
Chase Douglas <chase.douglas@canonical.com>,
Rafi Rubin <rafi@seas.upenn.edu>,
Henrik Rydberg <rydberg@euromail.se>
Subject: [PATCH 1/5] input: evdev: Convert to dynamic event buffer (rev5)
Date: Wed, 23 Jun 2010 13:14:42 +0200 [thread overview]
Message-ID: <1277291686-7153-2-git-send-email-rydberg@euromail.se> (raw)
In-Reply-To: <1277291686-7153-1-git-send-email-rydberg@euromail.se>
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: Henrik Rydberg <rydberg@euromail.se>
---
drivers/input/evdev.c | 25 +++++++++++++++++++++----
1 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 2ee6c7a..5d84e59 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -10,7 +10,7 @@
#define EVDEV_MINOR_BASE 64
#define EVDEV_MINORS 32
-#define EVDEV_BUFFER_SIZE 64
+#define EVDEV_MIN_BUFFER_SIZE 64
#include <linux/poll.h>
#include <linux/sched.h>
@@ -36,7 +36,8 @@ struct evdev {
};
struct evdev_client {
- struct input_event buffer[EVDEV_BUFFER_SIZE];
+ struct input_event *buffer;
+ int bufsize;
int head;
int tail;
spinlock_t buffer_lock; /* protects access to buffer, head and tail */
@@ -48,6 +49,11 @@ struct evdev_client {
static struct evdev *evdev_table[EVDEV_MINORS];
static DEFINE_MUTEX(evdev_table_mutex);
+static int evdev_compute_buffer_size(struct input_dev *dev)
+{
+ return EVDEV_MIN_BUFFER_SIZE;
+}
+
static void evdev_pass_event(struct evdev_client *client,
struct input_event *event)
{
@@ -56,7 +62,7 @@ static void evdev_pass_event(struct evdev_client *client,
*/
spin_lock(&client->buffer_lock);
client->buffer[client->head++] = *event;
- client->head &= EVDEV_BUFFER_SIZE - 1;
+ client->head &= client->bufsize - 1;
spin_unlock(&client->buffer_lock);
if (event->type == EV_SYN)
@@ -234,6 +240,7 @@ static int evdev_release(struct inode *inode, struct file *file)
mutex_unlock(&evdev->mutex);
evdev_detach_client(evdev, client);
+ kfree(client->buffer);
kfree(client);
evdev_close_device(evdev);
@@ -269,6 +276,14 @@ static int evdev_open(struct inode *inode, struct file *file)
goto err_put_evdev;
}
+ client->bufsize = evdev_compute_buffer_size(evdev->handle.dev);
+ client->buffer = kcalloc(client->bufsize, sizeof(struct input_event),
+ GFP_KERNEL);
+ if (!client->buffer) {
+ error = -ENOMEM;
+ goto err_free_memory;
+ }
+
spin_lock_init(&client->buffer_lock);
client->evdev = evdev;
evdev_attach_client(evdev, client);
@@ -284,6 +299,8 @@ static int evdev_open(struct inode *inode, struct file *file)
err_free_client:
evdev_detach_client(evdev, client);
+ kfree(client->buffer);
+ err_free_memory:
kfree(client);
err_put_evdev:
put_device(&evdev->dev);
@@ -334,7 +351,7 @@ static int evdev_fetch_next_event(struct evdev_client *client,
have_event = client->head != client->tail;
if (have_event) {
*event = client->buffer[client->tail++];
- client->tail &= EVDEV_BUFFER_SIZE - 1;
+ client->tail &= client->bufsize - 1;
}
spin_unlock_irq(&client->buffer_lock);
--
1.6.3.3
next prev parent reply other threads:[~2010-06-23 11:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-23 11:14 [PATCH 0/4] input: evdev: Dynamic buffers (rev5) Henrik Rydberg
2010-06-23 11:14 ` Henrik Rydberg [this message]
2010-06-23 11:14 ` [PATCH 2/5] input: Use driver hint to compute the evdev buffer size (rev3) Henrik Rydberg
2010-06-23 11:14 ` [PATCH 3/5] input: bcm5974: Set the average number of events per MT event packet Henrik Rydberg
2010-06-23 11:14 ` [PATCH 4/5] hid-input: Use a larger event buffer for MT devices Henrik Rydberg
2010-06-23 11:14 ` [PATCH 5/5] input: evdev: Never leave the client buffer empty after write Henrik Rydberg
2010-06-23 14:20 ` [PATCH 4/5] hid-input: Use a larger event buffer for MT devices Jiri Kosina
2010-06-23 16:54 ` [PATCH 2/5] input: Use driver hint to compute the evdev buffer size (rev3) Ping Cheng
2010-06-23 17:07 ` Henrik Rydberg
2010-06-23 17:12 ` Dmitry Torokhov
2010-06-23 17:27 ` Henrik Rydberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1277291686-7153-2-git-send-email-rydberg@euromail.se \
--to=rydberg@euromail.se \
--cc=chase.douglas@canonical.com \
--cc=dmitry.torokhov@gmail.com \
--cc=jkosina@suse.cz \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pingc@wacom.com \
--cc=rafi@seas.upenn.edu \
--cc=tissoire@cena.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®