net/dns_resolver: use kasprintf + kmemdup_nul to simplify dns_query
Subsystems (2)
PATCH 1/1 net/dns_resolver: use kasprintf + kmemdup_nul to simplify dns_query
Use kasprintf() for descriptions with a query type and kmemdup_nul() otherwise to simplify dns_query().
Signed-off-by Thorsten Blum <[email protected]>
--- net/dns_resolver/dns_query.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-)
net/dns_resolver/dns_query.c +7 -24
@@ -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);
Jakub Kicinski
maintainernet/dns_resolver/dns_query.c int dns_query(struct net *net, · line 70
Quoted 6 lines · On Fri, 29 May 2026 00:20:29 +0200 Thorsten Blum wrote:
net/dns_resolver/dns_query.c +1
-2struct 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.
Signature · 1 line
pw-bot: cr