From: Thorsten Blum <thorsten.blum@linux.dev>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Amir Goldstein <amir73il@gmail.com>,
Christian Brauner <brauner@kernel.org>,
Tim Bird <tim.bird@sony.com>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next] net/dns_resolver: clean up and simplify dns_query()
Date: Mon, 16 Mar 2026 22:38:45 +0100 [thread overview]
Message-ID: <20260316213846.1049655-3-thorsten.blum@linux.dev> (raw)
Fold the name length checks into a single early check, and use
kmemdup_nul() for name-only descriptions and snprintf() for
"<type>:<name>" descriptions to simplify dns_query().
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Compile-tested only.
---
net/dns_resolver/dns_query.c | 40 ++++++++++++++----------------------
1 file changed, 15 insertions(+), 25 deletions(-)
diff --git a/net/dns_resolver/dns_query.c b/net/dns_resolver/dns_query.c
index 53da62984447..3bdea41a2367 100644
--- a/net/dns_resolver/dns_query.c
+++ b/net/dns_resolver/dns_query.c
@@ -78,43 +78,33 @@ int dns_query(struct net *net,
{
struct key *rkey;
struct user_key_payload *upayload;
- size_t typelen, desclen;
- char *desc, *cp;
+ char *desc;
int ret, len;
kenter("%s,%*.*s,%zu,%s",
type, (int)namelen, (int)namelen, name, namelen, options);
- if (!name || namelen == 0)
+ if (!name || namelen < 3 || namelen > 255)
return -EINVAL;
/* construct the query key description as "[<type>:]<name>" */
- typelen = 0;
- desclen = 0;
- if (type) {
- typelen = strlen(type);
- if (typelen < 1)
+ if (!type) {
+ desc = kmemdup_nul(name, namelen, GFP_KERNEL);
+ if (!desc)
+ return -ENOMEM;
+ } else {
+ size_t desclen = strlen(type);
+
+ if (desclen == 0)
return -EINVAL;
- desclen += typelen + 1;
- }
-
- if (namelen < 3 || namelen > 255)
- return -EINVAL;
- desclen += namelen + 1;
- desc = kmalloc(desclen, GFP_KERNEL);
- if (!desc)
- return -ENOMEM;
+ desclen += 1 + namelen + 1;
+ desc = kmalloc(desclen, GFP_KERNEL);
+ if (!desc)
+ return -ENOMEM;
- cp = desc;
- if (type) {
- memcpy(cp, type, typelen);
- cp += typelen;
- *cp++ = ':';
+ snprintf(desc, desclen, "%s:%.*s", type, (int)namelen, name);
}
- memcpy(cp, name, namelen);
- cp += namelen;
- *cp = '\0';
if (!options)
options = "";
next reply other threads:[~2026-03-16 21:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 21:38 Thorsten Blum [this message]
2026-03-18 2:19 ` [PATCH net-next] net/dns_resolver: clean up and simplify dns_query() Jakub Kicinski
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=20260316213846.1049655-3-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tim.bird@sony.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.