From: "Morten Brørup" <mb@smartsharesystems.com>
To: "Stephen Hemminger" <stephen@networkplumber.org>
Cc: <dev@dpdk.org>
Subject: RE: [RFC PATCH] mempool: Fix some Coverity defects
Date: Mon, 9 Jun 2025 17:44:06 +0200 [thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35E9FCD7@smartserver.smartshare.dk> (raw)
In-Reply-To: <20250609082545.4c932967@hermes.local>
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Monday, 9 June 2025 17.26
>
> On Mon, 9 Jun 2025 14:42:26 +0000
> Morten Brørup <mb@smartsharesystems.com> wrote:
>
> > @@ -141,8 +141,13 @@ rte_mem_page_size(void)
> > {
> > static size_t page_size;
> >
> > - if (!page_size)
> > + if (page_size == 0) {
> > + errno = 0; /* man sysconf(3) */
> > page_size = sysconf(_SC_PAGESIZE);
> > + if ((ssize_t)page_size < 0)
> > + rte_panic("sysconf(_SC_PAGESIZE) failed: %s",
> > + errno == 0 ? "Indeterminate" :
> strerror(errno));
> > + }
>
> Why not make page_size a ssize_t or long?
> The return value of sysconf is long.
I guess it's a matter of preference...
This function returns size_t, i.e. an unsigned type. So I kept page_size (the cached return value) the same type, and put the type cast in the unlikely code path.
The alternative, changing page_size to a signed type (ssize_t or long), would require casting to an unsigned type in the return statement.
> Not sure if setting errno to zero is required, sysconf only touchs it if
> return value is negative.
The Linux man sysconf(3) page recommends setting errno to zero before calling sysconf(), so errno can be used to discriminate between actual errors and an indeterminate value when sysconf() returns -1.
Hence the "man sysconf(3)" comment.
BSD sysconf(3) behaves the same way, but the BSD man page is less explicit about setting errno to zero.
prev parent reply other threads:[~2025-06-09 15:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-09 14:42 Morten Brørup
2025-06-09 15:25 ` Stephen Hemminger
2025-06-09 15:44 ` Morten Brørup [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=98CBD80474FA8B44BF855DF32C47DC35E9FCD7@smartserver.smartshare.dk \
--to=mb@smartsharesystems.com \
--cc=dev@dpdk.org \
--cc=stephen@networkplumber.org \
/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).