mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-30 14:33:24 -04:00
rust: cpufreq: Add CPUFREQ_TABLE_END as last table entry in TableBuilder::to_table
The `TableBuilder::to_table` function adds `Hertz(c_ulong::MAX).as_khz()`
as the last frequency entry in the frequency table.
But the C API expects the last entry to have frequency set to
`CPUFREQ_TABLE_END` which is `~1u` as per include/linux/cpufreq.h.
Fix this by setting the last frequency entry to `CPUFREQ_TABLE_END`
instead of `Hertz(c_ulong::MAX).as_khz()`.
Fixes: 2207856ff0 ("rust: cpufreq: Add initial abstractions for cpufreq framework")
Reported-by: Dylan Zueck<dzueck@uci.edu>
Reported-by: Yuan Tan<ytan089@ucr.edu>
Assisted-by: ChatGPT:gpt-5.6-terra
Signed-off-by: Priya Bala Govindasamy<pgovind2@uci.edu>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
This commit is contained in:
committed by
Viresh Kumar
parent
391b4b1d54
commit
b5e4771f20
@@ -361,23 +361,28 @@ pub fn new() -> Self {
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a new entry to the table.
|
||||
pub fn add(&mut self, freq: Hertz, flags: u32, driver_data: u32) -> Result {
|
||||
/// Adds a raw frequency-table entry.
|
||||
fn push(&mut self, frequency: u32, flags: u32, driver_data: u32) -> Result {
|
||||
// Adds the new entry at the end of the vector.
|
||||
Ok(self.entries.push(
|
||||
bindings::cpufreq_frequency_table {
|
||||
flags,
|
||||
driver_data,
|
||||
frequency: freq.as_khz() as u32,
|
||||
frequency,
|
||||
},
|
||||
GFP_KERNEL,
|
||||
)?)
|
||||
}
|
||||
|
||||
/// Adds a new entry to the table.
|
||||
pub fn add(&mut self, freq: Hertz, flags: u32, driver_data: u32) -> Result {
|
||||
self.push(freq.as_khz() as u32, flags, driver_data)
|
||||
}
|
||||
|
||||
/// Consumes the [`TableBuilder`] and returns [`TableBox`].
|
||||
pub fn to_table(mut self) -> Result<TableBox> {
|
||||
// Add last entry to the table.
|
||||
self.add(Hertz(c_ulong::MAX), 0, 0)?;
|
||||
self.push(bindings::CPUFREQ_TABLE_END as u32, 0, 0)?;
|
||||
|
||||
TableBox::new(self.entries)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user