[PATCH net-next] net/dns_resolver: consolidate namelen checks in dns_query

From: Thorsten Blum

Date: Mon May 25 2026 - 06:00:02 EST


Consolidate the namelen checks and return -EINVAL early if needed. Drop
the namelen == 0 check since it is covered by namelen < 3.

Signed-off-by: Thorsten Blum <thorsten.blum@xxxxxxxxx>
---
net/dns_resolver/dns_query.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/net/dns_resolver/dns_query.c b/net/dns_resolver/dns_query.c
index e1c09d7b8200..c250d82cad96 100644
--- a/net/dns_resolver/dns_query.c
+++ b/net/dns_resolver/dns_query.c
@@ -73,7 +73,7 @@ int dns_query(struct net *net,
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>" */
@@ -86,8 +86,6 @@ int dns_query(struct net *net,
desclen += typelen + 1;
}

- if (namelen < 3 || namelen > 255)
- return -EINVAL;
desclen += namelen + 1;

desc = kmalloc(desclen, GFP_KERNEL);