rust: i2c: fix I2cAdapter refcount double increment
A single bugfix for the Rust I2C abstractions, targeting 7.1. `I2cAdapter::get` calls `i2c_get_adapter()` which returns a pointer with an already-incremented refcount. The code then converts the raw pointer to an `ARef` via `.into()`, which calls `inc_ref()` again through the `From<&T> for ARef<T>` impl — resulting in a leaked device and module reference on every call. The fix uses `ARef::from_raw()` instead, which takes ownership of the existing refcount without incrementing it. Signed-off-by: Igor Korotin <igor.korotin@linux.dev> -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG0Kepq7dYk2deNuvoxQiWQ2T6tUFAmokUrYACgkQoxQiWQ2T 6tXfcw//SeqQ76PJjSQf1DKf7uTEgR73RZIVEEAWEYaABPOVmwZpIAniqMz+Np2s CBNVpttdcbgjCsbxQny9zbgCbeOGbexP2sMEuugjxDYwXAHo5OFnY3q0ReJVQIGa I6HB38lQpK1+p20W+CzqH7TIT5Tj7VOCpuIRu86lMUVTFVAgJSW8VMGkKqjO7ler VshMUQe8SJaIxC6XAj1ChsELfHptJozZw7zUZhj2wCmfs+pl43onE079DqNfxQJ8 YWgaF3oSBxh2/CFORJKpCy5S7J4P6JQ4j0U8G7Gvs01lhnXggPewA0oJTQlpfNPj UGKLnSo9pG0BdGcxFqiPKqfxrAq29LO776IcrRSQa7sEcSlwRh4L4h0LFY0TUvmY 5nR5BoXLOYpmrNP7WFCUISvjVXJaX8F3MEnVC7R/PmnOUhXWLBXZyzqzgUrAPkgl R4Ofye3yWpdJRes4O7diR3vnvRdxLMpfehJi2WHUjB90StxrLkYGZRK5fGj6+90m Pmefu7Qic1mos5jy0/9UjfaIaUS1W23KxX8HcNoMLZF/tl8YJ1FtMpm6ZrRSxM/v 1LiEXLZkQOfuNebjfyUZwzWIptYtq9h4N9X9ANykLPTiTncJmxQmzaPsoRE4ew0T AD7P/WpLFbLs2XI/J5JuAVrfnOe+UjnvsixBxuPxEtgVY5K2pjA= =LhTi -----END PGP SIGNATURE----- Merge tag 'rust-i2c-7.1-rc7' of https://github.com/ikrtn/linux into i2c/for-current rust: i2c: fix I2cAdapter refcount double increment
This commit is contained in:
commit
b3f240cca1
1 changed files with 3 additions and 1 deletions
|
|
@ -405,7 +405,9 @@ impl I2cAdapter {
|
|||
|
||||
// SAFETY: `adapter` is non-null and points to a live `i2c_adapter`.
|
||||
// `I2cAdapter` is #[repr(transparent)], so this cast is valid.
|
||||
Ok(unsafe { (&*adapter.as_ptr().cast::<I2cAdapter<device::Normal>>()).into() })
|
||||
// `i2c_get_adapter` returned the adapter with an incremented refcount, which we pass to
|
||||
// the `ARef`.
|
||||
Ok(unsafe { ARef::from_raw(adapter.cast::<I2cAdapter<device::Normal>>()) })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue