Skip to content

Commit 6cb9c86

Browse files
andy-shevjwrdegoede
authored andcommitted
platform/x86: think-lmi: Use strreplace() to replace a character by nul
We can replace p = strchrnul(str, '$OLD'); *p = '\0'; with strreplace(str, '$OLD', '\0'); that does the compatible modification without a need of the temporary variable. Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Hans de Goede <[email protected]>
1 parent e621198 commit 6cb9c86

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

drivers/platform/x86/think-lmi.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,6 @@ static struct think_lmi tlmi_priv;
198198
static struct class *fw_attr_class;
199199
static DEFINE_MUTEX(tlmi_mutex);
200200

201-
/* ------ Utility functions ------------*/
202-
/* Strip out CR if one is present */
203-
static void strip_cr(char *str)
204-
{
205-
char *p = strchrnul(str, '\n');
206-
*p = '\0';
207-
}
208-
209201
/* Convert BIOS WMI error string to suitable error code */
210202
static int tlmi_errstr_to_err(const char *errstr)
211203
{
@@ -411,7 +403,7 @@ static ssize_t current_password_store(struct kobject *kobj,
411403

412404
strscpy(setting->password, buf, setting->maxlen);
413405
/* Strip out CR if one is present, setting password won't work if it is present */
414-
strip_cr(setting->password);
406+
strreplace(setting->password, '\n', '\0');
415407
return count;
416408
}
417409

@@ -921,7 +913,7 @@ static ssize_t display_name_show(struct kobject *kobj, struct kobj_attribute *at
921913
static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
922914
{
923915
struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
924-
char *item, *value, *p;
916+
char *item, *value;
925917
int ret;
926918

927919
ret = tlmi_setting(setting->index, &item, LENOVO_BIOS_SETTING_GUID);
@@ -934,8 +926,7 @@ static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *a
934926
ret = -EINVAL;
935927
else {
936928
/* On Workstations remove the Options part after the value */
937-
p = strchrnul(value, ';');
938-
*p = '\0';
929+
strreplace(value, ';', '\0');
939930
ret = sysfs_emit(buf, "%s\n", value + 1);
940931
}
941932
kfree(item);
@@ -1540,7 +1531,6 @@ static int tlmi_analyze(void)
15401531
for (i = 0; i < TLMI_SETTINGS_COUNT; ++i) {
15411532
struct tlmi_attr_setting *setting;
15421533
char *item = NULL;
1543-
char *p;
15441534

15451535
tlmi_priv.setting[i] = NULL;
15461536
ret = tlmi_setting(i, &item, LENOVO_BIOS_SETTING_GUID);
@@ -1557,8 +1547,7 @@ static int tlmi_analyze(void)
15571547
strreplace(item, '/', '\\');
15581548

15591549
/* Remove the value part */
1560-
p = strchrnul(item, ',');
1561-
*p = '\0';
1550+
strreplace(item, ',', '\0');
15621551

15631552
/* Create a setting entry */
15641553
setting = kzalloc(sizeof(*setting), GFP_KERNEL);

0 commit comments

Comments
 (0)