From patchwork Thu Jun 3 08:01:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henrik Rydberg X-Patchwork-Id: 104051 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o5383SGF018576 for ; Thu, 3 Jun 2010 08:03:28 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932558Ab0FCICZ (ORCPT ); Thu, 3 Jun 2010 04:02:25 -0400 Received: from ch-smtp02.sth.basefarm.net ([80.76.149.213]:52491 "EHLO ch-smtp02.sth.basefarm.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757973Ab0FCICW (ORCPT ); Thu, 3 Jun 2010 04:02:22 -0400 Received: from c83-248-196-134.bredband.comhem.se ([83.248.196.134]:38568 helo=alnilam) by ch-smtp02.sth.basefarm.net with smtp (Exim 4.68) (envelope-from ) id 1OK5Mu-0000tb-7y; Thu, 03 Jun 2010 10:01:39 +0200 Received: by alnilam (sSMTP sendmail emulation); Thu, 03 Jun 2010 10:01:36 +0200 From: "Henrik Rydberg" To: Dmitry Torokhov Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Kosina , Mika Kuoppala , Benjamin Tissoires , Rafi Rubin , Henrik Rydberg Subject: [PATCH 3/4] input: evdev: Convert to dynamic event buffer (rev3) Date: Thu, 3 Jun 2010 10:01:01 +0200 Message-Id: <1275552062-8153-4-git-send-email-rydberg@euromail.se> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1275552062-8153-3-git-send-email-rydberg@euromail.se> References: <1275552062-8153-1-git-send-email-rydberg@euromail.se> <1275552062-8153-2-git-send-email-rydberg@euromail.se> <1275552062-8153-3-git-send-email-rydberg@euromail.se> X-Originating-IP: 83.248.196.134 X-Scan-Result: No virus found in message 1OK5Mu-0000tb-7y. X-Scan-Signature: ch-smtp02.sth.basefarm.net 1OK5Mu-0000tb-7y e25adbad41877d93ed15e070f89d9980 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 03 Jun 2010 08:03:28 +0000 (UTC) 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 #include @@ -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;