Re: [PATCH v2] i2c: rust: fix I2cAdapter refcounts double increment

From: Igor Korotin

Date: Sat May 30 2026 - 13:12:06 EST


Hello Nicolás

On 5/26/2026 8:47 PM, Nicolás Antinori wrote:
// 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() })
+ Ok(unsafe {
+ ARef::from_raw(NonNull::new_unchecked(
+ adapter.as_ptr().cast::<I2cAdapter<device::Normal>>(),
+ ))
+ })
}
}

The `adapter` here is already a NonNull pointer. No need to call .as_ptr() and then rewrap
with new_unchecked.

Cheers
Igor