Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752420AbdFPEmn (ORCPT ); Fri, 16 Jun 2017 00:42:43 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:36116 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750866AbdFPElM (ORCPT ); Fri, 16 Jun 2017 00:41:12 -0400 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= To: Jonathan Woithe , Darren Hart , Andy Shevchenko Cc: platform-driver-x86@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/7] platform/x86: fujitsu-laptop: do not use kfifo for storing hotkey scancodes Date: Fri, 16 Jun 2017 06:40:52 +0200 Message-Id: <20170616044058.30443-2-kernel@kempniu.pl> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20170616044058.30443-1-kernel@kempniu.pl> References: <20170616044058.30443-1-kernel@kempniu.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4908 Lines: 157 All ACPI device notify callbacks are invoked using acpi_os_execute(), which causes the supplied callback to be queued to a static workqueue which always executes on CPU 0. This means that there is no possibility for any ACPI device notify callback to be concurrently executed on multiple CPUs, which in the case of fujitsu-laptop means that using a locked kfifo for handling hotkeys is redundant: as hotkey scancodes are only pushed and popped from within acpi_fujitsu_laptop_notify(), no risk of concurrent pushing and popping exists. Instead of a kfifo, use a fixed-size integer table for storing pushed scancodes and an associated variable holding the number of scancodes currently stored in that table. Change debug messages so that they no longer contain the term "ringbuffer". In order to simplify implementation, hotkey input device behavior is slightly changed (from FIFO to LIFO). The order of release events generated by the input device should not matter from end user perspective as upon releasing any hotkey the firmware only produces a single event which means "all hotkeys were released". Signed-off-by: Michał Kępień --- drivers/platform/x86/fujitsu-laptop.c | 54 +++++++++-------------------------- 1 file changed, 14 insertions(+), 40 deletions(-) diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c index 1c6fdd952c75..54cb7ae541d4 100644 --- a/drivers/platform/x86/fujitsu-laptop.c +++ b/drivers/platform/x86/fujitsu-laptop.c @@ -58,7 +58,6 @@ #include #include #include -#include #include #include #include @@ -110,7 +109,6 @@ #define KEY5_CODE 0x420 #define MAX_HOTKEY_RINGBUFFER_SIZE 100 -#define RINGBUFFERSIZE 40 /* Debugging */ #define FUJLAPTOP_DBG_ERROR 0x0001 @@ -146,8 +144,8 @@ struct fujitsu_laptop { struct input_dev *input; char phys[32]; struct platform_device *pf_device; - struct kfifo fifo; - spinlock_t fifo_lock; + int scancode_buf[40]; + int scancode_count; int flags_supported; int flags_state; }; @@ -813,23 +811,14 @@ static int acpi_fujitsu_laptop_add(struct acpi_device *device) sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS); device->driver_data = priv; - /* kfifo */ - spin_lock_init(&priv->fifo_lock); - error = kfifo_alloc(&priv->fifo, RINGBUFFERSIZE * sizeof(int), - GFP_KERNEL); - if (error) { - pr_err("kfifo_alloc failed\n"); - goto err_stop; - } - error = acpi_fujitsu_laptop_input_setup(device); if (error) - goto err_free_fifo; + return error; error = acpi_bus_update_power(device->handle, &state); if (error) { pr_err("Error reading power state\n"); - goto err_free_fifo; + return error; } pr_info("ACPI: %s [%s] (%s)\n", @@ -877,62 +866,47 @@ static int acpi_fujitsu_laptop_add(struct acpi_device *device) error = acpi_fujitsu_laptop_leds_register(device); if (error) - goto err_free_fifo; + return error; error = fujitsu_laptop_platform_add(device); if (error) - goto err_free_fifo; + return error; return 0; - -err_free_fifo: - kfifo_free(&priv->fifo); -err_stop: - return error; } static int acpi_fujitsu_laptop_remove(struct acpi_device *device) { - struct fujitsu_laptop *priv = acpi_driver_data(device); - fujitsu_laptop_platform_remove(device); - kfifo_free(&priv->fifo); - return 0; } static void acpi_fujitsu_laptop_press(struct acpi_device *device, int scancode) { struct fujitsu_laptop *priv = acpi_driver_data(device); - int status; - status = kfifo_in_locked(&priv->fifo, (unsigned char *)&scancode, - sizeof(scancode), &priv->fifo_lock); - if (status != sizeof(scancode)) { + if (priv->scancode_count == ARRAY_SIZE(priv->scancode_buf)) { vdbg_printk(FUJLAPTOP_DBG_WARN, "Could not push scancode [0x%x]\n", scancode); return; } + priv->scancode_buf[priv->scancode_count++] = scancode; sparse_keymap_report_event(priv->input, scancode, 1, false); vdbg_printk(FUJLAPTOP_DBG_TRACE, - "Push scancode into ringbuffer [0x%x]\n", scancode); + "Push scancode into buffer [0x%x]\n", scancode); } static void acpi_fujitsu_laptop_release(struct acpi_device *device) { struct fujitsu_laptop *priv = acpi_driver_data(device); - int scancode, status; - - while (true) { - status = kfifo_out_locked(&priv->fifo, - (unsigned char *)&scancode, - sizeof(scancode), &priv->fifo_lock); - if (status != sizeof(scancode)) - return; + int scancode; + + while (priv->scancode_count > 0) { + scancode = priv->scancode_buf[--priv->scancode_count]; sparse_keymap_report_event(priv->input, scancode, 0, false); vdbg_printk(FUJLAPTOP_DBG_TRACE, - "Pop scancode from ringbuffer [0x%x]\n", scancode); + "Pop scancode from buffer [0x%x]\n", scancode); } } -- 2.13.1