Skip to contentSkip to conversation

ASoC: mchp-spdiftx: Fix clang -Wbitfield-constant-conversion

PATCH In review Nathan Chancellor 4 participants 8 messages Aug 10, 2022 – Aug 23, 2022

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

PATCH 1/1 ASoC: mchp-spdiftx: Fix clang -Wbitfield-constant-conversion

A recent change in clang strengthened its -Wbitfield-constant-conversion to warn when 1 is assigned to a 1-bit signed integer bitfield, as it can only be 0 or -1, not 1:

sound/soc/atmel/mchp-spdiftx.c:505:20: error: implicit truncation from 'int' to bit-field changes value from 1 to -1 [-Werror,-Wbitfield-constant-conversion]

          dev->gclk_enabled = 1;
                            ^ ~

1 error generated.

The actual value of the field is never checked, just that it is not zero, so there is not a real bug here. However, it is simple enough to silence the warning by making the bitfield unsigned, which matches the mchp-spdifrx driver.

---
 sound/soc/atmel/mchp-spdiftx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/atmel/mchp-spdiftx.c +1 -1
index 4850a177803d..ab2d7a791f39 100644
@@ -196,7 +196,7 @@ struct mchp_spdiftx_dev {
 	struct clk				*pclk;
 	struct clk				*gclk;
 	unsigned int				fmt;
-	int					gclk_enabled:1;
+	unsigned int				gclk_enabled:1;
 };
 
 static inline int mchp_spdiftx_is_running(struct mchp_spdiftx_dev *dev)

base-commit: 15205c2829ca2cbb5ece5ceaafe1171a8470e62b

Signature · 1 line
2.37.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Nathan Chancellor

A recent change in clang strengthened its -Wbitfield-constant-conversion to warn when 1 is assigned to a 1-bit signed integer bitfield, as it can only be 0 or -1, not 1:

sound/soc/atmel/mchp-spdiftx.c:505:20: error: implicit truncation from 'int' to bit-field changes value from 1 to -1 [-Werror,-Wbitfield-constant-conversion]

          dev->gclk_enabled = 1;
                            ^ ~

1 error generated.

The actual value of the field is never checked, just that it is not zero, so there is not a real bug here. However, it is simple enough to silence the warning by making the bitfield unsigned, which matches the mchp-spdifrx driver.

Quoted 4 lines

Ah yes, my favorite, signed one bit integers...thanks for the patch.

grepping for gclk_enabled, we see three drivers with similar duplication (single bit bitfields):

sound/soc/atmel/mchp-spdifrx.c
241: unsigned int gclk_enabled:1;

sound/soc/atmel/mchp-pdmc.c
118: u8 gclk_enabled:1;

sound/soc/atmel/mchp-spdiftx.c
200: int gclk_enabled:1;

Quoted 22 lines
---
 sound/soc/atmel/mchp-spdiftx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/atmel/mchp-spdiftx.c +1 -1
index 4850a177803d..ab2d7a791f39 100644
@@ -196,7 +196,7 @@ struct mchp_spdiftx_dev {
        struct clk                              *pclk;
        struct clk                              *gclk;
        unsigned int                            fmt;
-       int                                     gclk_enabled:1;
+       unsigned int                            gclk_enabled:1;
 };
 
 static inline int mchp_spdiftx_is_running(struct mchp_spdiftx_dev *dev)

base-commit: 15205c2829ca2cbb5ece5ceaafe1171a8470e62b --
2.37.1

Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw

From: Nick Desaulniers

Quoted 7 lines

Sent: 10 August 2022 22:14

Quoted 4 lines · Nathan Chancellor

A recent change in clang strengthened its -Wbitfield-constant-conversion to warn when 1 is assigned to a 1-bit signed integer bitfield, as it can only be 0 or -1, not 1:

Is there a -Wsigned-bitfield ?
You probably don't ever want the compiler to be generating the code to sign-propagate a bitfield.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

maintainer
#3 lore raw
In reply to Nathan Chancellor
Quoted 10 lines · Nathan Chancellor

A recent change in clang strengthened its -Wbitfield-constant-conversion to warn when 1 is assigned to a 1-bit signed integer bitfield, as it can only be 0 or -1, not 1:

sound/soc/atmel/mchp-spdiftx.c:505:20: error: implicit truncation from 'int' to bit-field changes value from 1 to -1 [-Werror,-Wbitfield-constant-conversion]

          dev->gclk_enabled = 1;
                            ^ ~

1 error generated.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: mchp-spdiftx: Fix clang -Wbitfield-constant-conversion

      commit: eab9100d9898cbd37882b04415b12156f8942f18

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

#4 lore raw

Hi Mark,

Quoted 12 lines · Mark Brown
Quoted 10 lines · Nathan Chancellor

A recent change in clang strengthened its -Wbitfield-constant-conversion to warn when 1 is assigned to a 1-bit signed integer bitfield, as it can only be 0 or -1, not 1:

sound/soc/atmel/mchp-spdiftx.c:505:20: error: implicit truncation from 'int' to bit-field changes value from 1 to -1 [-Werror,-Wbitfield-constant-conversion]

          dev->gclk_enabled = 1;
                            ^ ~

1 error generated.

[...]

Quoted 8 lines

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: mchp-spdiftx: Fix clang -Wbitfield-constant-conversion

      commit: eab9100d9898cbd37882b04415b12156f8942f18

I noticed that this was applied to for-6.1. I know you do not rebase or change your trees so this request might be rejected based on that alone but would it be possible to cherry-pick this to for-6.0 so that it can be applied to Linus's tree quicker? We have had to apply this change to our CI to keep our builds green in mainline, -tip, and 5.19/5.15 stable with clang-16 due to -Werror. If not, no worries, I should have made it clearer that is what I was looking for with the subject prefix.

Cheers,
Nathan

maintainer
#5 lore raw
Quoted 7 lines · Nathan Chancellor

I noticed that this was applied to for-6.1. I know you do not rebase or change your trees so this request might be rejected based on that alone but would it be possible to cherry-pick this to for-6.0 so that it can be applied to Linus's tree quicker? We have had to apply this change to our CI to keep our builds green in mainline, -tip, and 5.19/5.15 stable with clang-16 due to -Werror. If not, no worries, I should have made it clearer that is what I was looking for with the subject prefix.

Hrm, OK - it's a bit surprising that this didn't get fixed in -next before the clang change made it to mainline TBH, it looked like something that had just hit -next.

#6 lore raw
Quoted 10 lines · Mark Brown
Quoted 7 lines · Nathan Chancellor

I noticed that this was applied to for-6.1. I know you do not rebase or change your trees so this request might be rejected based on that alone but would it be possible to cherry-pick this to for-6.0 so that it can be applied to Linus's tree quicker? We have had to apply this change to our CI to keep our builds green in mainline, -tip, and 5.19/5.15 stable with clang-16 due to -Werror. If not, no worries, I should have made it clearer that is what I was looking for with the subject prefix.

Quoted 3 lines

Hrm, OK - it's a bit surprising that this didn't get fixed in -next before the clang change made it to mainline TBH, it looked like something that had just hit -next.

Right, sorry for not making that more clear in the commit message. The change in clang was made only a few hours before this patch so I did fix it quickly but we do not usually get any heads up on new warnings. They just appear then we fix them and move on. I'll make it clearer where I want the patch to go in the future, thanks for accommodating this one time.

Cheers,
Nathan

maintainer
#7 lore raw
In reply to Nathan Chancellor
Quoted 10 lines · Nathan Chancellor

A recent change in clang strengthened its -Wbitfield-constant-conversion to warn when 1 is assigned to a 1-bit signed integer bitfield, as it can only be 0 or -1, not 1:

sound/soc/atmel/mchp-spdiftx.c:505:20: error: implicit truncation from 'int' to bit-field changes value from 1 to -1 [-Werror,-Wbitfield-constant-conversion]

          dev->gclk_enabled = 1;
                            ^ ~

1 error generated.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: mchp-spdiftx: Fix clang -Wbitfield-constant-conversion

      commit: 5c5c2baad2b55cc0a4b190266889959642298f79

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark