public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] fujitsu-laptop: acpi_fujitsu_notify() cleanup
@ 2017-01-17 11:07 Michał Kępień
  2017-01-17 11:07 ` [PATCH 1/2] platform/x86: fujitsu-laptop: decrease indentation in acpi_fujitsu_notify() Michał Kępień
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Michał Kępień @ 2017-01-17 11:07 UTC (permalink / raw)
  To: Jonathan Woithe, Darren Hart; +Cc: platform-driver-x86, linux-kernel

Here are two minor cleanups for acpi_fujitsu_notify() that I came up
with while preparing the sparse keymap migration.  They can be reviewed
and applied independently of the other series for fujitsu-laptop I
posted recently.

Jonathan, I decided to post this after re-reading the subjects of Alan
Jenkins' cleanup patches - I believe his work should not overlap with
this series.  In case it does, feel free to ignore or postpone this
series.  Also, there is no rush to apply these, they are just a base for
the upcoming sparse keymap patches.

 drivers/platform/x86/fujitsu-laptop.c | 61 ++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 34 deletions(-)

-- 
2.11.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] platform/x86: fujitsu-laptop: decrease indentation in acpi_fujitsu_notify()
  2017-01-17 11:07 [PATCH 0/2] fujitsu-laptop: acpi_fujitsu_notify() cleanup Michał Kępień
@ 2017-01-17 11:07 ` Michał Kępień
  2017-01-17 11:07 ` [PATCH 2/2] platform/x86: fujitsu-laptop: simplify brightness key event generation logic Michał Kępień
  2017-01-17 11:19 ` [PATCH 0/2] fujitsu-laptop: acpi_fujitsu_notify() cleanup Jonathan Woithe
  2 siblings, 0 replies; 5+ messages in thread
From: Michał Kępień @ 2017-01-17 11:07 UTC (permalink / raw)
  To: Jonathan Woithe, Darren Hart; +Cc: platform-driver-x86, linux-kernel

acpi_fujitsu_notify() is pretty deeply nested, which hurts readability.
Strip off one level of indentation by returning early when the event
code supplied as argument is not ACPI_FUJITSU_NOTIFY_CODE1.

Signed-off-by: Michał Kępień <kernel@kempniu.pl>
---
Changes introduced by this patch are best viewed when whitespace changes
are ignored.

 drivers/platform/x86/fujitsu-laptop.c | 64 ++++++++++++++++++-----------------
 1 file changed, 33 insertions(+), 31 deletions(-)

diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
index 96f8163d5002..35c1319b7c8e 100644
--- a/drivers/platform/x86/fujitsu-laptop.c
+++ b/drivers/platform/x86/fujitsu-laptop.c
@@ -789,40 +789,42 @@ static void acpi_fujitsu_notify(struct acpi_device *device, u32 event)
 
 	input = fujitsu->input;
 
-	switch (event) {
-	case ACPI_FUJITSU_NOTIFY_CODE1:
-		keycode = 0;
-		oldb = fujitsu->brightness_level;
-		get_lcd_level();
-		newb = fujitsu->brightness_level;
-
-		vdbg_printk(FUJLAPTOP_DBG_TRACE,
-			    "brightness button event [%i -> %i (%i)]\n",
-			    oldb, newb, fujitsu->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;
-		}
-		break;
-	default:
+	if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
 		keycode = KEY_UNKNOWN;
 		vdbg_printk(FUJLAPTOP_DBG_WARN,
 			    "unsupported event [0x%x]\n", event);
-		break;
+		input_report_key(input, keycode, 1);
+		input_sync(input);
+		input_report_key(input, keycode, 0);
+		input_sync(input);
+		return;
+	}
+
+	keycode = 0;
+	oldb = fujitsu->brightness_level;
+	get_lcd_level();
+	newb = fujitsu->brightness_level;
+
+	vdbg_printk(FUJLAPTOP_DBG_TRACE,
+		    "brightness button event [%i -> %i (%i)]\n",
+		    oldb, newb, fujitsu->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 (keycode != 0) {
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] platform/x86: fujitsu-laptop: simplify brightness key event generation logic
  2017-01-17 11:07 [PATCH 0/2] fujitsu-laptop: acpi_fujitsu_notify() cleanup Michał Kępień
  2017-01-17 11:07 ` [PATCH 1/2] platform/x86: fujitsu-laptop: decrease indentation in acpi_fujitsu_notify() Michał Kępień
@ 2017-01-17 11:07 ` Michał Kępień
  2017-01-17 11:19 ` [PATCH 0/2] fujitsu-laptop: acpi_fujitsu_notify() cleanup Jonathan Woithe
  2 siblings, 0 replies; 5+ messages in thread
From: Michał Kępień @ 2017-01-17 11:07 UTC (permalink / raw)
  To: Jonathan Woithe, Darren Hart; +Cc: platform-driver-x86, linux-kernel

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.

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

diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
index 35c1319b7c8e..37b0fcecff51 100644
--- a/drivers/platform/x86/fujitsu-laptop.c
+++ b/drivers/platform/x86/fujitsu-laptop.c
@@ -800,7 +800,6 @@ static void acpi_fujitsu_notify(struct acpi_device *device, u32 event)
 		return;
 	}
 
-	keycode = 0;
 	oldb = fujitsu->brightness_level;
 	get_lcd_level();
 	newb = fujitsu->brightness_level;
@@ -809,30 +808,22 @@ static void acpi_fujitsu_notify(struct acpi_device *device, u32 event)
 		    "brightness button event [%i -> %i (%i)]\n",
 		    oldb, newb, fujitsu->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.11.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] fujitsu-laptop: acpi_fujitsu_notify() cleanup
  2017-01-17 11:07 [PATCH 0/2] fujitsu-laptop: acpi_fujitsu_notify() cleanup Michał Kępień
  2017-01-17 11:07 ` [PATCH 1/2] platform/x86: fujitsu-laptop: decrease indentation in acpi_fujitsu_notify() Michał Kępień
  2017-01-17 11:07 ` [PATCH 2/2] platform/x86: fujitsu-laptop: simplify brightness key event generation logic Michał Kępień
@ 2017-01-17 11:19 ` Jonathan Woithe
  2017-02-03 14:08   ` Michał Kępień
  2 siblings, 1 reply; 5+ messages in thread
From: Jonathan Woithe @ 2017-01-17 11:19 UTC (permalink / raw)
  To: Micha?? K??pie??; +Cc: Darren Hart, platform-driver-x86, linux-kernel

Hi Michael

On Tue, Jan 17, 2017 at 12:07:33PM +0100, Micha?? K??pie?? wrote:
> Here are two minor cleanups for acpi_fujitsu_notify() that I came up
> with while preparing the sparse keymap migration.  They can be reviewed
> and applied independently of the other series for fujitsu-laptop I
> posted recently.

Ok.

> Jonathan, I decided to post this after re-reading the subjects of Alan
> Jenkins' cleanup patches - I believe his work should not overlap with
> this series.  In case it does, feel free to ignore or postpone this
> series.  Also, there is no rush to apply these, they are just a base for
> the upcoming sparse keymap patches.

I understand.  Thanks for posting these.  Like the earlier patch series they
look fairly innoculous but I would like to run them up on my hardware just
to be sure.  I do not have the hardware with me at linux.conf.au so this can
only be done early next week.  Apologies for the delay.

Regards
  jonathan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] fujitsu-laptop: acpi_fujitsu_notify() cleanup
  2017-01-17 11:19 ` [PATCH 0/2] fujitsu-laptop: acpi_fujitsu_notify() cleanup Jonathan Woithe
@ 2017-02-03 14:08   ` Michał Kępień
  0 siblings, 0 replies; 5+ messages in thread
From: Michał Kępień @ 2017-02-03 14:08 UTC (permalink / raw)
  To: Darren Hart, Andy Shevchenko
  Cc: Jonathan Woithe, platform-driver-x86, linux-kernel

> Hi Michael
> 
> On Tue, Jan 17, 2017 at 12:07:33PM +0100, Micha?? K??pie?? wrote:
> > Here are two minor cleanups for acpi_fujitsu_notify() that I came up
> > with while preparing the sparse keymap migration.  They can be reviewed
> > and applied independently of the other series for fujitsu-laptop I
> > posted recently.
> 
> Ok.
> 
> > Jonathan, I decided to post this after re-reading the subjects of Alan
> > Jenkins' cleanup patches - I believe his work should not overlap with
> > this series.  In case it does, feel free to ignore or postpone this
> > series.  Also, there is no rush to apply these, they are just a base for
> > the upcoming sparse keymap patches.
> 
> I understand.  Thanks for posting these.  Like the earlier patch series they
> look fairly innoculous but I would like to run them up on my hardware just
> to be sure.  I do not have the hardware with me at linux.conf.au so this can
> only be done early next week.  Apologies for the delay.

Darren, Andy, please drop this patch series for now.  I will send a
rebased v2 after a long overdue patch series from Alan Jenkins gets
applied in a reworked form.

Thanks,

-- 
Best regards,
Michał Kępień

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-02-03 14:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-17 11:07 [PATCH 0/2] fujitsu-laptop: acpi_fujitsu_notify() cleanup Michał Kępień
2017-01-17 11:07 ` [PATCH 1/2] platform/x86: fujitsu-laptop: decrease indentation in acpi_fujitsu_notify() Michał Kępień
2017-01-17 11:07 ` [PATCH 2/2] platform/x86: fujitsu-laptop: simplify brightness key event generation logic Michał Kępień
2017-01-17 11:19 ` [PATCH 0/2] fujitsu-laptop: acpi_fujitsu_notify() cleanup Jonathan Woithe
2017-02-03 14:08   ` Michał Kępień

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox