All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darren Hart (VMware)" <dvhart@infradead.org>
To: platform-driver-x86@vger.kernel.org
Cc: LKML <linux-kernel@vger.kernel.org>,
	"Stefan Brüns" <stefan.bruens@rwth-aachen.de>,
	"AceLan Kao" <acelan.kao@canonical.com>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>
Subject: [PATCH] platform/x86: intel-vbtn: Simplify autorelease logic
Date: Fri, 8 Dec 2017 15:07:08 -0800	[thread overview]
Message-ID: <eb2e1de12dad4c11454b009075f916c63de8a2a6.1512774279.git.dvhart@infradead.org> (raw)

The new notify_handler logic determining if autorelease should be used or
not is a bit awkward, and can result in more than one call to
sparse_keymap_report_event for the same event (scancode). The nesting
and long lines also made it difficult to read.

Simplify the logic by eliminating a level of nesting with a goto and
always calculate autorelease and val so we can make a single call to
sparse_keymap_report_event.

Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>
Cc: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Cc: AceLan Kao <acelan.kao@canonical.com>
---
Note: This is based on top of Stefan's v2 patch series for intel-vbtn, currently
      in my review-dvhart branch.

 drivers/platform/x86/intel-vbtn.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/platform/x86/intel-vbtn.c b/drivers/platform/x86/intel-vbtn.c
index 0861efe..297e1ac 100644
--- a/drivers/platform/x86/intel-vbtn.c
+++ b/drivers/platform/x86/intel-vbtn.c
@@ -80,6 +80,7 @@ static void notify_handler(acpi_handle handle, u32 event, void *context)
 {
 	struct platform_device *device = context;
 	struct intel_vbtn_priv *priv = dev_get_drvdata(&device->dev);
+	unsigned int val = !(event & 1); /* Even=press, Odd=release */
 	const struct key_entry *ke_rel;
 	bool autorelease;
 
@@ -88,20 +89,20 @@ static void notify_handler(acpi_handle handle, u32 event, void *context)
 			pm_wakeup_hard_event(&device->dev);
 			return;
 		}
-	} else {
-		/* Use the fact press/release come in even/odd pairs */
-		if ((event & 1) && sparse_keymap_report_event(priv->input_dev,
-							      event, 0, false))
-			return;
+		goto out_unknown;
+	}
 
-		ke_rel = sparse_keymap_entry_from_scancode(priv->input_dev,
-							   event | 1);
-		autorelease = !ke_rel || ke_rel->type == KE_IGNORE;
+	/*
+	 * Event press events are autorelease if there is no corresponding odd
+	 * release event, or if the odd event is KE_IGNORE.
+	 */
+	ke_rel = sparse_keymap_entry_from_scancode(priv->input_dev, event | 1);
+	autorelease = val && (!ke_rel || ke_rel->type == KE_IGNORE);
 
-		if (sparse_keymap_report_event(priv->input_dev, event, 1,
-					       autorelease))
-			return;
-	}
+	if (sparse_keymap_report_event(priv->input_dev, event, val, autorelease))
+		return;
+
+out_unknown:
 	dev_dbg(&device->dev, "unknown event index 0x%x\n", event);
 }
 
-- 
2.9.4


-- 
Darren Hart
VMware Open Source Technology Center

             reply	other threads:[~2017-12-08 23:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-08 23:07 Darren Hart (VMware) [this message]
2017-12-08 23:28 ` [PATCH] platform/x86: intel-vbtn: Simplify autorelease logic Stefan Brüns
2017-12-08 23:28   ` Stefan Brüns
2017-12-08 23:48   ` Darren Hart
2017-12-11  1:48 ` Stefan Brüns
2017-12-11  1:48   ` Stefan Brüns
2017-12-12  0:31   ` Darren Hart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eb2e1de12dad4c11454b009075f916c63de8a2a6.1512774279.git.dvhart@infradead.org \
    --to=dvhart@infradead.org \
    --cc=acelan.kao@canonical.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=stefan.bruens@rwth-aachen.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.