* [PATCH net-next] net/dns_resolver: use kasprintf + kmemdup_nul to simplify dns_query
@ 2026-05-28 22:20 Thorsten Blum
2026-06-02 2:15 ` Jakub Kicinski
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-05-28 22:20 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Tim Bird, Thorsten Blum, Amir Goldstein,
Christian Brauner
Cc: netdev, linux-kernel
Use kasprintf() for descriptions with a query type and kmemdup_nul()
otherwise to simplify dns_query().
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
net/dns_resolver/dns_query.c | 31 +++++++------------------------
1 file changed, 7 insertions(+), 24 deletions(-)
diff --git a/net/dns_resolver/dns_query.c b/net/dns_resolver/dns_query.c
index c250d82cad96..40c9acdb26cd 100644
--- a/net/dns_resolver/dns_query.c
+++ b/net/dns_resolver/dns_query.c
@@ -66,8 +66,7 @@ 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",
@@ -75,33 +74,17 @@ int dns_query(struct net *net,
if (!name || namelen < 3 || namelen > 255)
return -EINVAL;
+ if (type && *type == '\0')
+ return -EINVAL;
/* construct the query key description as "[<type>:]<name>" */
- typelen = 0;
- desclen = 0;
- if (type) {
- typelen = strlen(type);
- if (typelen < 1)
- return -EINVAL;
- desclen += typelen + 1;
- }
-
- desclen += namelen + 1;
-
- desc = kmalloc(desclen, GFP_KERNEL);
+ if (type)
+ desc = kasprintf(GFP_KERNEL, "%s:%.*s", type, (int)namelen, name);
+ else
+ desc = kmemdup_nul(name, namelen, GFP_KERNEL);
if (!desc)
return -ENOMEM;
- cp = desc;
- if (type) {
- memcpy(cp, type, typelen);
- cp += typelen;
- *cp++ = ':';
- }
- memcpy(cp, name, namelen);
- cp += namelen;
- *cp = '\0';
-
if (!options)
options = "";
kdebug("call request_key(,%s,%s)", desc, options);
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net-next] net/dns_resolver: use kasprintf + kmemdup_nul to simplify dns_query
2026-05-28 22:20 [PATCH net-next] net/dns_resolver: use kasprintf + kmemdup_nul to simplify dns_query Thorsten Blum
@ 2026-06-02 2:15 ` Jakub Kicinski
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2026-06-02 2:15 UTC (permalink / raw)
To: Thorsten Blum
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Tim Bird, Amir Goldstein, Christian Brauner, netdev, linux-kernel
On Fri, 29 May 2026 00:20:29 +0200 Thorsten Blum wrote:
> struct key *rkey;
> struct user_key_payload *upayload;
> - size_t typelen, desclen;
> - char *desc, *cp;
> + char *desc;
> int ret, len;
Let's try to follow the ideal coding style for networking (longest to
shortest sort of variable decl lines) if we have to be touching this
code.
--
pw-bot: cr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-02 2:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-28 22:20 [PATCH net-next] net/dns_resolver: use kasprintf + kmemdup_nul to simplify dns_query Thorsten Blum
2026-06-02 2:15 ` Jakub Kicinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox