mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Michał Kępień" <kernel@kempniu.pl>
To: Jonathan Woithe <jwoithe@just42.net>,
	Darren Hart <dvhart@infradead.org>,
	Andy Shevchenko <andy@infradead.org>
Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/2] platform/x86: fujitsu-laptop: simplify brightness key event generation logic
Date: Wed,  1 Mar 2017 07:42:54 +0100	[thread overview]
Message-ID: <20170301064254.1311-3-kernel@kempniu.pl> (raw)
In-Reply-To: <20170301064254.1311-1-kernel@kempniu.pl>

Returning early when there is no brightness change allows removal of a
duplicate code block, makes the purpose of the following code clearer
and allows the condition surrounding key event generation to be removed.
Local integer variables can also be declared in a single line.

Signed-off-by: Michał Kępień <kernel@kempniu.pl>
---
 drivers/platform/x86/fujitsu-laptop.c | 40 +++++++++++++----------------------
 1 file changed, 15 insertions(+), 25 deletions(-)

diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
index b19f6e1c0173..4a5e7b60a672 100644
--- a/drivers/platform/x86/fujitsu-laptop.c
+++ b/drivers/platform/x86/fujitsu-laptop.c
@@ -790,8 +790,7 @@ static int acpi_fujitsu_bl_remove(struct acpi_device *device)
 static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
 {
 	struct input_dev *input;
-	int keycode;
-	int oldb, newb;
+	int oldb, newb, keycode;
 
 	input = fujitsu_bl->input;
 
@@ -806,7 +805,6 @@ static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
 		return;
 	}
 
-	keycode = 0;
 	oldb = fujitsu_bl->brightness_level;
 	get_lcd_level();
 	newb = fujitsu_bl->brightness_level;
@@ -815,30 +813,22 @@ static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
 		    "brightness button event [%i -> %i (%i)]\n",
 		    oldb, newb, fujitsu_bl->brightness_changed);
 
-	if (oldb < newb) {
-		if (disable_brightness_adjust != 1) {
-			if (use_alt_lcd_levels)
-				set_lcd_level_alt(newb);
-			else
-				set_lcd_level(newb);
-		}
-		keycode = KEY_BRIGHTNESSUP;
-	} else if (oldb > newb) {
-		if (disable_brightness_adjust != 1) {
-			if (use_alt_lcd_levels)
-				set_lcd_level_alt(newb);
-			else
-				set_lcd_level(newb);
-		}
-		keycode = KEY_BRIGHTNESSDOWN;
-	}
+	if (oldb == newb)
+		return;
 
-	if (keycode != 0) {
-		input_report_key(input, keycode, 1);
-		input_sync(input);
-		input_report_key(input, keycode, 0);
-		input_sync(input);
+	if (disable_brightness_adjust != 1) {
+		if (use_alt_lcd_levels)
+			set_lcd_level_alt(newb);
+		else
+			set_lcd_level(newb);
 	}
+
+	keycode = oldb < newb ? KEY_BRIGHTNESSUP : KEY_BRIGHTNESSDOWN;
+
+	input_report_key(input, keycode, 1);
+	input_sync(input);
+	input_report_key(input, keycode, 0);
+	input_sync(input);
 }
 
 /* ACPI device for hotkey handling */
-- 
2.12.0

  parent reply	other threads:[~2017-03-01  6:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-01  6:42 [PATCH v2 0/2] fujitsu-laptop: acpi_fujitsu_bl_notify() cleanup Michał Kępień
2017-03-01  6:42 ` [PATCH v2 1/2] platform/x86: fujitsu-laptop: decrease indentation in acpi_fujitsu_bl_notify() Michał Kępień
2017-03-01  6:42 ` Michał Kępień [this message]
2017-03-01 22:34 ` [PATCH v2 0/2] fujitsu-laptop: acpi_fujitsu_bl_notify() cleanup Jonathan Woithe
2017-03-05 22:57 ` Jonathan Woithe
2017-03-13 16:01   ` Andy Shevchenko

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=20170301064254.1311-3-kernel@kempniu.pl \
    --to=kernel@kempniu.pl \
    --cc=andy@infradead.org \
    --cc=dvhart@infradead.org \
    --cc=jwoithe@just42.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®