Skip to content

drivers/clk: use uintptr_t for register addresses to fix GCC15 warnings - #19168

Merged
xiaoxiang781216 merged 2 commits into
apache:masterfrom
RogerNext:fix/clk-uintptr-t
Jun 18, 2026
Merged

xiaoxiang781216 merged 2 commits into
apache:masterfrom
RogerNext:fix/clk-uintptr-t

Conversation

@RogerNext

Copy link
Copy Markdown
Contributor

Summary

Change the reg field type from uint32_t to uintptr_t in all clock provider structs and their clk_register_*() function prototypes. Update clk_write() / clk_read() inline helpers accordingly.

Fixes #16896 (sub-item: drivers/clk/clk.h int-to-pointer cast warning).

Changes

drivers/clk/clk.h (2 functions):

  • clk_write(uint32_t reg, ...) → clk_write(uintptr_t reg, ...)
  • clk_read(uint32_t reg) → clk_read(uintptr_t reg)
  • Remove redundant (uintptr_t) cast in function bodies

include/nuttx/clk/clk_provider.h (6 structs + 6 prototypes):

  • uint32_t reg → uintptr_t reg in: clk_gate_s, clk_divider_s, clk_phase_s, clk_fractional_divider_s, clk_multiplier_s, clk_mux_s
  • Matching change in all clk_register_gate/divider/phase/fractional_divider/multiplier/mux() prototypes

Impact

  • Build: Fixes -Wint-to-pointer-cast warning on 64-bit targets (e.g. sim). GCC15 promotes this warning to an error.
  • User: No functional change on 32-bit embedded targets (uintptr_t == uint32_t).
  • Hardware: No change.
  • Documentation: No change.
  • Security: No change.
  • Compatibility: ABI-compatible on all 32-bit targets. On 64-bit targets the struct layout changes (field width 4→8 bytes) but the clock framework is not used on 64-bit hardware.

Why uintptr_t

The reg field holds a memory-mapped register address. Using uintptr_t is the semantically correct type for storing addresses in C. All callers pass address values, and the inline functions already cast through (uintptr_t) before dereferencing.

Testing

Verified with sim:nsh build (the primary 64-bit target that triggers the warning):

./tools/configure.sh sim:nsh
make -j$(nproc)
# Before: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
# After: clean build, no warnings from clk.h

Also verified ARM cross-compilation has no regression:

./tools/configure.sh stm32f4discovery:nsh
make -j$(nproc)  # clean build

Change the 'reg' field type from uint32_t to uintptr_t in all clock
provider structs (clk_gate_s, clk_divider_s, clk_phase_s,
clk_fractional_divider_s, clk_multiplier_s, clk_mux_s) and their
corresponding clk_register_*() function prototypes.

Also update clk_write() and clk_read() inline functions to take
uintptr_t parameter and remove the now-redundant (uintptr_t) cast.

On 32-bit embedded platforms uintptr_t equals uint32_t so there is
no functional change. On 64-bit targets (e.g. sim) this fixes
-Wint-to-pointer-cast warnings that GCC15 promotes to errors.

Fixes: apache#16896
Signed-off-by: hanzhijian <[email protected]>
@github-actions github-actions Bot added Area: Drivers Drivers issues Size: S The size of the change in this PR is small labels Jun 17, 2026
@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@Zepp-Hanzj please fix:

Error: clk/clk_divider.c:364:19: error: conflicting types for 'clk_register_divider'; have 'struct clk_s *(const char *, const char *, uint8_t,  uint32_t,  uint8_t,  uint8_t,  uint16_t)' {aka 'struct clk_s *(const char *, const char *, unsigned char,  unsigned int,  unsigned char,  unsigned char,  short unsigned int)'}
  364 | FAR struct clk_s *clk_register_divider(FAR const char *name,
      |                   ^~~~~~~~~~~~~~~~~~~~

Update the function definitions in all 6 clk implementation files to
match the uintptr_t parameter type already declared in clk_provider.h.

Fixes CI error:
  error: conflicting types for 'clk_register_divider'

Signed-off-by: hanzhijian <[email protected]>
@RogerNext

Copy link
Copy Markdown
Contributor Author

Fixed. Updated all 6 implementation files (, , , , , ) to match the parameter type in the header. Thanks for catching this!

@xiaoxiang781216
xiaoxiang781216 merged commit 8857d36 into apache:master Jun 18, 2026
41 checks passed
@RogerNext
RogerNext deleted the fix/clk-uintptr-t branch June 19, 2026 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Support for GCC15

3 participants