Skip to content

Commit cfa75cc

Browse files
nitinexclusivelyjwrdegoede
authored andcommitted
platform/x86: thinkpad_acpi: fixed warning and incorporated review comments
The previous commit adding new sysfs for keyboard language has warning and few code correction has to be done as per new review comments. Below changes has been addressed in this version: - corrected warning. Many thanks to kernel test robot <lkp@intel.com> for reporting and determining this warning. - used sysfs_emit_at() API instead of strcat. - sorted keyboard language array. - removed unwanted space and corrected sentences. Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Nitin Joshi <njoshi1@lenovo.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Link: https://lore.kernel.org/r/20210202003210.91773-1-njoshi1@lenovo.com Signed-off-by: Hans de Goede <hdegoede@redhat.com>
1 parent a78b96f commit cfa75cc

File tree

2 files changed

+19
-29
lines changed

2 files changed

+19
-29
lines changed

Documentation/admin-guide/laptops/thinkpad-acpi.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,18 +1476,19 @@ sysfs: keyboard_lang
14761476
This feature is used to set keyboard language to ECFW using ASL interface.
14771477
Fewer thinkpads models like T580 , T590 , T15 Gen 1 etc.. has "=", "(',
14781478
")" numeric keys, which are not displaying correctly, when keyboard language
1479-
is other than "english". This is because of default keyboard language in ECFW
1480-
is set as "english". Hence using this sysfs, user can set correct keyboard
1481-
language to ECFW and then these key's will work correctly .
1479+
is other than "english". This is because the default keyboard language in ECFW
1480+
is set as "english". Hence using this sysfs, user can set the correct keyboard
1481+
language to ECFW and then these key's will work correctly.
14821482

14831483
Example of command to set keyboard language is mentioned below::
14841484

14851485
echo jp > /sys/devices/platform/thinkpad_acpi/keyboard_lang
14861486

1487-
Text corresponding to keyboard layout to be set in sysfs are : jp (Japan), be(Belgian),
1488-
cz(Czech), en(English), da(Danish), de(German), es(Spain) , et(Estonian),
1489-
fr(French) , fr-ch (French(Switzerland)), pl(Polish), sl(Slovenian), hu
1490-
(Hungarian), nl(Dutch), tr(Turkey), it(Italy), sv(Sweden), pt(portugese)
1487+
Text corresponding to keyboard layout to be set in sysfs are: be(Belgian),
1488+
cz(Czech), da(Danish), de(German), en(English), es(Spain), et(Estonian),
1489+
fr(French), fr-ch(French(Switzerland)), hu(Hungarian), it(Italy), jp (Japan),
1490+
nl(Dutch), nn(Norway), pl(Polish), pt(portugese), sl(Slovenian), sv(Sweden),
1491+
tr(Turkey)
14911492

14921493

14931494
Adaptive keyboard

drivers/platform/x86/thinkpad_acpi.c

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9992,16 +9992,12 @@ struct keyboard_lang_data {
99929992
int lang_code;
99939993
};
99949994

9995-
/*
9996-
* When adding new entries to keyboard_lang_data, please check that
9997-
* the select_lang[] buffer in keyboard_lang_show() is still large enough.
9998-
*/
9999-
struct keyboard_lang_data keyboard_lang_data[] = {
10000-
{"en", 0},
9995+
static const struct keyboard_lang_data keyboard_lang_data[] = {
100019996
{"be", 0x080c},
100029997
{"cz", 0x0405},
100039998
{"da", 0x0406},
100049999
{"de", 0x0c07},
10000+
{"en", 0x0000},
1000510001
{"es", 0x2c0a},
1000610002
{"et", 0x0425},
1000710003
{"fr", 0x040c},
@@ -10064,29 +10060,25 @@ static ssize_t keyboard_lang_show(struct device *dev,
1006410060
struct device_attribute *attr,
1006510061
char *buf)
1006610062
{
10067-
int output, err, i;
10068-
char select_lang[80] = "";
10069-
char lang[8] = "";
10063+
int output, err, i, len = 0;
1007010064

1007110065
err = get_keyboard_lang(&output);
1007210066
if (err)
1007310067
return err;
1007410068

1007510069
for (i = 0; i < ARRAY_SIZE(keyboard_lang_data); i++) {
1007610070
if (i)
10077-
strcat(select_lang, " ");
10071+
len += sysfs_emit_at(buf, len, "%s", " ");
1007810072

1007910073
if (output == keyboard_lang_data[i].lang_code) {
10080-
strcat(lang, "[");
10081-
strcat(lang, keyboard_lang_data[i].lang_str);
10082-
strcat(lang, "]");
10083-
strcat(select_lang, lang);
10074+
len += sysfs_emit_at(buf, len, "[%s]", keyboard_lang_data[i].lang_str);
1008410075
} else {
10085-
strcat(select_lang, keyboard_lang_data[i].lang_str);
10076+
len += sysfs_emit_at(buf, len, "%s", keyboard_lang_data[i].lang_str);
1008610077
}
1008710078
}
10079+
len += sysfs_emit_at(buf, len, "\n");
1008810080

10089-
return sysfs_emit(buf, "%s\n", select_lang);
10081+
return len;
1009010082
}
1009110083

1009210084
static ssize_t keyboard_lang_store(struct device *dev,
@@ -10113,7 +10105,7 @@ static ssize_t keyboard_lang_store(struct device *dev,
1011310105
if (err)
1011410106
return err;
1011510107
} else {
10116-
pr_err("Unknown Keyboard language. Ignoring\n");
10108+
dev_err(&tpacpi_pdev->dev, "Unknown Keyboard language. Ignoring\n");
1011710109
return -EINVAL;
1011810110
}
1011910111

@@ -10124,7 +10116,6 @@ static ssize_t keyboard_lang_store(struct device *dev,
1012410116

1012510117
return count;
1012610118
}
10127-
1012810119
static DEVICE_ATTR_RW(keyboard_lang);
1012910120

1013010121
static struct attribute *kbdlang_attributes[] = {
@@ -10143,7 +10134,7 @@ static int tpacpi_kbdlang_init(struct ibm_init_struct *iibm)
1014310134
err = get_keyboard_lang(&output);
1014410135
/*
1014510136
* If support isn't available (ENODEV) then don't return an error
10146-
* just don't create the sysfs group
10137+
* just don't create the sysfs group.
1014710138
*/
1014810139
if (err == -ENODEV)
1014910140
return 0;
@@ -10152,9 +10143,7 @@ static int tpacpi_kbdlang_init(struct ibm_init_struct *iibm)
1015210143
return err;
1015310144

1015410145
/* Platform supports this feature - create the sysfs file */
10155-
err = sysfs_create_group(&tpacpi_pdev->dev.kobj, &kbdlang_attr_group);
10156-
10157-
return err;
10146+
return sysfs_create_group(&tpacpi_pdev->dev.kobj, &kbdlang_attr_group);
1015810147
}
1015910148

1016010149
static void kbdlang_exit(void)

0 commit comments

Comments
 (0)