[PATCH i-g-t] lib/igt_core: Use suffix for casting to long to avoid overflow
Zbigniew Kempczyński
zbigniew.kempczynski at intel.com
Wed Dec 18 05:45:22 UTC 2024
On Tue, Dec 17, 2024 at 09:15:06AM -0600, Lucas De Marchi wrote:
> On Tue, Dec 17, 2024 at 11:58:07AM +0100, Zbigniew Kempczyński wrote:
> > Multiplication without using casting to long (long) for at least
> > one argument in expression may cause overflow especially when we're
> > using this for calculating timeouts in nanoseconds precision.
> >
> > Ensure we're picking valid ul/ull suffix for base definitions for
> > all dependents.
> >
> > Reported-by: Ilia Levi <ilia.levi at intel.com>
> > Closes: https://gitlab.freedesktop.org/drm/igt-gpu-tools/-/issues/163
> >
>
> drop this newline so the lines above are also part of the git trailer.
Ok.
>
> > Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
> > Cc: Lucas De Marchi <lucas.demarchi at intel.com>
> > Cc: Ilia Levi <ilia.levi at intel.com>
> > ---
> > lib/igt_core.h | 10 ++++++++--
> > 1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/lib/igt_core.h b/lib/igt_core.h
> > index 90f57402f0..1b6e70182b 100644
> > --- a/lib/igt_core.h
> > +++ b/lib/igt_core.h
> > @@ -1517,11 +1517,17 @@ void igt_kmsg(const char *format, ...);
> > #define le32_to_cpu(x) (x)
> > #endif
> >
> > -#define MSEC_PER_SEC (1000u)
> > +#if __WORDSIZE == 64
>
> we could just use ull regardless of wordsize
No, we can't. There will be a lot of warnings where PRIx64 is used.
__WORDSIZE is defined in bits/wordsize.h and included in stdint.h
what is included in igt.h.
I'll dare to get your r-b, but I'll adopt commit message as Kamil
suggests.
--
Zbigniew
>
> but overall lgtm. With those changes: Reviewed-by: Lucas De Marchi <lucas.demarchi at intel.com>
>
>
> Lucas De Marchi
>
> > +#define MSEC_PER_SEC (1000ul)
> > +#define USEC_PER_MSEC (1000ul)
> > +#else
> > +#define MSEC_PER_SEC (1000ull)
> > +#define USEC_PER_MSEC (1000ull)
> > +#endif
> > +
> > #define USEC_PER_SEC (1000u * MSEC_PER_SEC)
> > #define USEC_PER_DECISEC (100u * MSEC_PER_SEC)
> > #define NSEC_PER_SEC (1000u * USEC_PER_SEC)
> > -#define USEC_PER_MSEC (1000u)
> > #define NSEC_PER_MSEC (1000u * USEC_PER_MSEC)
> >
> > #define for_if(expr__) if (!(expr__)) {} else
> > --
> > 2.34.1
> >
More information about the igt-dev
mailing list