Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: devres: initialize Devres::inner::data last

Users may want to access the Devres object from callbacks registered
through the initialization of Devres::inner::data.

For those accesses to be valid, Devres::inner::data must be initialized
last [1].

Credit to Boqun for spotting this [2].

Link: https://lore.kernel.org/lkml/DBBPHO26CPBS.2OVI1OERCB2J5@kernel.org/ [1]
Link: https://lore.kernel.org/lkml/aHSmxWeIy3L-AKIV@Mac.home/ [2]
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20250714113712.22158-1-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

+8 -8
+8 -8
rust/kernel/devres.rs
··· 137 137 let callback = Self::devres_callback; 138 138 139 139 try_pin_init!(&this in Self { 140 - // INVARIANT: `inner` is properly initialized. 141 - inner <- Opaque::pin_init(try_pin_init!(Inner { 142 - data <- Revocable::new(data), 143 - devm <- Completion::new(), 144 - revoke <- Completion::new(), 145 - })), 140 + dev: dev.into(), 146 141 callback, 147 - dev: { 142 + // INVARIANT: `inner` is properly initialized. 143 + inner <- { 148 144 // SAFETY: `this` is a valid pointer to uninitialized memory. 149 145 let inner = unsafe { &raw mut (*this.as_ptr()).inner }; 150 146 ··· 154 158 bindings::devm_add_action(dev.as_raw(), Some(callback), inner.cast()) 155 159 })?; 156 160 157 - dev.into() 161 + Opaque::pin_init(try_pin_init!(Inner { 162 + devm <- Completion::new(), 163 + revoke <- Completion::new(), 164 + data <- Revocable::new(data), 165 + })) 158 166 }, 159 167 }) 160 168 }