Re: [PATCH v3] rust: cpufreq: Fix temporary write in Registration::bios_limit_callback
Viresh Kumar <[email protected]> Tue, 28 Jul 2026 14:17:14 +0530
| Newsgroups | org.kernel.vger.rust-for-linux,org.kernel.vger.linux-pm |
|---|---|
| Message-ID | <dwdbn7ea6evjhxtpobcg3cxgi3shb65ddsvk6xrqbujbq22hqz@5hxvifua2zyo> |
On 20-07-26, 18:00, Priya Bala Govindasamy wrote:
> In `Registration::bios_limit_callback`, the expression
> `&mut (unsafe { *limit })` creates a reference to a temporary copy
> of the value pointed to by `limit` on the stack.
> Therefore, writes made by `T::bios_limit` go to this temporary
> instead of the memory location pointed to by `limit`.
>
> Additionally, `limit` may be uninitialized, such as when
> `Registration::bios_limit_callback` is invoked by `show_bios_limit`
> in drivers/cpufreq/cpufreq.c. Therefore creating a reference to
> `limit` is unsound.
>
> Fix this by changing the signature of `T::bios_limit` to return the limit
> value.
> `Registration::bios_limit_callback` can then update `limit` directly.
>
> Fixes: c6af9a1191d042839e56abff69e8b0302d117988 ("rust: cpufreq: Extend abstractions for driver registration")
> Reported-by: Dylan Zueck<[email protected]>
> Reported-by: Yuan Tan<[email protected]>
> Assisted-by: ChatGPT:gpt-5.4
> Signed-off-by: Priya Bala Govindasamy<[email protected]>
>
> changes in v3:
> - Update documentation for `bios_limit`
> - Use direct raw pointer assignment instead of non-dropping write for
> `limit`
> - v2 Link: https://lore.kernel.org/rust-for-linux/2fd4425697efb6d52459cd886115edd281bd5f44.1784155370.git.pgovind2@uci.edu/
> - v1 Link: https://lore.kernel.org/rust-for-linux/[email protected]/T/#t
> ---
The above part which shouldn't be part of the commit (Changes in v3),
should be added here after the `---` line. Else git am picks this up
as well in commit log.
> rust/kernel/cpufreq.rs | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
Applied. Thanks.
--
viresh