Re: [PATCH V7 03/16] rust: cpu: Add from_cpu()
From: Viresh Kumar
Date: Wed Jan 15 2025 - 02:21:03 EST
On 14-01-25, 19:44, Greg KH wrote:
> > +pub fn from_cpu(cpu: u32) -> Result<&'static Device> {
> > + // SAFETY: The pointer returned by `get_cpu_device()`, if not `NULL`, is a valid pointer to
> > + // a `struct device` and is never freed by the C code.
>
> I thought it was pointed out that it could be freed when a cpu was
> hot-unplugged? Or is that a different device in the cpu code? We seem
> to have 2 of them and it's not obvious which is which :(
I did reply [1] to that earlier. The CPU can get unregistered but the
memory for the device is never freed (it is part of struct cpu). Some
calls on the CPU device may fail later on (if called for an unregisted
dev), but should never crash the kernel.
--
viresh
[1] https://lore.kernel.org/all/20250109063605.gmykltd6bnjaspwm@vireshk-i7/