lkml.org 
[lkml]   [2023]   [Sep]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v1 2/2] platform/x86: think-lmi: Use strreplace() to replace a character by nul
From
On 13/09/2023 11.27, Andy Shevchenko wrote:

> @@ -921,7 +913,7 @@ static ssize_t display_name_show(struct kobject *kobj, struct kobj_attribute *at
> static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
> {
> struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
> - char *item, *value, *p;
> + char *item, *value;
> int ret;
>
> 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
> ret = -EINVAL;
> else {
> /* On Workstations remove the Options part after the value */
> - p = strchrnul(value, ';');
> - *p = '\0';
> + strreplace(value, ';', '\0');

So how do you know that the string contains at most one ';'? Same for
all the other replacements. If that's not guaranteed, this is not at all
equivalent.

Or maybe the result is just used a normal string afterwards, and it
doesn't matter at all how the content after the first ';' has been mangled?

It's certainly not obvious to me that this is correct, but of course I
know nothing about this code.

Rasmus

\
 
 \ /
  Last update: 2023-09-18 17:23    [W:0.063 / U:0.280 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site