Skip to content

Commit be51bd4

Browse files
committed
platform/x86: thinkpad_acpi: Replace next_cmd(&buf) with strsep(&buf, ",")
It seems next_cmd() predates the strsep() implementation in the kernel. For a long time we have the latter one, thus, replace next_cmd(&buf) with strsep(&buf, ","). Signed-off-by: Andy Shevchenko <[email protected]>
1 parent dd950f1 commit be51bd4

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

drivers/platform/x86/thinkpad_acpi.c

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -885,10 +885,10 @@ static ssize_t dispatch_proc_write(struct file *file,
885885

886886
if (!ibm || !ibm->write)
887887
return -EINVAL;
888-
if (count > PAGE_SIZE - 2)
888+
if (count > PAGE_SIZE - 1)
889889
return -EINVAL;
890890

891-
kernbuf = kmalloc(count + 2, GFP_KERNEL);
891+
kernbuf = kmalloc(count + 1, GFP_KERNEL);
892892
if (!kernbuf)
893893
return -ENOMEM;
894894

@@ -898,7 +898,6 @@ static ssize_t dispatch_proc_write(struct file *file,
898898
}
899899

900900
kernbuf[count] = 0;
901-
strcat(kernbuf, ",");
902901
ret = ibm->write(kernbuf);
903902
if (ret == 0)
904903
ret = count;
@@ -916,23 +915,6 @@ static const struct proc_ops dispatch_proc_ops = {
916915
.proc_write = dispatch_proc_write,
917916
};
918917

919-
static char *next_cmd(char **cmds)
920-
{
921-
char *start = *cmds;
922-
char *end;
923-
924-
while ((end = strchr(start, ',')) && end == start)
925-
start = end + 1;
926-
927-
if (!end)
928-
return NULL;
929-
930-
*end = 0;
931-
*cmds = end + 1;
932-
return start;
933-
}
934-
935-
936918
/****************************************************************************
937919
****************************************************************************
938920
*
@@ -1423,7 +1405,7 @@ static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id, char *buf)
14231405
if (id >= TPACPI_RFK_SW_MAX)
14241406
return -ENODEV;
14251407

1426-
while ((cmd = next_cmd(&buf))) {
1408+
while ((cmd = strsep(&buf, ","))) {
14271409
if (strlencmp(cmd, "enable") == 0)
14281410
status = TPACPI_RFK_RADIO_ON;
14291411
else if (strlencmp(cmd, "disable") == 0)
@@ -4306,7 +4288,7 @@ static int hotkey_write(char *buf)
43064288
mask = hotkey_user_mask;
43074289

43084290
res = 0;
4309-
while ((cmd = next_cmd(&buf))) {
4291+
while ((cmd = strsep(&buf, ","))) {
43104292
if (strlencmp(cmd, "enable") == 0) {
43114293
hotkey_enabledisable_warn(1);
43124294
} else if (strlencmp(cmd, "disable") == 0) {
@@ -5233,7 +5215,7 @@ static int video_write(char *buf)
52335215
enable = 0;
52345216
disable = 0;
52355217

5236-
while ((cmd = next_cmd(&buf))) {
5218+
while ((cmd = strsep(&buf, ","))) {
52375219
if (strlencmp(cmd, "lcd_enable") == 0) {
52385220
enable |= TP_ACPI_VIDEO_S_LCD;
52395221
} else if (strlencmp(cmd, "lcd_disable") == 0) {
@@ -5477,7 +5459,7 @@ static int kbdlight_write(char *buf)
54775459
if (!tp_features.kbdlight)
54785460
return -ENODEV;
54795461

5480-
while ((cmd = next_cmd(&buf))) {
5462+
while ((cmd = strsep(&buf, ","))) {
54815463
if (strlencmp(cmd, "0") == 0)
54825464
level = 0;
54835465
else if (strlencmp(cmd, "1") == 0)
@@ -5657,7 +5639,7 @@ static int light_write(char *buf)
56575639
if (!tp_features.light)
56585640
return -ENODEV;
56595641

5660-
while ((cmd = next_cmd(&buf))) {
5642+
while ((cmd = strsep(&buf, ","))) {
56615643
if (strlencmp(cmd, "on") == 0) {
56625644
newstatus = 1;
56635645
} else if (strlencmp(cmd, "off") == 0) {
@@ -5742,7 +5724,7 @@ static int cmos_write(char *buf)
57425724
char *cmd;
57435725
int cmos_cmd, res;
57445726

5745-
while ((cmd = next_cmd(&buf))) {
5727+
while ((cmd = strsep(&buf, ","))) {
57465728
if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
57475729
cmos_cmd >= 0 && cmos_cmd <= 21) {
57485730
/* cmos_cmd set */
@@ -6131,7 +6113,7 @@ static int led_write(char *buf)
61316113
if (!led_supported)
61326114
return -ENODEV;
61336115

6134-
while ((cmd = next_cmd(&buf))) {
6116+
while ((cmd = strsep(&buf, ","))) {
61356117
if (sscanf(cmd, "%d", &led) != 1)
61366118
return -EINVAL;
61376119

@@ -6218,7 +6200,7 @@ static int beep_write(char *buf)
62186200
if (!beep_handle)
62196201
return -ENODEV;
62206202

6221-
while ((cmd = next_cmd(&buf))) {
6203+
while ((cmd = strsep(&buf, ","))) {
62226204
if (sscanf(cmd, "%u", &beep_cmd) == 1 &&
62236205
beep_cmd >= 0 && beep_cmd <= 17) {
62246206
/* beep_cmd set */
@@ -7106,7 +7088,7 @@ static int brightness_write(char *buf)
71067088
if (level < 0)
71077089
return level;
71087090

7109-
while ((cmd = next_cmd(&buf))) {
7091+
while ((cmd = strsep(&buf, ","))) {
71107092
if (strlencmp(cmd, "up") == 0) {
71117093
if (level < bright_maxlvl)
71127094
level++;
@@ -7858,7 +7840,7 @@ static int volume_write(char *buf)
78587840
new_level = s & TP_EC_AUDIO_LVL_MSK;
78597841
new_mute = s & TP_EC_AUDIO_MUTESW_MSK;
78607842

7861-
while ((cmd = next_cmd(&buf))) {
7843+
while ((cmd = strsep(&buf, ","))) {
78627844
if (!tp_features.mixer_no_level_control) {
78637845
if (strlencmp(cmd, "up") == 0) {
78647846
if (new_mute)
@@ -9168,7 +9150,7 @@ static int fan_write(char *buf)
91689150
char *cmd;
91699151
int rc = 0;
91709152

9171-
while (!rc && (cmd = next_cmd(&buf))) {
9153+
while (!rc && (cmd = strsep(&buf, ","))) {
91729154
if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) &&
91739155
fan_write_cmd_level(cmd, &rc)) &&
91749156
!((fan_control_commands & TPACPI_FAN_CMD_ENABLE) &&
@@ -9807,7 +9789,7 @@ static int lcdshadow_write(char *buf)
98079789
if (lcdshadow_state < 0)
98089790
return -ENODEV;
98099791

9810-
while ((cmd = next_cmd(&buf))) {
9792+
while ((cmd = strsep(&buf, ","))) {
98119793
if (strlencmp(cmd, "0") == 0)
98129794
state = 0;
98139795
else if (strlencmp(cmd, "1") == 0)
@@ -10330,10 +10312,9 @@ static int __init set_ibm_param(const char *val, const struct kernel_param *kp)
1033010312
continue;
1033110313

1033210314
if (strcmp(ibm->name, kp->name) == 0 && ibm->write) {
10333-
if (strlen(val) > sizeof(ibms_init[i].param) - 2)
10315+
if (strlen(val) > sizeof(ibms_init[i].param) - 1)
1033410316
return -ENOSPC;
1033510317
strcpy(ibms_init[i].param, val);
10336-
strcat(ibms_init[i].param, ",");
1033710318
return 0;
1033810319
}
1033910320
}

0 commit comments

Comments
 (0)