From: Ferruh Yigit <ferruh.yigit@amd.com>
To: David Marchand <david.marchand@redhat.com>, dev@dpdk.org
Cc: Thomas Monjalon <thomas@monjalon.net>,
Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Subject: Re: [PATCH] ethdev: prefer offload names in logs
Date: Wed, 17 May 2023 15:52:58 +0100 [thread overview]
Message-ID: <201bce73-59a6-cca8-5f48-556599baf73d@amd.com> (raw)
In-Reply-To: <20230309081633.780438-1-david.marchand@redhat.com>
On 3/9/2023 8:16 AM, David Marchand wrote:
> +static char *
> +eth_dev_offload_names(uint64_t bitmask, const char *(*offload_name)(uint64_t))
> +{
> + uint64_t offload;
> + char *names;
> +
> + if (bitmask == 0) {
> + names = strdup("");
> + goto out;
> + }
> +
> + offload = RTE_BIT64(__builtin_ctzll(bitmask));
> + names = strdup(offload_name(offload));
> + if (names == NULL)
> + goto out;
> +
> + bitmask &= ~offload;
> + while (bitmask != 0) {
> + char *old = names;
> + int ret;
> +
> + offload = RTE_BIT64(__builtin_ctzll(bitmask));
> + ret = asprintf(&names, "%s,%s", old, offload_name(offload));
> + free(old);
> + if (ret == -1) {
> + names = NULL;
> + goto out;
> + }
> +
> + bitmask &= ~offload;
> + }
> +
> +out:
> + return names;
> +}
> +
Above works fine, not a strong opinion but just a comment,
this function is just for logging and output string will be short lived,
but it does lots of memory alloc and free, and expose lot of failure points.
To simplify, why not just alloc a big enough buffer, fill it in a loop
and never return NULL?
(Can always append "%s," and drop final ',' at the end.)
next prev parent reply other threads:[~2023-05-17 14:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-09 8:16 David Marchand
2023-03-09 16:21 ` Stephen Hemminger
2023-05-17 14:52 ` Ferruh Yigit
2023-06-13 13:07 ` David Marchand
2023-05-17 14:52 ` Ferruh Yigit [this message]
2023-06-13 13:24 ` [PATCH v2] " David Marchand
2023-06-13 16:37 ` Ferruh Yigit
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=201bce73-59a6-cca8-5f48-556599baf73d@amd.com \
--to=ferruh.yigit@amd.com \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=thomas@monjalon.net \
/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;
as well as URLs for NNTP newsgroup(s).