[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1275552062-8153-4-git-send-email-rydberg@euromail.se>
Date: Thu, 3 Jun 2010 10:01:01 +0200
From: "Henrik Rydberg" <rydberg@...omail.se>
To: Dmitry Torokhov <dmitry.torokhov@...il.com>
Cc: linux-input@...r.kernel.org, linux-kernel@...r.kernel.org,
Jiri Kosina <jkosina@...e.cz>,
Mika Kuoppala <mika.kuoppala@...ia.com>,
Benjamin Tissoires <tissoire@...a.fr>,
Rafi Rubin <rafi@...s.upenn.edu>,
Henrik Rydberg <rydberg@...omail.se>
Subject: [PATCH 3/4] input: evdev: Convert to dynamic event buffer (rev3)
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@...omail.se>
---
drivers/input/evdev.c | 23 +++++++++++++++++++----
1 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 7f0c7da..2e2a339 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>
@@ -35,7 +35,8 @@ struct evdev {
struct mutex mutex;
struct device dev;
struct buflock_writer writer;
- struct input_event buffer[EVDEV_BUFFER_SIZE];
+ unsigned int bufsize;
+ struct input_event *buffer;
};
struct evdev_client {
@@ -74,7 +75,7 @@ static void evdev_event(struct input_handle *handle,
event.value = value;
/* lock-less write */
- buflock_write(evdev->writer, evdev->buffer, EVDEV_BUFFER_SIZE, event);
+ buflock_write(evdev->writer, evdev->buffer, evdev->bufsize, event);
rcu_read_lock();
@@ -121,6 +122,7 @@ static void evdev_free(struct device *dev)
struct evdev *evdev = container_of(dev, struct evdev, dev);
input_put_device(evdev->handle.dev);
+ kfree(evdev->buffer);
kfree(evdev);
}
@@ -333,7 +335,7 @@ static int evdev_fetch_next_event(struct evdev_client *client,
have_event = !buflock_reader_empty(client->reader);
if (have_event)
buflock_read(client->reader, evdev->writer,
- evdev->buffer, EVDEV_BUFFER_SIZE, *event);
+ evdev->buffer, evdev->bufsize, *event);
spin_unlock_irq(&client->entry_lock);
@@ -786,6 +788,11 @@ static void evdev_cleanup(struct evdev *evdev)
}
}
+static int evdev_compute_buffer_size(struct input_dev *dev)
+{
+ return EVDEV_MIN_BUFFER_SIZE;
+}
+
/*
* Create new evdev device. Note that input core serializes calls
* to connect and disconnect so we don't need to lock evdev_table here.
@@ -830,6 +837,14 @@ static int evdev_connect(struct input_handler *handler, struct input_dev *dev,
evdev->dev.release = evdev_free;
device_initialize(&evdev->dev);
+ evdev->bufsize = evdev_compute_buffer_size(dev);
+ evdev->buffer = kzalloc(evdev->bufsize * sizeof(struct input_event),
+ GFP_KERNEL);
+ if (!evdev->buffer) {
+ error = -ENOMEM;
+ goto err_free_evdev;
+ }
+
error = input_register_handle(&evdev->handle);
if (error)
goto err_free_evdev;
--
1.6.3.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists