Commit 26217796 authored by Barnabás Pőcze's avatar Barnabás Pőcze Committed by Hans de Goede

platform/x86: thinkpad_acpi: use strstarts()

There is a function, `strstarts()`, in linux/string.h
to check if a string is prefix of another. So remove
the custom version from the driver.
Signed-off-by: default avatarBarnabás Pőcze <pobrn@protonmail.com>
Link: https://lore.kernel.org/r/20221021180007.55535-1-pobrn@protonmail.comReviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent 6e9b8992
...@@ -265,9 +265,6 @@ enum tpacpi_hkey_event_t { ...@@ -265,9 +265,6 @@ enum tpacpi_hkey_event_t {
#define FAN_NOT_PRESENT 65535 #define FAN_NOT_PRESENT 65535
#define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
/**************************************************************************** /****************************************************************************
* Driver-wide structs and misc. variables * Driver-wide structs and misc. variables
*/ */
...@@ -1335,9 +1332,9 @@ static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id, char *buf) ...@@ -1335,9 +1332,9 @@ static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id, char *buf)
return -ENODEV; return -ENODEV;
while ((cmd = strsep(&buf, ","))) { while ((cmd = strsep(&buf, ","))) {
if (strlencmp(cmd, "enable") == 0) if (strstarts(cmd, "enable"))
status = TPACPI_RFK_RADIO_ON; status = TPACPI_RFK_RADIO_ON;
else if (strlencmp(cmd, "disable") == 0) else if (strstarts(cmd, "disable"))
status = TPACPI_RFK_RADIO_OFF; status = TPACPI_RFK_RADIO_OFF;
else else
return -EINVAL; return -EINVAL;
...@@ -4198,12 +4195,12 @@ static int hotkey_write(char *buf) ...@@ -4198,12 +4195,12 @@ static int hotkey_write(char *buf)
res = 0; res = 0;
while ((cmd = strsep(&buf, ","))) { while ((cmd = strsep(&buf, ","))) {
if (strlencmp(cmd, "enable") == 0) { if (strstarts(cmd, "enable")) {
hotkey_enabledisable_warn(1); hotkey_enabledisable_warn(1);
} else if (strlencmp(cmd, "disable") == 0) { } else if (strstarts(cmd, "disable")) {
hotkey_enabledisable_warn(0); hotkey_enabledisable_warn(0);
res = -EPERM; res = -EPERM;
} else if (strlencmp(cmd, "reset") == 0) { } else if (strstarts(cmd, "reset")) {
mask = (hotkey_all_mask | hotkey_source_mask) mask = (hotkey_all_mask | hotkey_source_mask)
& ~hotkey_reserved_mask; & ~hotkey_reserved_mask;
} else if (sscanf(cmd, "0x%x", &mask) == 1) { } else if (sscanf(cmd, "0x%x", &mask) == 1) {
...@@ -5233,33 +5230,33 @@ static int video_write(char *buf) ...@@ -5233,33 +5230,33 @@ static int video_write(char *buf)
disable = 0; disable = 0;
while ((cmd = strsep(&buf, ","))) { while ((cmd = strsep(&buf, ","))) {
if (strlencmp(cmd, "lcd_enable") == 0) { if (strstarts(cmd, "lcd_enable")) {
enable |= TP_ACPI_VIDEO_S_LCD; enable |= TP_ACPI_VIDEO_S_LCD;
} else if (strlencmp(cmd, "lcd_disable") == 0) { } else if (strstarts(cmd, "lcd_disable")) {
disable |= TP_ACPI_VIDEO_S_LCD; disable |= TP_ACPI_VIDEO_S_LCD;
} else if (strlencmp(cmd, "crt_enable") == 0) { } else if (strstarts(cmd, "crt_enable")) {
enable |= TP_ACPI_VIDEO_S_CRT; enable |= TP_ACPI_VIDEO_S_CRT;
} else if (strlencmp(cmd, "crt_disable") == 0) { } else if (strstarts(cmd, "crt_disable")) {
disable |= TP_ACPI_VIDEO_S_CRT; disable |= TP_ACPI_VIDEO_S_CRT;
} else if (video_supported == TPACPI_VIDEO_NEW && } else if (video_supported == TPACPI_VIDEO_NEW &&
strlencmp(cmd, "dvi_enable") == 0) { strstarts(cmd, "dvi_enable")) {
enable |= TP_ACPI_VIDEO_S_DVI; enable |= TP_ACPI_VIDEO_S_DVI;
} else if (video_supported == TPACPI_VIDEO_NEW && } else if (video_supported == TPACPI_VIDEO_NEW &&
strlencmp(cmd, "dvi_disable") == 0) { strstarts(cmd, "dvi_disable")) {
disable |= TP_ACPI_VIDEO_S_DVI; disable |= TP_ACPI_VIDEO_S_DVI;
} else if (strlencmp(cmd, "auto_enable") == 0) { } else if (strstarts(cmd, "auto_enable")) {
res = video_autosw_set(1); res = video_autosw_set(1);
if (res) if (res)
return res; return res;
} else if (strlencmp(cmd, "auto_disable") == 0) { } else if (strstarts(cmd, "auto_disable")) {
res = video_autosw_set(0); res = video_autosw_set(0);
if (res) if (res)
return res; return res;
} else if (strlencmp(cmd, "video_switch") == 0) { } else if (strstarts(cmd, "video_switch")) {
res = video_outputsw_cycle(); res = video_outputsw_cycle();
if (res) if (res)
return res; return res;
} else if (strlencmp(cmd, "expand_toggle") == 0) { } else if (strstarts(cmd, "expand_toggle")) {
res = video_expand_toggle(); res = video_expand_toggle();
if (res) if (res)
return res; return res;
...@@ -5653,9 +5650,9 @@ static int light_write(char *buf) ...@@ -5653,9 +5650,9 @@ static int light_write(char *buf)
return -ENODEV; return -ENODEV;
while ((cmd = strsep(&buf, ","))) { while ((cmd = strsep(&buf, ","))) {
if (strlencmp(cmd, "on") == 0) { if (strstarts(cmd, "on")) {
newstatus = 1; newstatus = 1;
} else if (strlencmp(cmd, "off") == 0) { } else if (strstarts(cmd, "off")) {
newstatus = 0; newstatus = 0;
} else } else
return -EINVAL; return -EINVAL;
...@@ -7126,10 +7123,10 @@ static int brightness_write(char *buf) ...@@ -7126,10 +7123,10 @@ static int brightness_write(char *buf)
return level; return level;
while ((cmd = strsep(&buf, ","))) { while ((cmd = strsep(&buf, ","))) {
if (strlencmp(cmd, "up") == 0) { if (strstarts(cmd, "up")) {
if (level < bright_maxlvl) if (level < bright_maxlvl)
level++; level++;
} else if (strlencmp(cmd, "down") == 0) { } else if (strstarts(cmd, "down")) {
if (level > 0) if (level > 0)
level--; level--;
} else if (sscanf(cmd, "level %d", &level) == 1 && } else if (sscanf(cmd, "level %d", &level) == 1 &&
...@@ -7878,13 +7875,13 @@ static int volume_write(char *buf) ...@@ -7878,13 +7875,13 @@ static int volume_write(char *buf)
while ((cmd = strsep(&buf, ","))) { while ((cmd = strsep(&buf, ","))) {
if (!tp_features.mixer_no_level_control) { if (!tp_features.mixer_no_level_control) {
if (strlencmp(cmd, "up") == 0) { if (strstarts(cmd, "up")) {
if (new_mute) if (new_mute)
new_mute = 0; new_mute = 0;
else if (new_level < TP_EC_VOLUME_MAX) else if (new_level < TP_EC_VOLUME_MAX)
new_level++; new_level++;
continue; continue;
} else if (strlencmp(cmd, "down") == 0) { } else if (strstarts(cmd, "down")) {
if (new_mute) if (new_mute)
new_mute = 0; new_mute = 0;
else if (new_level > 0) else if (new_level > 0)
...@@ -7896,9 +7893,9 @@ static int volume_write(char *buf) ...@@ -7896,9 +7893,9 @@ static int volume_write(char *buf)
continue; continue;
} }
} }
if (strlencmp(cmd, "mute") == 0) if (strstarts(cmd, "mute"))
new_mute = TP_EC_AUDIO_MUTESW_MSK; new_mute = TP_EC_AUDIO_MUTESW_MSK;
else if (strlencmp(cmd, "unmute") == 0) else if (strstarts(cmd, "unmute"))
new_mute = 0; new_mute = 0;
else else
return -EINVAL; return -EINVAL;
...@@ -9121,10 +9118,9 @@ static int fan_write_cmd_level(const char *cmd, int *rc) ...@@ -9121,10 +9118,9 @@ static int fan_write_cmd_level(const char *cmd, int *rc)
{ {
int level; int level;
if (strlencmp(cmd, "level auto") == 0) if (strstarts(cmd, "level auto"))
level = TP_EC_FAN_AUTO; level = TP_EC_FAN_AUTO;
else if ((strlencmp(cmd, "level disengaged") == 0) || else if (strstarts(cmd, "level disengaged") || strstarts(cmd, "level full-speed"))
(strlencmp(cmd, "level full-speed") == 0))
level = TP_EC_FAN_FULLSPEED; level = TP_EC_FAN_FULLSPEED;
else if (sscanf(cmd, "level %d", &level) != 1) else if (sscanf(cmd, "level %d", &level) != 1)
return 0; return 0;
...@@ -9142,7 +9138,7 @@ static int fan_write_cmd_level(const char *cmd, int *rc) ...@@ -9142,7 +9138,7 @@ static int fan_write_cmd_level(const char *cmd, int *rc)
static int fan_write_cmd_enable(const char *cmd, int *rc) static int fan_write_cmd_enable(const char *cmd, int *rc)
{ {
if (strlencmp(cmd, "enable") != 0) if (!strstarts(cmd, "enable"))
return 0; return 0;
*rc = fan_set_enable(); *rc = fan_set_enable();
...@@ -9157,7 +9153,7 @@ static int fan_write_cmd_enable(const char *cmd, int *rc) ...@@ -9157,7 +9153,7 @@ static int fan_write_cmd_enable(const char *cmd, int *rc)
static int fan_write_cmd_disable(const char *cmd, int *rc) static int fan_write_cmd_disable(const char *cmd, int *rc)
{ {
if (strlencmp(cmd, "disable") != 0) if (!strstarts(cmd, "disable"))
return 0; return 0;
*rc = fan_set_disable(); *rc = fan_set_disable();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment