From patchwork Thu Jun 24 19:50:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henrik Rydberg X-Patchwork-Id: 56829 X-Patchwork-Delegate: leann.ogasawara@canonical.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 199EFB6F1A for ; Fri, 25 Jun 2010 05:51:43 +1000 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.69) (envelope-from ) id 1ORsSZ-00066D-N0; Thu, 24 Jun 2010 20:51:39 +0100 Received: from ch-smtp03.sth.basefarm.net ([80.76.149.214]) by chlorine.canonical.com with esmtp (Exim 4.69) (envelope-from ) id 1ORsSY-00065v-GN for kernel-team@lists.ubuntu.com; Thu, 24 Jun 2010 20:51:38 +0100 Received: from c83-248-196-134.bredband.comhem.se ([83.248.196.134]:47568 helo=alnilam) by ch-smtp03.sth.basefarm.net with smtp (Exim 4.68) (envelope-from ) id 1ORsRm-0005S0-C6; Thu, 24 Jun 2010 21:50:54 +0200 Received: by alnilam (sSMTP sendmail emulation); Thu, 24 Jun 2010 21:50:50 +0200 From: "Henrik Rydberg" To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/5] Input: evdev - convert to dynamic event buffer Date: Thu, 24 Jun 2010 21:50:34 +0200 Message-Id: <1277409038-25887-2-git-send-email-rydberg@euromail.se> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1277409038-25887-1-git-send-email-rydberg@euromail.se> References: <1277409038-25887-1-git-send-email-rydberg@euromail.se> X-Originating-IP: 83.248.196.134 X-Scan-Result: No virus found in message 1ORsRm-0005S0-C6. X-Scan-Signature: ch-smtp03.sth.basefarm.net 1ORsRm-0005S0-C6 58bdefb7e2ec26f13eb759c2b804a211 Cc: Dmitry Torokhov X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: kernel-team-bounces@lists.ubuntu.com Errors-To: kernel-team-bounces@lists.ubuntu.com 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 Signed-off-by: Dmitry Torokhov --- drivers/input/evdev.c | 22 +++++++++++++++++----- 1 files changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index 2ee6c7a..cff7bf9 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 #include @@ -36,13 +36,14 @@ struct evdev { }; struct evdev_client { - struct input_event buffer[EVDEV_BUFFER_SIZE]; int head; int tail; spinlock_t buffer_lock; /* protects access to buffer, head and tail */ struct fasync_struct *fasync; struct evdev *evdev; struct list_head node; + int bufsize; + struct input_event buffer[]; }; static struct evdev *evdev_table[EVDEV_MINORS]; @@ -56,7 +57,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) @@ -242,11 +243,17 @@ static int evdev_release(struct inode *inode, struct file *file) 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) { struct evdev *evdev; struct evdev_client *client; int i = iminor(inode) - EVDEV_MINOR_BASE; + unsigned int bufsize; int error; if (i >= EVDEV_MINORS) @@ -263,12 +270,17 @@ static int evdev_open(struct inode *inode, struct file *file) if (!evdev) 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) { error = -ENOMEM; goto err_put_evdev; } + client->bufsize = bufsize; spin_lock_init(&client->buffer_lock); client->evdev = evdev; evdev_attach_client(evdev, client); @@ -334,7 +346,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);