From: David Laight <david.laight.linux@gmail.com>
To: Thorsten Blum <thorsten.blum@linux.dev>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Christian Brauner <brauner@kernel.org>,
Tim Bird <tim.bird@sony.com>, Amir Goldstein <amir73il@gmail.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v2] net/dns_resolver: use kasprintf + kmemdup_nul to simplify dns_query
Date: Thu, 4 Jun 2026 15:19:25 +0100 [thread overview]
Message-ID: <20260604151925.081e9f47@pumpkin> (raw)
In-Reply-To: <20260602071343.962830-2-thorsten.blum@linux.dev>
On Tue, 2 Jun 2026 09:13:41 +0200
Thorsten Blum <thorsten.blum@linux.dev> wrote:
> Use kasprintf() for descriptions with a query type and kmemdup_nul()
> otherwise to simplify dns_query().
It'll be a lot slower - if that matters.
-- David
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> Changes in v2:
> - Reverse xmas tree (Jakub)
> - v1: https://lore.kernel.org/lkml/20260528222030.1655010-2-thorsten.blum@linux.dev/
> ---
> net/dns_resolver/dns_query.c | 33 ++++++++-------------------------
> 1 file changed, 8 insertions(+), 25 deletions(-)
>
> diff --git a/net/dns_resolver/dns_query.c b/net/dns_resolver/dns_query.c
> index c250d82cad96..14bee83cbe22 100644
> --- a/net/dns_resolver/dns_query.c
> +++ b/net/dns_resolver/dns_query.c
> @@ -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);
>
prev parent reply other threads:[~2026-06-04 14:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-02 7:13 [PATCH net-next v2] net/dns_resolver: use kasprintf + kmemdup_nul to simplify dns_query Thorsten Blum
2026-06-04 12:41 ` Simon Horman
2026-06-04 14:19 ` David Laight [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260604151925.081e9f47@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=thorsten.blum@linux.dev \
--cc=tim.bird@sony.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox