← Back to Pull requests

drivers: sensor: drop int64 casts where int32 suffices #127517

Open
unknown opened this pull request with 272 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 29, 2026 10:09 UTC
Author

Description

The hmc5883l, icm42605 and mpu9250 conversion helpers cast small int16 samples to int64_t for fraction math even though every intermediate fits in int32, pulling the software 64-bit division helper (__aeabi_ldivmod) onto divider-less cores on every sample:

  • drivers/sensor/honeywell/hmc5883l/hmc5883l.c \u2014 (((int64_t)raw_val % divider) 1000000L) / divider: the largest gain divisor in hmc5883l_gain[] is 1370, so remainder 1000000 peaks at 1.37e9.

  • drivers/sensor/tdk/icm42605/icm42605.c \u2014 the temperature conversion divides and mods a 64-bit raw_val 100 by 207; the value peaks at 3.3e6 and the remainder fraction at 2.06e8. This is the direct TDK sibling of the icm40627 conversion #125508 rewrote.

  • drivers/sensor/tdk/mpu9250/mpu9250.c \u2014 ((int64_t)(raw_val % 334) 1000000) / 334: peaks at 3.34e8.
  • The int64 casts are dropped so the conversions run in int32 arithmetic.

    Motivation and context

    Same class as #125508 and #126044. Found by rescanning drivers/sensor/ for 64-bit divisions and modulos by non-power-of-two constants after #126044; these three drivers cast values whose full intermediate chains fit int32. Neighboring / 256-style sites were excluded because the compiler already lowers signed power-of-two divides to shifts, and lis3mdl (largest divisor 6842) is excluded because the naive cast-drop would overflow int32 there \u2014 noted in #127516 as needing the wider per-gain reduction technique.

    Fixes #127516

    How was this tested?

    Equivalence verified exhaustively against the previous int64 form with C truncation semantics (not Python floor): all 2^16 signed int16 input values, for each hmc5883l gain divisor (all eight), for icm42605, and for mpu9250 \u2014 identical results, and every intermediate proven int32-bounded (largest: 1.37e9 in the hmc5883l 1370-divisor case). No local twister run available on this machine; CI compiles the drivers and runs the sensor test suites.

    Note

    Developed with AI assistance (rescan, rewrite and equivalence proof), reviewed and verified by the contributor \u2014 recorded via the Assisted-by: trailer in the commit message.

    Diff: 272 lines (+204 / -68) across 3 files Reviewer: rbuisson-invn Review duration: 2293m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.39) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 272 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.336
    Real PR Conversation Timeline
    1 comments
    "Review active on #127517"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.5% (MEDIUM) · Higher = larger blast radius
    39.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21% · Safe to merge
    21%