| arch |
arch/arm/core/mmu/arm_mmu_priv.h |
L87, L124 |
| drivers |
drivers/audio/mic_privacy/intel/mic_privacy_registers.h |
L23, L95, L125, L206 |
| drivers |
drivers/can/can_mcan.h |
L910, L951, L992 |
| drivers |
drivers/clock_control/clock_control_mchp_pic32cm_jh.c |
L99 |
| drivers |
drivers/clock_control/clock_control_mchp_pic32cm_pl.c |
L48 |
| drivers |
drivers/clock_control/clock_control_mchp_pic32cz_ca.c |
L92 |
| drivers |
drivers/clock_control/clock_control_mchp_sam_d5x_e5x.c |
L118 |
| drivers |
drivers/crypto/crypto_intel_sha_priv.h |
L58 |
| drivers |
drivers/crypto/crypto_intel_sha_registers.h |
L12, L36, L45, L54, L62, L70, L78, L86, L94, L101, L109, L116, L129, L137, L144 |
| drivers |
drivers/dai/intel/alh/alh.h |
L52 |
| drivers |
drivers/dai/intel/ssp/dai-params-intel-ipc4.h |
L136, L162, L187 |
| drivers |
drivers/ethernet/intel/eth_intel_igc_priv.h |
L369, L409 |
| drivers |
drivers/flash/flash_cadence_nand_ll.h |
L334 |
| drivers |
drivers/fpga/fpga_altera_agilex_bridge.h |
L75, L105, L121 |
| drivers |
drivers/gpio/gpio_max14906.h |
L93, L107, L121, L135, L149, L163, L177, L191, L205, L218, L228, L238, L252, L265 |
| drivers |
drivers/gpio/gpio_max14916.h |
L98, L112, L125, L136, L150, L164, L178, L192 |
| drivers |
drivers/gpio/gpio_max2219x.c |
L91, L105, L119, L132, L145, L156 |
| drivers |
drivers/i2c/i2c_dw_registers.h |
L16, L72, L94, L120, L132, L148 |
| drivers |
drivers/i2c/i2c_wch.c |
L40 |
| drivers |
drivers/interrupt_controller/intc_clic.h |
L46, L60, L69, L78, L101, L114 |
| drivers |
drivers/interrupt_controller/intc_intel_vtd.h |
L19, L62, L81, L99 |
| drivers |
drivers/memc/memc_mspi_aps_z8.h |
L43, L55, L65, L75, L86, L96, L104 |
| drivers |
drivers/mfd/mfd_infineon_hppass.c |
L59, L75, L89, L106, L134, L150 |
| drivers |
drivers/mipi_dbi/mipi_dbi_nxp_lcdic.c |
L53 |
| drivers |
drivers/pcie/host/ptm.h |
L15, L29 |
| drivers |
drivers/pcie/host/vc.h |
L16, L33, L44, L72, L89, L108 |
| drivers |
drivers/sensor/bosch/bmi160/bmi160.h |
L444 |
| drivers |
drivers/sensor/bosch/bmm350/bmm350.h |
L454 |
| drivers |
drivers/sensor/lm75/lm75.c |
L50 |
| drivers |
drivers/sensor/lm77/lm77.c |
L35 |
| drivers |
drivers/sensor/pixart/paa3905/paa3905.h |
L25 |
| drivers |
drivers/sensor/pni/rm3100/rm3100.h |
L31 |
| drivers |
drivers/sensor/tdk/icm45686/icm45686.h |
L50 |
| drivers |
drivers/spi/spi_it8xxx2.c |
L71 |
| drivers |
drivers/uaol/uaol_intel_adsp.h |
L40, L53, L63, L73, L82, L89, L96, L107, L119, L129, L140, L147, L154, L173, L183, L196 |
| drivers |
drivers/usb/device/usb_dc_kinetis.c |
L56 |
| drivers |
drivers/usb/udc/udc_kinetis.c |
L55 |
| drivers |
drivers/w1/w1_ds2477_85_common.h |
L180 |
| drivers |
drivers/watchdog/wdt_nxp_fs26.c |
L51 |
| subsys |
subsys/bluetooth/controller/ll_sw/lll.h |
L515, L517 |
| subsys |
subsys/bluetooth/controller/ll_sw/lll_conn.h |
L90 |
| subsys |
subsys/bluetooth/controller/ll_sw/ull_conn_iso_types.h |
L95 |
| subsys |
subsys/bluetooth/controller/ll_sw/ull_conn_types.h |
L170 |
| subsys |
subsys/bluetooth/controller/ll_sw/ull_llcp_internal.h |
L186 |
| subsys |
subsys/lorawan/services/frag_transport.c |
L93, L108 |
| subsys |
subsys/net/l2/ethernet/gptp/gptp_messages.h |
L296 |
| subsys |
subsys/net/l2/wifi/wifi_shell.c |
L87 |
| subsys |
subsys/net/lib/ptp/ds.h |
L190 |
| subsys |
subsys/portability/posix/options/posix_internal.h |
L39 |
| soc |
soc/amd/acp_7_0/include/acp70_chip_reg.h |
L15, L25, L33, L42, L107, L120, L133, L142, L154 |
| soc |
soc/amd/acp_7_0/include/acp70_fw_scratch_mem.h |
L54 |
| soc |
soc/amd/acp_7_x/include/acp7x_chip_reg.h |
L13, L22, L29, L36, L57, L79, L97, L105, L115, L122, L129, L139, L148, L159, L174, L185, L191, L198, L204, L211, L218, L225, L232, L239, L246, L253, L260, L267, L274, L281, L287, L293, L299, L305, L312, L319, L326, L334, L346, L357, L367, L377, L385, L397, L404, L411, L419, L427, L434, L442, L451, L464, L475, L496, L507, L522, L534, L547, L564, L579, L590, L601, L615, L633, L647, L671, L680 |
| soc |
soc/amd/acp_7_x/include/acp7x_fw_scratch_mem.h |
L54 |
| soc |
soc/intel/intel_adsp/common/include/manifest.h |
L40 |
| soc |
soc/ite/ec/it8xxx2/chip_chipregs.h |
L521, L584, L668 |
| soc |
soc/renesas/rz/common/pinctrl_rza.h |
L18 |
| soc |
soc/renesas/rz/common/pinctrl_rzg.h |
L18 |
| soc |
soc/renesas/rz/common/pinctrl_rzn.h |
L20 |
| soc |
soc/renesas/rz/common/pinctrl_rzt.h |
L20 |
| soc |
soc/renesas/rz/common/pinctrl_rzv.h |
L18 |
| include |
include/zephyr/acpi/acpi.h |
L47 |
| include |
include/zephyr/arch/arc/v2/arc_connect.h |
L120, L133, L154 |
| include |
include/zephyr/arch/x86/ia32/segmentation.h |
L132, L150, L186 |
| include |
include/zephyr/arch/xtensa/mpu.h |
L95, L141 |
| include |
include/zephyr/canbus/isotp.h |
L176 |
| include |
include/zephyr/display/mb_display.h |
L38 |
| include |
include/zephyr/drivers/dac/dac161s997.h |
L36 |
| include |
include/zephyr/drivers/flash/ra_flash_api_extensions.h |
L58 |
| include |
include/zephyr/drivers/mic_privacy/intel/mic_privacy.h |
L27 |
| include |
include/zephyr/drivers/misc/renesas_rx_dtc/renesas_rx_dtc.h |
L98 |
| include |
include/zephyr/drivers/sensor_data_types.h |
L157 |
| include |
include/zephyr/drivers/usb_c/usbc_pd.h |
L320, L351, L427, L474, L533, L552, L599, L618, L665, L698, L730 |
| include |
include/zephyr/irq_multilevel.h |
L25 |
| include |
include/zephyr/net/ethernet.h |
L361 |
| boards |
boards/arduino/opta/board.h |
L19 |
| samples |
samples/subsys/logging/syst/src/main.c |
L21 |
Problem Description
Many places use a C bit-field struct or union to map a fixed bit layout: a hardware register, a DMA descriptor, or a wire or flash field. The C standard does not fix that layout, so this is not portable.
From: https://github.com/zephyrproject-rtos/zephyr/blob/main/doc/contribute/coding_guidelines/index.rst?plain=1#L38
__packeddoes not help. It sets byte padding, not bit order.Already seen in practice: #113320 fixes a bit-field overlay in
irq_multilevel.hthat gave wrong values on big-endian. A guideline PR #113584 was closed as already covered by the rule above.A scan of
mainatb5fb5c845b9e(2026-07-16) finds 738 sites in 238 files. This is a wide clean-up, so it is an RFC, not one bug.Proposed Change (Summary)
FIELD_GET,FIELD_PREP, andGENMASK, with byte-order helpers (sys_le32_to_cpuand so on) at hardware or wire boundaries.No behaviour change is intended. The encodings stay the same. Only the access method changes.
The findings fall into four groups:
Sites per area:
Notes:
drivershas the most work.socis mostly register headers.includeholds API headers owned by each subsystem.kernelhas no findings.Proposed Change (Detailed)
The fix pattern:
Steps per PR: add named
GENMASKmasks, convert reads and writes toFIELD_GETandFIELD_PREP, add the right byte-order helper at each boundary, keep aBUILD_ASSERTon the word size, then remove the bit-field struct or union. Do the big-endian or cross-machine sites (protocol, DMA, flash) first.C1 to C3 are deterministic and can be treated as a firm list. C4 is heuristic. It keeps only strong signals (register casts, casts of typed byte buffers, memcpy between a bit-field object and a byte buffer). Confirm each C4 site before its PR.
Every site is listed below. Each file is a link to the snapshot. The numbers after it are the lines in that file.
C1: Direct bit-field unions (264 sites, 76 files)
C2: Transitive bit-field unions (38 sites, 32 files)
C3: Packed structs with bit-fields (192 sites, 78 files)
C4: Bit-field struct over raw memory (heuristic) (244 sites, 88 files)
Dependencies
This touches many maintainer areas: arch, drivers, subsys, soc, lib, include, boards, tests, and samples. See the per-area table in the summary for the size of each area.
includeheaders are owned by their subsystems, not one owner. No external modules and no on-wire or on-flash encodings change. Only the access method in the code changes.Concerns and Unresolved Questions
Alternatives Considered
FIELD_GETandFIELD_PREPover a plain word. Chosen. Standard C, already common in the tree, same idea as Linuxlinux/bitfield.h.Also to add, Linux documents mmap'd bitfield structs over hardware as non-portable and steers toward shift/mask instead: https://docs.kernel.org/core-api/packing.html#problem-statement (and FIELD_GET/FIELD_PREP in include/linux/bitfield.h is the concrete pattern).
Reports can be generated using the attached python script: bitfield_layout_audit.py
NOTE: Issue details and tree wide search is done using Claude Opus 4.8 LLM. Although the data is cross checked multiple time before posting here, please be aware the data could be error-prone.