Skip to content

iio: trx-rf: ad9088: fix __counted_by misuse in ad9088_clk_register()#3215

Merged
nunojsa merged 1 commit intomainfrom
staging/xlnx/ad9088-Wsequence-point
Mar 27, 2026
Merged

iio: trx-rf: ad9088: fix __counted_by misuse in ad9088_clk_register()#3215
nunojsa merged 1 commit intomainfrom
staging/xlnx/ad9088-Wsequence-point

Conversation

@nunojsa
Copy link
Copy Markdown
Collaborator

@nunojsa nunojsa commented Mar 27, 2026

clk_hw_onecell_data::hws is a flexible array annotated with __counted_by(num). Using hws[num++] to append clocks is, in theory, correct from a sequence point perspective (the post-increment in a subscript is well-defined in C), but it triggers -Wsequence-point warnings with recent GCC versions. More importantly, it violates the __counted_by contract: the array is accessed at index num before the counter is incremented, triggering runtime UBSAN bounds checks.

Fix this by indexing hws with the source enum directly (which already indexes into phy->clks[]) and setting clk_data->num once upfront in ad9088_probe().

PR Description

  • Please replace this comment with a summary of your changes, and add any context
    necessary to understand them. List any dependencies required for this change.
  • To check the checkboxes below, insert a 'x' between square brackets (without
    any space), or simply check them after publishing the PR.
  • If you changes include a breaking change, please specify dependent PRs in the
    description and try to push all related PRs simultaneously.

PR Type

  • Bug fix (a change that fixes an issue)
  • New feature (a change that adds new functionality)
  • Breaking change (a change that affects other repos or cause CIs to fail)

PR Checklist

  • I have conducted a self-review of my own code changes
  • I have compiled my changes, including the documentation
  • I have tested the changes on the relevant hardware
  • I have updated the documentation outside this repo accordingly
  • I have provided links for the relevant upstream lore

clk_hw_onecell_data::hws is a flexible array annotated with
__counted_by(num). Using hws[num++] to append clocks is, in theory,
correct from a sequence point perspective (the post-increment in a
subscript is well-defined in C), but it triggers -Wsequence-point
warnings with recent GCC versions. More importantly, it violates the
__counted_by contract: the array is accessed at index num before the
counter is incremented, triggering runtime UBSAN bounds checks.

Fix this by indexing hws with the source enum directly (which already
indexes into phy->clks[]) and setting clk_data->num once upfront in
ad9088_probe().

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
@nunojsa nunojsa merged commit 91f00ab into main Mar 27, 2026
30 of 31 checks passed
@nunojsa nunojsa deleted the staging/xlnx/ad9088-Wsequence-point branch March 27, 2026 14:12
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.

2 participants