* [PATCH net-next] net/dns_resolver: clean up and simplify dns_query()
@ 2026-03-16 21:38 Thorsten Blum
2026-03-18 2:19 ` Jakub Kicinski
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-03-16 21:38 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Amir Goldstein, Christian Brauner, Tim Bird
Cc: Thorsten Blum, netdev, linux-kernel
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 = "";
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] net/dns_resolver: clean up and simplify dns_query()
2026-03-16 21:38 [PATCH net-next] net/dns_resolver: clean up and simplify dns_query() Thorsten Blum
@ 2026-03-18 2:19 ` Jakub Kicinski
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2026-03-18 2:19 UTC (permalink / raw)
To: Thorsten Blum
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Amir Goldstein, Christian Brauner, Tim Bird, netdev, linux-kernel
On Mon, 16 Mar 2026 22:38:45 +0100 Thorsten Blum wrote:
> Fold the name length checks into a single early check, and use
> kmemdup_nul() for name-only descriptions and snprintf() for
would be easier to review it if it was two changes but..
> "<type>:<name>" descriptions to simplify dns_query().
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> Compile-tested only.
.. we have a policy against encouraging trivial cleanups.
If you can't even test this let's not bother.
--
pw-bot: cr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-18 2:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-16 21:38 [PATCH net-next] net/dns_resolver: clean up and simplify dns_query() Thorsten Blum
2026-03-18 2:19 ` Jakub Kicinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox