netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Kees Cook <keescook@chromium.org>,
	linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
	sparclinux@vger.kernel.org, netdev@vger.kernel.org
Cc: Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	"David S. Miller" <davem@davemloft.net>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Andy Shevchenko <andy@kernel.org>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Subject: [PATCH net-next v1 2/2] dns: use memscan() instead of open coded variant
Date: Thu, 16 Feb 2023 13:42:34 +0200	[thread overview]
Message-ID: <20230216114234.36343-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20230216114234.36343-1-andriy.shevchenko@linux.intel.com>

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(-)

diff --git a/net/dns_resolver/dns_key.c b/net/dns_resolver/dns_key.c
index 01e54b46ae0b..835be6e2dd83 100644
--- a/net/dns_resolver/dns_key.c
+++ b/net/dns_resolver/dns_key.c
@@ -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);
-- 
2.39.1


  reply	other threads:[~2023-02-16 11:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-16 11:42 [PATCH net-next v1 1/2] string: Make memscan() to take const Andy Shevchenko
2023-02-16 11:42 ` Andy Shevchenko [this message]
2023-02-21  0:26 ` Jakub Kicinski
2023-02-21  9:37   ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230216114234.36343-2-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=agordeev@linux.ibm.com \
    --cc=andy@kernel.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=hpa@zytor.com \
    --cc=keescook@chromium.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sparclinux@vger.kernel.org \
    --cc=svens@linux.ibm.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).