From patchwork Wed Jan 11 08:59:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBLxJlwaWXFhA==?= X-Patchwork-Id: 9509559 X-Patchwork-Delegate: dvhart@infradead.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CD6D660231 for ; Wed, 11 Jan 2017 09:01:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC025285B8 for ; Wed, 11 Jan 2017 09:01:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B04092029C; Wed, 11 Jan 2017 09:01:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3EE592029C for ; Wed, 11 Jan 2017 09:01:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936883AbdAKJAf (ORCPT ); Wed, 11 Jan 2017 04:00:35 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:35479 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936800AbdAKI7n (ORCPT ); Wed, 11 Jan 2017 03:59:43 -0500 Received: by mail-lf0-f65.google.com with SMTP id v186so10771046lfa.2 for ; Wed, 11 Jan 2017 00:59:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kempniu.pl; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YvPLza8PCmOURsSdOXR0DMOAq+VVcbpTMw5b0JN2q2I=; b=WwwG7FVfPy3mk3zgbGbWib6I689GyT7c54dt8FRtwknRy3Gb1q5SgJMK3zF9nlKGlx weK3bPHccONxTeoAxFm0GGH76aJ+0Mz4lMjffekVf3VKEHkEU8Ke2sDvahEUF+ZYVs00 cOI/kK4vMzE/R6gDf68Ub7EgxVJhVVWvG2gLI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YvPLza8PCmOURsSdOXR0DMOAq+VVcbpTMw5b0JN2q2I=; b=jYZP36A1RkvIvML4g9deCvQySSLr4kKbbAChcGnMGlGEchHnUrnuzQJBODrhTeGmso 4utH2egCHovZ4BsY465V0kUIeICp9tgUU1A1urFhfVMmLvulsNtce0nHJ3IJCTQ1mmm0 roJoGZTr3jaRuXi6I3nhz8j1kcx5vSfnALCYNxCqwF6om9uONBMfUWfMSIizAV+o0MFS KaGP97kEUhgA0UOJ+hJvXKGZURhSY4xrscnIfsfKv1XHLzEvqF0w4Pe0mpT0IKFtqLNl hLBs+WD77hNzsIzmQI4Y7krbbMY9bvaSeYAtGiUFAZUIMae9iZJc18TQiuvk09Me8eXi foDg== X-Gm-Message-State: AIkVDXK67HNPtlMz3EZ0HnNDZeFpOb3o5CmAlgov4ntGI8Ev9HwHxWnnL93npvb6ws1trw== X-Received: by 10.25.79.71 with SMTP id a7mr2991576lfk.67.1484125181932; Wed, 11 Jan 2017 00:59:41 -0800 (PST) Received: from ozzy.nask.waw.pl ([2001:a10:160:3::3]) by smtp.googlemail.com with ESMTPSA id r127sm1157567lfr.3.2017.01.11.00.59.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jan 2017 00:59:41 -0800 (PST) From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= To: Jonathan Woithe , Darren Hart Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] platform/x86: fujitsu-laptop: move keycode processing to separate functions Date: Wed, 11 Jan 2017 09:59:31 +0100 Message-Id: <20170111085933.2486-3-kernel@kempniu.pl> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170111085933.2486-1-kernel@kempniu.pl> References: <20170111085933.2486-1-kernel@kempniu.pl> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP acpi_fujitsu_hotkey_notify() is pretty deeply nested, which hurts readability. Move the keycode processing part to two separate functions to make the code easier to understand and save a few line breaks. Rename variable keycode_r to keycode as there is no longer any need to differentiate between the two. Tweak indentations to make checkpatch happy. Signed-off-by: Michał Kępień Acked-by: Jonathan Woithe --- drivers/platform/x86/fujitsu-laptop.c | 76 ++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c index c2022f8af51b..e57d3724d2ce 100644 --- a/drivers/platform/x86/fujitsu-laptop.c +++ b/drivers/platform/x86/fujitsu-laptop.c @@ -1030,12 +1030,48 @@ static int acpi_fujitsu_hotkey_remove(struct acpi_device *device) return 0; } +static void acpi_fujitsu_hotkey_press(int keycode) +{ + struct input_dev *input = fujitsu_hotkey->input; + int status; + + vdbg_printk(FUJLAPTOP_DBG_TRACE, + "Push keycode into ringbuffer [%d]\n", keycode); + status = kfifo_in_locked(&fujitsu_hotkey->fifo, + (unsigned char *)&keycode, sizeof(keycode), + &fujitsu_hotkey->fifo_lock); + if (status != sizeof(keycode)) { + vdbg_printk(FUJLAPTOP_DBG_WARN, + "Could not push keycode [0x%x]\n", keycode); + } else { + input_report_key(input, keycode, 1); + input_sync(input); + } +} + +static void acpi_fujitsu_hotkey_release(void) +{ + struct input_dev *input = fujitsu_hotkey->input; + int keycode, status; + + while ((status = kfifo_out_locked(&fujitsu_hotkey->fifo, + (unsigned char *)&keycode, + sizeof(keycode), + &fujitsu_hotkey->fifo_lock)) + == sizeof(keycode)) { + input_report_key(input, keycode, 0); + input_sync(input); + vdbg_printk(FUJLAPTOP_DBG_TRACE, + "Pop keycode from ringbuffer [%d]\n", keycode); + } +} + static void acpi_fujitsu_hotkey_notify(struct acpi_device *device, u32 event) { struct input_dev *input; - int keycode, keycode_r; + int keycode; unsigned int irb = 1; - int i, status; + int i; input = fujitsu_hotkey->input; @@ -1083,37 +1119,11 @@ static void acpi_fujitsu_hotkey_notify(struct acpi_device *device, u32 event) keycode = -1; break; } - if (keycode > 0) { - vdbg_printk(FUJLAPTOP_DBG_TRACE, - "Push keycode into ringbuffer [%d]\n", - keycode); - status = kfifo_in_locked(&fujitsu_hotkey->fifo, - (unsigned char *)&keycode, - sizeof(keycode), - &fujitsu_hotkey->fifo_lock); - if (status != sizeof(keycode)) { - vdbg_printk(FUJLAPTOP_DBG_WARN, - "Could not push keycode [0x%x]\n", - keycode); - } else { - input_report_key(input, keycode, 1); - input_sync(input); - } - } else if (keycode == 0) { - while ((status = - kfifo_out_locked( - &fujitsu_hotkey->fifo, - (unsigned char *) &keycode_r, - sizeof(keycode_r), - &fujitsu_hotkey->fifo_lock)) - == sizeof(keycode_r)) { - input_report_key(input, keycode_r, 0); - input_sync(input); - vdbg_printk(FUJLAPTOP_DBG_TRACE, - "Pop keycode from ringbuffer [%d]\n", - keycode_r); - } - } + + if (keycode > 0) + acpi_fujitsu_hotkey_press(keycode); + else if (keycode == 0) + acpi_fujitsu_hotkey_release(); } /* On some models (first seen on the Skylake-based Lifebook