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 <thorsten.blum@linux.dev>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20260602071343.962830-2-thorsten.blum@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Thorsten Blum
2026-06-02 09:13:41 +02:00
committed by Jakub Kicinski
parent 0416f7b354
commit 6ce66868d1

View File

@@ -64,44 +64,27 @@ int dns_query(struct net *net,
const char *options, char **_result, time64_t *_expiry,
bool invalidate)
{
struct key *rkey;
struct user_key_payload *upayload;
size_t typelen, desclen;
char *desc, *cp;
struct key *rkey;
int ret, len;
char *desc;
kenter("%s,%*.*s,%zu,%s",
type, (int)namelen, (int)namelen, name, namelen, options);
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);