qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] util/cacheinfo: fix crash when compiling with uClibc


From: Carlos Santos
Subject: Re: [PATCH] util/cacheinfo: fix crash when compiling with uClibc
Date: Mon, 16 Dec 2019 08:18:42 -0300

On Thu, Oct 17, 2019 at 8:06 PM Carlos Santos <address@hidden> wrote:
>
> On Thu, Oct 17, 2019 at 9:47 AM Peter Maydell <address@hidden> wrote:
> >
> > On Thu, 17 Oct 2019 at 13:39, <address@hidden> wrote:
> > >
> > > From: Carlos Santos <address@hidden>
> > >
> > > 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 <address@hidden>
> > > ---
> > >  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 ?
>
> It's there to remind the reader that a type coercion may occur, since
> sysconf() returns a long and isize is an int.
>
> > > +    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
>
> --
> Carlos Santos
> Senior Software Maintenance Engineer
> Red Hat
> address@hidden    T: +55-11-3534-6186

Hi,

Any chance to have this merged for Christmas? :-)

-- 
Carlos Santos
Senior Software Maintenance Engineer
Red Hat
address@hidden    T: +55-11-3534-6186




reply via email to

[Prev in Thread] Current Thread [Next in Thread]