Skip to contentSkip to conversation

coresight: do not use the BIT() macro in the UAPI header

PATCH In review Eugene Syromiatnikov 3 participants 7 messages Mar 24, 2020 – Mar 26, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 coresight: do not use the BIT() macro in the UAPI header

The BIT() macro definition is not available for the UAPI headers (moreover, it can be defined differently in the user space); replace its usage with the _BITUL() macro that is defined in <linux/const.h>.

Fixes 237483aa5cf4 ("coresight: stm: adding driver for CoreSight STM component")
---
 include/uapi/linux/coresight-stm.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/uapi/linux/coresight-stm.h +4 -2
index aac550a..8847dbf 100644
@@ -2,8 +2,10 @@
 #ifndef __UAPI_CORESIGHT_STM_H_
 #define __UAPI_CORESIGHT_STM_H_
 
-#define STM_FLAG_TIMESTAMPED   BIT(3)
-#define STM_FLAG_GUARANTEED    BIT(7)
+#include <linux/const.h>
+
+#define STM_FLAG_TIMESTAMPED   _BITUL(3)
+#define STM_FLAG_GUARANTEED    _BITUL(7)
 
 /*
  * The CoreSight STM supports guaranteed and invariant timing
Signature · 1 line
2.1.4
#1 lore raw
Quoted 3 lines · Eugene Syromiatnikov

The BIT() macro definition is not available for the UAPI headers (moreover, it can be defined differently in the user space); replace its usage with the _BITUL() macro that is defined in <linux/const.h>.

Why is somehow _BITUL() ok to use here instead?

Just open-code it, I didn't think we could use any BIT()-like macros in uapi .h files.

thanks,

greg k-h

#2 lore raw
Quoted 6 lines · Greg Kroah-Hartman
Quoted 3 lines · Eugene Syromiatnikov

The BIT() macro definition is not available for the UAPI headers (moreover, it can be defined differently in the user space); replace its usage with the _BITUL() macro that is defined in <linux/const.h>.

Why is somehow _BITUL() ok to use here instead?

It is provided in an UAPI header (include/uapi/linux/const.h) and is appropriately prefixed with an underscore to avoid conflicts.

Quoted 7 lines

Just open-code it, I didn't think we could use any BIT()-like macros in uapi .h files.

thanks,

greg k-h

#3 lore raw
Quoted 10 lines · Eugene Syromiatnikov
Quoted 6 lines · Greg Kroah-Hartman
Quoted 3 lines · Eugene Syromiatnikov

The BIT() macro definition is not available for the UAPI headers (moreover, it can be defined differently in the user space); replace its usage with the _BITUL() macro that is defined in <linux/const.h>.

Why is somehow _BITUL() ok to use here instead?

It is provided in an UAPI header (include/uapi/linux/const.h) and is appropriately prefixed with an underscore to avoid conflicts.

Because no one uses _ in their own macros? :)

Anyway, this is fine, but if it's really the way forward, I think a lot of files will end up being changed...

thanks,

greg k-h

#4 lore raw
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Eugene Syromiatnikov
Quoted 5 lines · Greg Kroah-Hartman
Quoted 3 lines · Eugene Syromiatnikov

The BIT() macro definition is not available for the UAPI headers (moreover, it can be defined differently in the user space); replace its usage with the _BITUL() macro that is defined in <linux/const.h>.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Why is somehow _BITUL() ok to use here instead?

It is provided in an UAPI header (include/uapi/linux/const.h) and is appropriately prefixed with an underscore to avoid conflicts.

Because no one uses _ in their own macros? :)

Well, it is a reserved prefix (ANSI C99, 4.1.2 "Standard headers": "All other identifiers that begin with an underscore and either an upper-case letter or another underscore are reserved"), so valid C files shouldn't use them.

Quoted 2 lines

Anyway, this is fine, but if it's really the way forward, I think a lot of files will end up being changed...

There are 5 cases for using BIT() in UAPI headers so far (rtc.h[1], serio.h[2], psci.h[3], pkt_sched.h[4], coresight-stm.h), two of them were conversions from the open-coded variant; the usage of _BITUL in pkt_sched.h made me think that it is the better approach since people tend to use BIT-like macro anyway, so, by increasing a number of cases it may raise awareness of the UAPI specifics.

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/
[4] https://lore.kernel.org/lkml/[email protected]/

Quoted 5 lines

thanks,

greg k-h

Reviewed-by on v1 1/1
#5 lore raw
In reply to Eugene Syromiatnikov
Quoted 16 lines · Eugene Syromiatnikov

The BIT() macro definition is not available for the UAPI headers (moreover, it can be defined differently in the user space); replace its usage with the _BITUL() macro that is defined in <linux/const.h>.

Fixes 237483aa5cf4 ("coresight: stm: adding driver for CoreSight STM component")
---
 include/uapi/linux/coresight-stm.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/uapi/linux/coresight-stm.h +0 -0
index aac550a..8847dbf 100644

include/uapi/linux/coresight-stm.h line 8

Quoted 9 lines
include/uapi/linux/coresight-stm.h +4 -2
@@ -2,8 +2,10 @@
 #ifndef __UAPI_CORESIGHT_STM_H_
 #define __UAPI_CORESIGHT_STM_H_
 
-#define STM_FLAG_TIMESTAMPED   BIT(3)
-#define STM_FLAG_GUARANTEED    BIT(7)
+#include <linux/const.h>
+
+#define STM_FLAG_TIMESTAMPED   _BITUL(3)
+#define STM_FLAG_GUARANTEED    _BITUL(7)

Greg, if you want to pick this up right away:

Otherwise let me know and I'll add it to my next tree.

Thanks,
Mathieu

Quoted 6 lines
include/uapi/linux/coresight-stm.h +0 -1
 /*
  * The CoreSight STM supports guaranteed and invariant timing
--

2.1.4

#6 lore raw
Quoted 29 lines · Mathieu Poirier
Quoted 16 lines · Eugene Syromiatnikov

The BIT() macro definition is not available for the UAPI headers (moreover, it can be defined differently in the user space); replace its usage with the _BITUL() macro that is defined in <linux/const.h>.

Fixes 237483aa5cf4 ("coresight: stm: adding driver for CoreSight STM component")
---
 include/uapi/linux/coresight-stm.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/uapi/linux/coresight-stm.h +0 -0
index aac550a..8847dbf 100644

include/uapi/linux/coresight-stm.h line 8

Quoted 9 lines
include/uapi/linux/coresight-stm.h +4 -2
@@ -2,8 +2,10 @@
 #ifndef __UAPI_CORESIGHT_STM_H_
 #define __UAPI_CORESIGHT_STM_H_
 
-#define STM_FLAG_TIMESTAMPED   BIT(3)
-#define STM_FLAG_GUARANTEED    BIT(7)
+#include <linux/const.h>
+
+#define STM_FLAG_TIMESTAMPED   _BITUL(3)
+#define STM_FLAG_GUARANTEED    _BITUL(7)

Greg, if you want to pick this up right away:

Quoted 3 lines

Otherwise let me know and I'll add it to my next tree.

I'll take it now, thanks.

greg k-h