2017-04-11 19:17:36

by Matthias Kaehlcke

[permalink] [raw]
Subject: [PATCH] clocksource: Use GENMASK_ULL in definition of CLOCKSOURCE_MASK

Besides reusing existing code this removes the special case handling
for 64-bit masks, which causes clang to raise a shift count overflow
warning due to https://bugs.llvm.org//show_bug.cgi?id=10030.

Suggested-by: Dmitry Torokhov <[email protected]>
Signed-off-by: Matthias Kaehlcke <[email protected]>
---
include/linux/clocksource.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index cfc75848a35d..06e604b9e9dc 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -120,7 +120,7 @@ struct clocksource {
#define CLOCK_SOURCE_RESELECT 0x100

/* simplify initialization of mask field */
-#define CLOCKSOURCE_MASK(bits) (u64)((bits) < 64 ? ((1ULL<<(bits))-1) : -1)
+#define CLOCKSOURCE_MASK(bits) (u64)GENMASK_ULL((bits) - 1, 0)

static inline u32 clocksource_freq2mult(u32 freq, u32 shift_constant, u64 from)
{
--
2.12.2.715.g7642488e1d-goog


2017-04-15 04:02:10

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH] clocksource: Use GENMASK_ULL in definition of CLOCKSOURCE_MASK

Hi Matthias,

On Tue, Apr 11, 2017 at 12:17 PM, Matthias Kaehlcke <[email protected]> wrote:
> Besides reusing existing code this removes the special case handling
> for 64-bit masks, which causes clang to raise a shift count overflow
> warning due to https://bugs.llvm.org//show_bug.cgi?id=10030.
>
> Suggested-by: Dmitry Torokhov <[email protected]>
> Signed-off-by: Matthias Kaehlcke <[email protected]>
> ---
> include/linux/clocksource.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
> index cfc75848a35d..06e604b9e9dc 100644
> --- a/include/linux/clocksource.h
> +++ b/include/linux/clocksource.h
> @@ -120,7 +120,7 @@ struct clocksource {
> #define CLOCK_SOURCE_RESELECT 0x100
>
> /* simplify initialization of mask field */
> -#define CLOCKSOURCE_MASK(bits) (u64)((bits) < 64 ? ((1ULL<<(bits))-1) : -1)
> +#define CLOCKSOURCE_MASK(bits) (u64)GENMASK_ULL((bits) - 1, 0)

I do not think cast to u64 is needed for GENMASK_ULL.

>
> static inline u32 clocksource_freq2mult(u32 freq, u32 shift_constant, u64 from)
> {
> --
> 2.12.2.715.g7642488e1d-goog
>

Thanks,
Dmitry

2017-04-17 16:57:12

by Matthias Kaehlcke

[permalink] [raw]
Subject: Re: [PATCH] clocksource: Use GENMASK_ULL in definition of CLOCKSOURCE_MASK

Hi Dmitry,

El Fri, Apr 14, 2017 at 09:02:03PM -0700 Dmitry Torokhov ha dit:

> On Tue, Apr 11, 2017 at 12:17 PM, Matthias Kaehlcke <[email protected]> wrote:
> > Besides reusing existing code this removes the special case handling
> > for 64-bit masks, which causes clang to raise a shift count overflow
> > warning due to https://bugs.llvm.org//show_bug.cgi?id=10030.
> >
> > Suggested-by: Dmitry Torokhov <[email protected]>
> > Signed-off-by: Matthias Kaehlcke <[email protected]>
> > ---
> > include/linux/clocksource.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
> > index cfc75848a35d..06e604b9e9dc 100644
> > --- a/include/linux/clocksource.h
> > +++ b/include/linux/clocksource.h
> > @@ -120,7 +120,7 @@ struct clocksource {
> > #define CLOCK_SOURCE_RESELECT 0x100
> >
> > /* simplify initialization of mask field */
> > -#define CLOCKSOURCE_MASK(bits) (u64)((bits) < 64 ? ((1ULL<<(bits))-1) : -1)
> > +#define CLOCKSOURCE_MASK(bits) (u64)GENMASK_ULL((bits) - 1, 0)
>
> I do not think cast to u64 is needed for GENMASK_ULL.

Indeed, it is not needed, I will update the patch

Thanks!

Matthias