From<u8> for Mode maps 252 of 256 inputs to Continuous (probably wontfix)

オープン
#80 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
rust
領域
embedded-iot

調査の方向性

Read tmp108.ddsl:27-33 and :40 to understand the documented conversion precondition and generator input, then inspect generated src/inner.rs:794. Check tests/reexports.rs and sources/datasheet.txt:754 for public API and device behavior. Done means confirming the recommended wontfix, or narrowing work to the optional rustdoc clarification.

索引モデルが issue の本文から書いたものです。

説明

audit:SBOS663A impact:latent question verdict:unsupported

Mode is the only one of the five re-exported configuration enums with an
infallible u8 conversion. Polarity, Hysteresis, ConversionRate
and Thermostat all get TryFrom<u8> with
device_driver::ConversionError<u8>; Mode gets:

impl From<u8> for Mode {
    fn from(val: u8) -> Self {
        match val {
            0 => Self::Shutdown,
            1 => Self::OneShot,
            _ => Self::default(),      // Continuous
        }
    }
}

src/inner.rs:794

So 252 of 256 inputs — every value above 3 — silently become
Continuous. tmp108::Mode::from(0x20) reports continuous conversion,
although the M field of the configuration byte 0x20 is 00, shutdown.

This is probably working as intended

Filing for the record rather than as an action item, because the obvious
fixes are all worse than the problem:

The field is two bits wide. Every path inside the driver reaches this
conversion through the generated field accessor, which masks to 1:0
first. Only a caller invoking Mode::from directly on an unmasked byte
can reach the catch-all with an out-of-domain value.

The code is generated. src/inner.rs is machine output from
tmp108.ddsl (AGENTS.md gotcha #2 forbids hand-editing it), and the
catch-all is not an accident of the generator — it is what
tmp108.ddsl:40 asks for:

enum Mode {
    shutdown: 0,
    one-shot: 1,
    continuous: default 2,
},

default is what makes device-driver emit From + catch-all instead of
TryFrom. It is there deliberately, from bbcfbe5 fix!: decode M = 0b11 as continuous mode, because 0b10 and 0b11 are both continuous:

When the TMP108 is in continuous conversion mode (M1 = 1), a single conversion is performed at a rate

SBOS663A §7.4.3, sources/datasheet.txt:754

Getting "accept 0..=3, reject 4.." out of the generator would need either
a fourth enum variant for 0b11 — which would be a worse public API,
since it is not a distinct mode — or hand-edited generated code.

It is already documented. tmp108.ddsl:27-33 spells out the exact
hazard:

From<u8> converts an already-extracted M-field value, not
a whole configuration byte: it neither masks nor validates
its input.

Options

  1. Wontfix. The precondition is documented at the DDSL and flows into
    the generated rustdoc; the field is two bits; no internal path can
    violate it. Recommended.
  2. Strengthen the rustdoc only — e.g. an explicit "callers must mask
    with & 0b11" sentence plus a doctest showing the trap. Cheap,
    non-breaking.
  3. Stop re-exporting the From impl. Not possible without dropping
    the Mode re-export, which tests/reexports.rs pins as public API.

Note on semver

The v0.6.0 tag did export TryFrom<u8> for Mode; the change to From
landed in bbcfbe5, correctly marked fix!. That bump is already owed
and release-plz will take it. No action needed here.

Provenance

Raised by the datasheet compliance audit of PR #77. The audit's architect
agent reported this as a defect requiring a checked conversion and
attributed it to the PR stack; both the severity and the attribution were
wrong, and are corrected above.

主要言語
Rust
スター
2
フォーク
7
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

OpenDevicePartnership/tmp108 のほかの issue

OpenDevicePartnership/tmp108 の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。