@@ -134,8 +134,8 @@ dns_resolver_preparse(struct key_preparsed_payload *prep)
/* deal with any options embedded in the data */
end = data + datalen;
- opt = memchr(data, '#', datalen);
- if (!opt) {
+ opt = memscan(data, '#', datalen);
+ if (opt == end) {
/* no options: the entire data is the result */
kdebug("no options");
result_len = datalen;
@@ -150,7 +150,7 @@ dns_resolver_preparse(struct key_preparsed_payload *prep)
const char *eq;
char optval[128];
- next_opt = memchr(opt, '#', end - opt) ?: end;
+ next_opt = memscan(opt, '#', end - opt);
opt_len = next_opt - opt;
if (opt_len <= 0 || opt_len > sizeof(optval)) {
pr_warn_ratelimited("Invalid option length (%d) for dns_resolver key\n",
@@ -158,16 +158,10 @@ dns_resolver_preparse(struct key_preparsed_payload *prep)
return -EINVAL;
}
- eq = memchr(opt, '=', opt_len);
- if (eq) {
- opt_nlen = eq - opt;
- eq++;
- memcpy(optval, eq, next_opt - eq);
- optval[next_opt - eq] = '\0';
- } else {
- opt_nlen = opt_len;
- optval[0] = '\0';
- }
+ eq = memscan(opt, '=', opt_len);
+ opt_nlen = eq - opt;
+ memcpy(optval, eq, next_opt - eq);
+ optval[next_opt - eq] = '\0';
kdebug("option '%*.*s' val '%s'",
opt_nlen, opt_nlen, opt, optval);
memscan() is a standard API to provide an equivalent to memchr(foo, $CHAR, end - foo) ?: end so use it. Memory footprint (x86_64): Function old new delta dns_resolver_preparse 1429 1393 -36 Total: Before=3229, After=3193, chg -1.11% Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> --- net/dns_resolver/dns_key.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)