mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
rust: clk: document overflow panics in Hertz constructors
`Hertz::from_khz()`, `from_mhz()` and `from_ghz()` multiply their
argument by 1_000, 1_000_000 and 1_000_000_000 respectively without
checking for overflow. When `CONFIG_RUST_OVERFLOW_CHECKS` is enabled,
each panics once its argument exceeds `c_ulong::MAX` divided by that
factor. None of the three documents this. The panic occurs only at
runtime, when the argument is not a constant expression.
Add the missing `# Panics` sections stating the bound for each unit.
Fixes: d01d702056 ("rust: clk: Add initial abstractions")
Signed-off-by: Georgios Androutsopoulos <georgeandrout13@gmail.com>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Brian Masney <bmasney@redhat.com>
This commit is contained in:
parent
4e39820b60
commit
45a68afbd4
|
|
@ -35,16 +35,31 @@ impl Hertz {
|
|||
const GHZ_TO_HZ: c_ulong = 1_000_000_000;
|
||||
|
||||
/// Create a new instance from kilohertz (kHz)
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if `CONFIG_RUST_OVERFLOW_CHECKS` is enabled and `khz` is greater
|
||||
/// than `c_ulong::MAX / 1_000`.
|
||||
pub const fn from_khz(khz: c_ulong) -> Self {
|
||||
Self(khz * Self::KHZ_TO_HZ)
|
||||
}
|
||||
|
||||
/// Create a new instance from megahertz (MHz)
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if `CONFIG_RUST_OVERFLOW_CHECKS` is enabled and `mhz` is greater
|
||||
/// than `c_ulong::MAX / 1_000_000`.
|
||||
pub const fn from_mhz(mhz: c_ulong) -> Self {
|
||||
Self(mhz * Self::MHZ_TO_HZ)
|
||||
}
|
||||
|
||||
/// Create a new instance from gigahertz (GHz)
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if `CONFIG_RUST_OVERFLOW_CHECKS` is enabled and `ghz` is greater
|
||||
/// than `c_ulong::MAX / 1_000_000_000`.
|
||||
pub const fn from_ghz(ghz: c_ulong) -> Self {
|
||||
Self(ghz * Self::GHZ_TO_HZ)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user