From<u8> for Mode maps 252 of 256 inputs to Continuous (probably wontfix)
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 25/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- Active
- Stack technique
- rust
- Domaine
- embedded-iot
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
- 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. - Strengthen the rustdoc only — e.g. an explicit "callers must mask
with& 0b11" sentence plus a doctest showing the trap. Cheap,
non-breaking. - Stop re-exporting the
Fromimpl. Not possible without dropping
theModere-export, whichtests/reexports.rspins 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.
- Langage dominant
- Rust
- Étoiles
- 2
- Forks
- 7
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de OpenDevicePartnership/tmp108
-
audit:SBOS663A bug impact:field-visible
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
-
audit:SBOS663A bug documentation impact:field-visible verdict:contradicts
Difficulté 1/5 Moins d'une heure Accessibilité débutants 95/100
-
audit:SBOS663A bug enhancement impact:documentation
Difficulté 3/5 1-2 jours Accessibilité débutants 74/100
-
bug
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
Toutes les issues de OpenDevicePartnership/tmp108
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 83/100
n0-computer/iroh#4669 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
rubys/roundhouse#1950 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
cloudflare/workers-rs#1130 ·
Les mainteneurs répondent en général sous 11 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 69/100
vfarcic/dot-agent-deck#2160 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
RustCrypto/utils#1597 ·
Les mainteneurs répondent en général sous 1 jour