Re: [PATCH v2 2/6] platform/x86: dell-smo8800: Move instantiation of lis3lv02d i2c_client from i2c-i801 to dell-smo8800

Steven Rostedt
2024-01-07T16:08:07Z

On Sat, 6 Jan 2024 18:24:34 +0200
Andy Shevchenko <andy@kernel.org> wrote:

> > + if (!strstarts(adap->name, "SMBus I801 adapter"))
> > + return 0;
>
> Bah, we have str_has_prefix() and this, much older one...
> Steven? Others? I mean we can do something about this duplication, right?

They are not really duplicate functions.

Note that strstarts() is just a boolean (does this start with something)
where as str_has_prefix() returns the length of the prefix.

Yes, strstarts() can be swapped to str_has_prefix() but it can't go the
other way around. One use case of the str_has_prefix() feature is in the
histogram parsing:

for (i = 0; i < hist_data->attrs->n_actions; i++) {
str = hist_data->attrs->action_str[i];

if ((len = str_has_prefix(str, "onmatch("))) {
char *action_str = str + len;

data = onmatch_parse(tr, action_str);
if (IS_ERR(data)) {
ret = PTR_ERR(data);
break;
}
} else if ((len = str_has_prefix(str, "onmax("))) {
char *action_str = str + len;

data = track_data_parse(hist_data, action_str,
HANDLER_ONMAX);
if (IS_ERR(data)) {
ret = PTR_ERR(data);
break;
}
} else if ((len = str_has_prefix(str, "onchange("))) {
char *action_str = str + len;

data = track_data_parse(hist_data, action_str,
HANDLER_ONCHANGE);
if (IS_ERR(data)) {
ret = PTR_ERR(data);
break;
}

Where we get the length of the prefix if there's a match, and use that to
skip over the prefix.

If you just need to know if something starts with a string, then
"strstarts()" is perfectly fine to use.

-- Steve