thinkpad_acpi: Factor out get/set adaptive kbd mode
Subsystems (2)
PATCH 2/6 thinkpad_acpi: Factor out get/set adaptive kbd mode
--- drivers/platform/x86/thinkpad_acpi.c | 61 ++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 23 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +38 -23
@@ -3480,6 +3480,32 @@ const int adaptive_keyboard_modes[] = {static bool adaptive_keyboard_mode_is_saved;static int adaptive_keyboard_prev_mode; +static int adaptive_keyboard_get_mode (void ) +{ +u32 mode =0 ; + +if (!acpi_evalf (hkey_handle, &mode,"GTRW" ,"dd" ,0 )) { +pr_err ("Cannot read adaptive keyboard mode\n" ); +return -EIO ; + } + +return mode; +} + +static int adaptive_keyboard_set_mode (int new_mode) +{ +if (new_mode <0 || + new_mode >LAYFLAT_MODE ) +return -EINVAL ; + +if (!acpi_evalf (hkey_handle,NULL ,"STRW" ,"vd" , new_mode)) { +pr_err ("Cannot set adaptive keyboard mode\n" ); +return -EIO ; + } + +return 0 ; +} +static int adaptive_keyboard_get_next_mode (int mode) {size_t i;
@@ -3509,39 +3535,28 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode) new_mode = adaptive_keyboard_prev_mode; adaptive_keyboard_mode_is_saved = false; }else { -if (!acpi_evalf ( - hkey_handle, ¤t_mode, -"GTRW" ,"dd" ,0 )) { -pr_err ("Cannot read adaptive keyboard mode\n" ); + current_mode =adaptive_keyboard_get_mode (); +if (current_mode <0 )return false; - }else { - new_mode =adaptive_keyboard_get_next_mode ( - current_mode); - } + new_mode =adaptive_keyboard_get_next_mode ( + current_mode); } -if (!acpi_evalf (hkey_handle,NULL ,"STRW" ,"vd" , new_mode)) { -pr_err ("Cannot set adaptive keyboard mode\n" ); +if (adaptive_keyboard_set_mode (new_mode) <0 )return false; - }return true;case DFR_SHOW_QUICKVIEW_ROW : -if (!acpi_evalf (hkey_handle, - &adaptive_keyboard_prev_mode, -"GTRW" ,"dd" ,0 )) { -pr_err ("Cannot read adaptive keyboard mode\n" ); + current_mode =adaptive_keyboard_get_mode (); +if (current_mode <0 )return false; - }else { - adaptive_keyboard_mode_is_saved = true; -if (!acpi_evalf (hkey_handle, -NULL ,"STRW" ,"vd" ,FUNCTION_MODE )) { -pr_err ("Cannot set adaptive keyboard mode\n" ); -return false; - } - } + adaptive_keyboard_prev_mode = current_mode; + adaptive_keyboard_mode_is_saved = true; + +if (adaptive_keyboard_set_mode (FUNCTION_MODE ) <0 ) +return false;return true;default :
Signature · 1 line
2.1.0
On Wed, Feb 18, 2015 at 09:53:35PM +0100, Bastien Nocera wrote:
Please provide a commit message. There is always something to say beyond what is in the subject. In this case, I suggest the motivation and justification for the change.
While I appreciate the abstraction, it makes the code at the call site easier to read, note that you added more code than you removed.
So, please provide a justificaiton.
Under no circumstances will I accept a patch without a commit message body.
Quoted 10 lines
Signed-off-by Bastien Nocera <[email protected]>--- drivers/platform/x86/thinkpad_acpi.c | 61 ++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 23 deletions(-)drivers/platform/x86/thinkpad_acpi.c +0
-0
drivers/platform/x86/thinkpad_acpi.c const int adaptive_keyboard_modes[] = { · line 3485
Quoted 6 lines
drivers/platform/x86/thinkpad_acpi.c +3
-0@@ -3480,6 +3480,32 @@ const int adaptive_keyboard_modes[] = {static bool adaptive_keyboard_mode_is_saved;static int adaptive_keyboard_prev_mode; +static int adaptive_keyboard_get_mode (void ) +{ +u32 mode =0 ;
acpi_evalf second argument takes an "int" and this function returns "int". Is there a reason to use u32 for mode?
...
Quoted 7 lines
drivers/platform/x86/thinkpad_acpi.c +0
-3@@ -3509,39 +3535,28 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode) new_mode = adaptive_keyboard_prev_mode; adaptive_keyboard_mode_is_saved = false; }else { -if (!acpi_evalf ( - hkey_handle, ¤t_mode, -"GTRW" ,"dd" ,0 )) {
drivers/platform/x86/thinkpad_acpi.c static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode) · line 3542
Quoted 10 lines
drivers/platform/x86/thinkpad_acpi.c +4
-5-pr_err ("Cannot read adaptive keyboard mode\n" ); + current_mode =adaptive_keyboard_get_mode (); +if (current_mode <0 )return false; - }else { - new_mode =adaptive_keyboard_get_next_mode ( - current_mode); - } + new_mode =adaptive_keyboard_get_next_mode ( + current_mode);
This now fits on one line I believe.
...
Signature · 2 lines
Darren Hart Intel Open Source Technology Center
Quoted 10 lines · Darren Hart
On Wed, Feb 18, 2015 at 09:53:35PM +0100, Bastien Nocera wrote:
Please provide a commit message. There is always something to say beyond what is in the subject. In this case, I suggest the motivation and justification for the change.
While I appreciate the abstraction, it makes the code at the call site easier to read, note that you added more code than you removed.
So, please provide a justificaiton.
Sure, done.
Quoted 15 lines
Under no circumstances will I accept a patch without a commit message body.
Quoted 13 lines
Signed-off-by Bastien Nocera <[email protected]>--- drivers/platform/x86/thinkpad_acpi.c | 61 ++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 23 deletions(-)drivers/platform/x86/thinkpad_acpi.c +0
-0@@ -3480,6 +3480,32 @@ const int adaptive_keyboard_modes[] = {static bool adaptive_keyboard_mode_is_saved;static int adaptive_keyboard_prev_mode;
Quoted 6 lines
drivers/platform/x86/thinkpad_acpi.c const int adaptive_keyboard_modes[] = { · line 3485
Quoted 3 lines
drivers/platform/x86/thinkpad_acpi.c +3
-0+static int adaptive_keyboard_get_mode (void ) +{ +u32 mode =0 ;
acpi_evalfsecond argument takes an "int" and this function returns "int". Is there a reason to use u32 for mode?
Used int, done.
Quoted 11 lines
Quoted 11 lines
drivers/platform/x86/thinkpad_acpi.c +2
-4@@ -3509,39 +3535,28 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode) new_mode = adaptive_keyboard_prev_mode; adaptive_keyboard_mode_is_saved = false; }else { -if (!acpi_evalf ( - hkey_handle, ¤t_mode, -"GTRW" ,"dd" ,0 )) { -pr_err ("Cannot read adaptive keyboard mode\n" ); + current_mode =adaptive_keyboard_get_mode (); +if (current_mode <0 )return false;
Quoted 8 lines
drivers/platform/x86/thinkpad_acpi.c static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode) · line 3542
Quoted 6 lines
drivers/platform/x86/thinkpad_acpi.c +2
-4- }else { - new_mode =adaptive_keyboard_get_next_mode ( - current_mode); - } + new_mode =adaptive_keyboard_get_next_mode ( + current_mode);This now fits on one line I believe.
Nope, 81 characters. I've kept it as-is.