fujitsu-laptop: acpi_fujitsu_notify() cleanup
Subsystems (2)
cover fujitsu-laptop: acpi_fujitsu_notify() cleanup
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(-)
Signature · 1 line
2.11.0
PATCH 1/2 platform/x86: fujitsu-laptop: decrease indentation in acpi_fujitsu_notify()
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.
---
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(-)
drivers/platform/x86/fujitsu-laptop.c +33 -31
@@ -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 ) {
Signature · 1 line
2.11.0
PATCH 2/2 platform/x86: fujitsu-laptop: simplify brightness key event generation logic
In reply to Michał Kępień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.
--- drivers/platform/x86/fujitsu-laptop.c | 37 +++++++++++++---------------------- 1 file changed, 14 insertions(+), 23 deletions(-)
drivers/platform/x86/fujitsu-laptop.c +14 -23
@@ -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 */
Signature · 1 line
2.11.0
Jonathan Woithe
maintainerHi Michael
Quoted 4 lines · Micha?? K??pie??
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.
Quoted 5 lines
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
Quoted 16 lines
Hi Michael
Quoted 4 lines · Micha?? K??pie??
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.
Quoted 5 lines
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.
Quoted 4 lines
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,
Signature · 2 lines
Best regards, Michał Kępień