scsi: ufs: Fix the build for gcc 9 and before
Subsystems (2)
Bart Van Assche
reviewerPATCH 1/1 scsi: ufs: Fix the build for gcc 9 and before
gcc compilers before version 10 cannot do constant-folding for sub-byte bitfields. This makes the compiler layout tests fail. Hence skip the layout checks for gcc 9 and before.
--- drivers/ufs/core/ufshcd.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/ufs/core/ufshcd.c +9 -0
@@ -10564,6 +10564,15 @@ static const struct dev_pm_ops ufshcd_wl_pm_ops = {static void ufshcd_check_header_layout (void ) { +#if defined(__GNUC__) && __GNUC__ -0 <10 +/* +* gcc compilers before version 10 cannot do constant-folding for +* sub-byte bitfields. Hence skip the layout checks for gcc 9 and +* before. +*/ +return ; +#endif +BUILD_BUG_ON (((u8 *)&(struct request_desc_header ){ .cci =3 })[0 ] !=3 );
Quoted 18 lines · Bart Van Assche
gcc compilers before version 10 cannot do constant-folding for sub-byte bitfields. This makes the compiler layout tests fail. Hence skip the layout checks for gcc 9 and before.
Cc Arnd Bergmann <[email protected]>Cc Naresh Kamboju <[email protected]>Reported-by Naresh Kamboju <[email protected]>Suggested-by Arnd Bergmann <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- drivers/ufs/core/ufshcd.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/ufs/core/ufshcd.c +0
-0
drivers/ufs/core/ufshcd.c static const struct dev_pm_ops ufshcd_wl_pm_ops = { · line 10567
Quoted 4 lines
drivers/ufs/core/ufshcd.c +1
-0@@ -10564,6 +10564,15 @@ static const struct dev_pm_ops ufshcd_wl_pm_ops = {static void ufshcd_check_header_layout (void ) { +#if defined(__GNUC__) && __GNUC__ -0 <10
clang defines __GNUC__ and it does not sound like it is impacted by this issue? I just built with LLVM 11 through 17 and did not see it. Can this be made more specific?
Also, can we use IS_ENABLED() and not rely on the preprocessor? This appears to work for me.
if (IS_ENABLED(CONFIG_CC_IS_GCC) && CONFIG_GCC_VERSION < 100000)
return;Quoted 11 lines
drivers/ufs/core/ufshcd.c +8
-0+/* +* gcc compilers before version 10 cannot do constant-folding for +* sub-byte bitfields. Hence skip the layout checks for gcc 9 and +* before. +*/ +return ; +#endif +BUILD_BUG_ON (((u8 *)&(struct request_desc_header ){ .cci =3 })[0 ] !=3 );
Bart Van Assche
reviewerQuoted 9 lines · Nathan Chancellor
Quoted 3 lines · Bart Van Assche
static void
ufshcd_check_header_layout(void)
{
+#ifdefined(__GNUC__)&&__GNUC__-0 < 10clang defines
__GNUC__and it does not sound like it is impacted by this issue? I just built with LLVM 11 through 17 and did not see it. Can this be made more specific?
Quoted 5 lines
Also, can we use
IS_ENABLED()and not rely on the preprocessor? This appears to work for me.if (IS_ENABLED(CONFIG_CC_IS_GCC) && CONFIG_GCC_VERSION < 100000) return;
Thanks for the feedback. A new version of this patch has been posted.
Bart.