qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: casantos@redhat.com
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [PATCH] util/cacheinfo: fix crash when compiling with uClibc
Date: Thu, 17 Oct 2019 13:47:18 +0100	[thread overview]
Message-ID: <CAFEAcA9dMRBtDs6QSXGVv_bNhtu5wnGKLvMxr2YuoWM=yomGDg@mail.gmail.com> (raw)
In-Reply-To: <20191017123713.30192-1-casantos@redhat.com>

On Thu, 17 Oct 2019 at 13:39, <casantos@redhat.com> wrote:
>
> From: Carlos Santos <casantos@redhat.com>
>
> uClibc defines _SC_LEVEL1_ICACHE_LINESIZE and _SC_LEVEL1_DCACHE_LINESIZE
> but the corresponding sysconf calls returns -1, which is a valid result,
> meaning that the limit is indeterminate.
>
> Handle this situation using the fallback values instead of crashing due
> to an assertion failure.
>
> Signed-off-by: Carlos Santos <casantos@redhat.com>
> ---
>  util/cacheinfo.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/util/cacheinfo.c b/util/cacheinfo.c
> index ea6f3e99bf..d94dc6adc8 100644
> --- a/util/cacheinfo.c
> +++ b/util/cacheinfo.c
> @@ -93,10 +93,16 @@ static void sys_cache_info(int *isize, int *dsize)
>  static void sys_cache_info(int *isize, int *dsize)
>  {
>  # ifdef _SC_LEVEL1_ICACHE_LINESIZE
> -    *isize = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
> +    int tmp_isize = (int) sysconf(_SC_LEVEL1_ICACHE_LINESIZE);

Do we need the cast here ?

> +    if (tmp_isize > 0) {
> +        *isize = tmp_isize;
> +    }
>  # endif
>  # ifdef _SC_LEVEL1_DCACHE_LINESIZE
> -    *dsize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
> +    int tmp_dsize = (int) sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
> +    if (tmp_dsize > 0) {
> +        *dsize = tmp_dsize;
> +    }
>  # endif
>  }
>  #endif /* sys_cache_info */
> --

thanks
-- PMM


  reply	other threads:[~2019-10-17 12:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-17 12:37 [PATCH] util/cacheinfo: fix crash when compiling with uClibc casantos
2019-10-17 12:47 ` Peter Maydell [this message]
2019-10-17 23:06   ` Carlos Santos
2019-12-16 11:18     ` Carlos Santos
2020-01-17  0:04       ` Richard Henderson
2020-01-20 18:26         ` Carlos Santos

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='CAFEAcA9dMRBtDs6QSXGVv_bNhtu5wnGKLvMxr2YuoWM=yomGDg@mail.gmail.com' \
    --to=peter.maydell@linaro.org \
    --cc=casantos@redhat.com \
    --cc=qemu-devel@nongnu.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).