Skip to content

Fix Clang 22 warnings#7299

Merged
pelwell merged 6 commits intoraspberrypi:rpi-6.18.yfrom
KonstaT:rpi-6.18.y-clang
Apr 10, 2026
Merged

Fix Clang 22 warnings#7299
pelwell merged 6 commits intoraspberrypi:rpi-6.18.yfrom
KonstaT:rpi-6.18.y-clang

Conversation

@KonstaT
Copy link
Copy Markdown

@KonstaT KonstaT commented Apr 2, 2026

This patch set fixes build warnings with Clang. These issues were observed when compiling code merged from this repository as part of Android kernel which is compiled using Clang 22 and CONFIG_WERROR=y set.

I also reproduced that these issues are present and resolved with this patch set when compiling the kernel from this repository (rpi-6.18.y branch) with Clang 22 both cross-compiling on Ubuntu host as well as natively on Raspberry Pi 5 using Raspberry Pi OS.

# Install Raspberry Pi OS (2025-12-04-raspios-trixie-arm64.img.xz) and update
$ sudo apt update
$ sudo apt full-upgrade

# Install build dependecies (https://www.raspberrypi.com/documentation/computers/linux_kernel.html#natively-build-a-kernel)
$ sudo apt install bc bison flex libssl-dev make

# Install Clang 22 (https://apt.llvm.org/)
$ wget https://apt.llvm.org/llvm.sh
$ chmod +x llvm.sh
$ sudo ./llvm.sh 22

# Download kernel source code (shallow clone to save time)
$ git clone https://github.com/raspberrypi/linux -b rpi-6.18.y --depth=1
$ cd linux

# Compile using Clang 22 with CONFIG_WERROR=y set
$ export LLVM=-22 CC=clang-22 KERNEL=kernel_2712
$ make bcm2712_defconfig
$ scripts/config --file .config --set-val CONFIG_WERROR y
$ make Image.gz modules dtbs -j$(nproc)

Also fixed minor issue that SND_PIMIDI and SND_PISOUND_MICRO should rather select CRC8 than depend on it. This likely works here as some other drivers already selects CRC8. I generally don't compile the Android kernel with SND_PISOUND_MICRO enabled but it doesn't get set in defconfig as there's also no CRC8 set otherwise.

@6by9
Copy link
Copy Markdown
Contributor

6by9 commented Apr 7, 2026

I agree with "fixup! drm/vc4: Assign 32 overlay planes to writeback only"

I'll leave others to review the remaining patches.

@popcornmix
Copy link
Copy Markdown
Collaborator

These all look fine, although I'd like @pelwell to check the PIO_ORIGIN_ANY one (which I suspect is fine).

@pelwell
Copy link
Copy Markdown
Contributor

pelwell commented Apr 9, 2026

The PIO_ORIGIN_ANY change is going to need more thought by me, but I'm happy to merge the others now if you split it into a separate PR.

KonstaT added 6 commits April 9, 2026 20:58
* Fixes build with Clang.

drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c:1513:3: error: variable 'chan_flags_all' is uninitialized when used here [-Werror,-Wuninitialized]
 1513 |                 chan_flags_all |= dw->chan_flags[i];
      |                 ^~~~~~~~~~~~~~
drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c:1502:25: note: initialize the variable 'chan_flags_all' to silence this warning
 1502 |         uint32_t chan_flags_all;
      |                                ^
      |                                 = 0
1 error generated.
* Fixes build with Clang.

drivers/gpu/drm/vc4/vc4_plane.c:2799:2: error: variable 'txp_crtc' is used uninitialized whenever 'for' loop exits because its condition is false [-Werror,-Wsometimes-uninitialized]
 2799 |         drm_for_each_crtc(crtc, drm) {
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/drm/drm_crtc.h:1312:2: note: expanded from macro 'drm_for_each_crtc'
 1312 |         list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/list.h:783:7: note: expanded from macro 'list_for_each_entry'
  783 |              !list_entry_is_head(pos, head, member);                    \
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/vc4/vc4_plane.c:2809:20: note: uninitialized use occurs here
 2809 |                                         drm_crtc_mask(txp_crtc);
      |                                                       ^~~~~~~~
drivers/gpu/drm/vc4/vc4_plane.c:2799:2: note: remove the condition if it is always true
 2799 |         drm_for_each_crtc(crtc, drm) {
      |         ^
include/drm/drm_crtc.h:1312:2: note: expanded from macro 'drm_for_each_crtc'
 1312 |         list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
      |         ^
include/linux/list.h:783:7: note: expanded from macro 'list_for_each_entry'
  783 |              !list_entry_is_head(pos, head, member);                    \
      |              ^
drivers/gpu/drm/vc4/vc4_plane.c:2796:27: note: initialize the variable 'txp_crtc' to silence this warning
 2796 |         struct drm_crtc *txp_crtc;
      |                                  ^
      |                                   = NULL
1 error generated.
* Fixes build with Clang.

drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c:461:10: error: array index 18 is past the end of the array (that has type 'u8[1]' (aka 'unsigned char[1]')) [-Werror,-Warray-bounds]
  461 |                 setbit(eventmask_msg->mask, BRCMF_E_ULP);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/wireless/broadcom/brcm80211/brcmfmac/../include/brcmu_utils.h:37:30: note: expanded from macro 'setbit'
   37 | #define setbit(a, i)    (((u8 *)a)[(i)/NBBY] |= 1<<((i)%NBBY))
      |                                 ^  ~~~~~~~~
drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h:313:2: note: array 'mask' declared here
  313 |         u8      mask[1];
      |         ^
1 error generated.
…nk-up

* Fixes build with Clang.

drivers/pci/controller/pcie-brcmstb.c:1595:3: error: variable 'clkreq_cntl' is uninitialized when used here [-Werror,-Wuninitialized]
 1595 |                 clkreq_cntl |= PCIE_MISC_HARD_PCIE_HARD_DEBUG_CLKREQ_DEBUG_ENABLE_MASK;
      |                 ^~~~~~~~~~~
drivers/pci/controller/pcie-brcmstb.c:1578:17: note: initialize the variable 'clkreq_cntl' to silence this warning
 1578 |         u32 clkreq_cntl;
      |                        ^
      |                         = 0
1 error generated.
* Change SND_PIMIDI and SND_PISOUND_MICRO to select CRC8 instead of depend
  on it.
* Fixes build with Clang.

sound/drivers/upisnd/upisnd_codec.c:741:6: error: variable 'ret' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
  741 |         if (adau->clk_src != ADAU1961_CLK_SRC_MCLK)
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sound/drivers/upisnd/upisnd_codec.c:744:9: note: uninitialized use occurs here
  744 |         return ret;
      |                ^~~
sound/drivers/upisnd/upisnd_codec.c:741:2: note: remove the 'if' if its condition is always true
  741 |         if (adau->clk_src != ADAU1961_CLK_SRC_MCLK)
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  742 |                 ret = snd_soc_dapm_add_routes(dapm, &adau1961_dapm_pll_route, 1);
sound/drivers/upisnd/upisnd_codec.c:739:9: note: initialize the variable 'ret' to silence this warning
  739 |         int ret;
      |                ^
      |                 = 0
1 error generated.
* Fixes build with Clang.

sound/soc/bcm/hifiberry_studio_dac8x.c:770:41: error: equality comparison with extraneous parentheses [-Werror,-Wparentheses-equality]
  770 |                 if ((priv->card_info.card_clk_options == 0x02)) {
      |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
sound/soc/bcm/hifiberry_studio_dac8x.c:770:41: note: remove extraneous parentheses around the comparison to silence this warning
  770 |                 if ((priv->card_info.card_clk_options == 0x02)) {
      |                     ~                                 ^      ~
sound/soc/bcm/hifiberry_studio_dac8x.c:770:41: note: use '=' to turn this equality comparison into an assignment
  770 |                 if ((priv->card_info.card_clk_options == 0x02)) {
      |                                                       ^~
      |                                                       =
1 error generated.
@KonstaT
Copy link
Copy Markdown
Author

KonstaT commented Apr 9, 2026

Done. Split the PIO_ORIGIN_ANY change to #7309.

RP1_PIO_ORIGIN_ANY is defined elsewhere as ((uint16_t)(~0)).
https://github.com/raspberrypi/linux/blob/rpi-6.18.y/include/uapi/misc/rp1_pio_if.h#L16

Not familiar with the code so not sure why PIO_ORIGIN_ANY is defined here as ((uint)(~0)).

Would
#define PIO_ORIGIN_ANY RP1_PIO_ORIGIN_ANY
actually be more clear if it's fine otherwise?

@pelwell pelwell merged commit eb7cf94 into raspberrypi:rpi-6.18.y Apr 10, 2026
11 of 12 checks passed
@KonstaT
Copy link
Copy Markdown
Author

KonstaT commented Apr 10, 2026

Thanks for the merge!

Couple of follow up questions.

  1. At what point do you generally start merging the sublevel releases (i.e. 6.18.y in this case) instead of rebasing Raspberry Pi specific patches on top? It's a bit tedious for downstream maintainer, that's all. E.g. in my case I'm merging this with AOSP common kernel source with few additional patches on top (few less now thanks to this :)).

  2. Could you consider adding a build target to CI that uses Clang compiler to avoid similar problems in the future? Clang diagnostics seems to be better at picking up possible issues.

@popcornmix
Copy link
Copy Markdown
Collaborator

  1. when the kernel reaches apt. Probably within the next few weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants