rust: devres: initialize Devres::inner::data last
Subsystems (2)
Danilo Krummrich
maintainerPATCH 1/1 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].
--- rust/kernel/devres.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
rust/kernel/devres.rs +8 -8
@@ -137,14 +137,10 @@ pub fn new<'a, E>(let callback =Self ::devres_callback;try_pin_init! (&this inSelf { -// INVARIANT: `inner` is properly initialized. - inner <-Opaque ::pin_init (try_pin_init! (Inner { - data <-Revocable ::new (data), - devm <-Completion ::new (), - revoke <-Completion ::new (), - })), + dev: dev.into (), callback, - dev: { +// INVARIANT: `inner` is properly initialized. + inner <- {// SAFETY: `this` is a valid pointer to uninitialized memory. let inner =unsafe { &raw mut (*this.as_ptr ()).inner };
@@ -158,7 +154,11 @@ pub fn new<'a, E>( bindings::devm_add_action (dev.as_raw (),Some (callback), inner.cast ()) })?; - dev.into () +Opaque ::pin_init (try_pin_init! (Inner { + devm <-Completion ::new (), + revoke <-Completion ::new (), + data <-Revocable ::new (data), + })) }, }) }
base-commit: 3964d07dd821efe9680e90c51c86661a98e60a0f
prerequisite-patch-id: 12a88f7c46bec668e4f71ec0d94b1782d9446d0b
Signature · 1 line
2.50.0
Alice Ryhl
reviewerQuoted 6 lines · Danilo Krummrich
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::datamust be initialized last [1].
Quoted 7 lines
Credit to Boqun for spotting this [2].
Signed-off-by Danilo Krummrich <[email protected]>---
base-commit:3964d07dd821efe9680e90c51c86661a98e60a0f
I couldn't find this commit. Where does this apply?
Alice
Danilo Krummrich
maintainerQuoted 9 lines · Alice Ryhl
Quoted 8 lines · Danilo Krummrich
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::datamust be initialized last [1].Credit to Boqun for spotting this [2].
Quoted 7 lines
Quoted 5 lines
Signed-off-by Danilo Krummrich <[email protected]>---
base-commit:3964d07dd821efe9680e90c51c86661a98e60a0fI couldn't find this commit. Where does this apply?
The commit is in driver-core-next.
Quoted 17 lines · Danilo Krummrich
Quoted 15 lines · Alice Ryhl
Quoted 13 lines · Danilo Krummrich
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::datamust be initialized last [1].Credit to Boqun for spotting this [2].
Signed-off-by Danilo Krummrich <[email protected]>---
base-commit:3964d07dd821efe9680e90c51c86661a98e60a0f
Quoted 3 lines
Quoted 1 line
I couldn't find this commit. Where does this apply?
The commit is in driver-core-next.
Danilo Krummrich
maintainerQuoted 11 lines · Danilo Krummrich
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::datamust be initialized last [1].Credit to Boqun for spotting this [2].
Applied to driver-core-testing, thanks!