From<u8> for Mode maps 252 of 256 inputs to Continuous (probably wontfix)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- rust
- Lĩnh vực
- embedded-iot
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Rust
- Star
- 2
- Fork
- 7
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của OpenDevicePartnership/tmp108
-
audit:SBOS663A bug impact:field-visible
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
-
audit:SBOS663A bug documentation impact:field-visible verdict:contradicts
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
-
audit:SBOS663A bug enhancement impact:documentation
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 74/100
-
bug
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Tất cả issue của OpenDevicePartnership/tmp108
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
rubys/roundhouse#1917 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày
-
good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[cosmic-applet-battery] Division by zero displays NaN% when UPower reports max_brightness = 0Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
pop-os/cosmic-applets#1619 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
binding:python bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày