From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792601985; b=cyLT8JIXmLzEyE0v3tX97sLkX+WpqrZ0yd9H+lg1AcBAiSw0SoJBpTjrLO54is5jBaeD 9HzByzauOZi10pxoB4juIVYry2/BlZmSztXV3sAa1zMrkhk03pk8whZ2eSvW1wSCFudzu QZhKffRUfgDO5VyorRyC/nHJsJOgL6DcvPv4QEmZ5ArQKWtTv1wbTMOwEgKC+lPVakgFe VfoiL5OxwBTQOlEXLadWJGT1BWt07c0EimCxpRt5LsTQn91MzOi0wBElS8ugTG74aCcpc Ntdk40H29kAOCtSZ/2VpiP2q/Q8iZEdU7Vpkiw7oubLgRo8UdiJaEb9LlVQmomiXZ3g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792601985; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: In-Reply-To:References:Content-Type:Content-Transfer-Encoding: MIME-Version; bh=p+CU0uLPlyx2SCbGFn0tLzOAhUz48rH3EvqMuFceNuw=; b=hdmpoPVr04p0j5zFO1YVsEP8ptdCAqdZFAfnWmG4f/N2hg6lJ1zgLe9OPbvSWaXIviVc v4BIScSmsF43RF11XyuQ+dSc2T8U0OEyFyKlBo8QIqNL0E9DsqJEAUwSNPL65UN+HrEhA OtKsnIKA//f64Kc3dqt0OFjBz9sM8Ges+htFA6EHj0DkhNm2vuIoPV/OhxwvwBYvFH6B+ hkDpFUpt32UcbyCj+gJg4Nwv8F6SrwL2vnxxz4LbR5OWw8NPsI825Ueg8D8gjZTsfxaop yp4blSGln22axB6sOE1WiSx4bNhR+mz/LHTWnoCO5ApBVP1uZkieUvdIG9HY1/0QhFw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=none smtp.remote-ip=91.218.175.71 Received: from mta0.migadu.com (out-71.mta0.migadu.com [91.218.175.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F85D606A329 for ; Wed, 21 Oct 2026 16:59:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5F85D606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: linux-i2c@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=N2OoIaXbm1ikGvwpS1JJSDFdorhSOcRL/wya42gaR/o=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1792601977; v=1; x=1793206777; b=WqohzBuXMER1LmjiCeUCqqT3n8lklluRkRPsxMIjlU1bosfcFkiH5w/GJGYfTwMS7MRRniwW R64eJpT1uOdaQPteFt49LBqyJyKoAX/7hmh1cq1dAiDDzX72NdvsXJG/M9S07K6GTAojBCM6oBe xJRmKI4T+lMdZXoUDKMiFCzs= X-Envelope-To: linux-i2c@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id de2331398842e179; Wed, 21 Oct 2026 16:59:37 +0000 X-Mizu-Trace-ID: de2331398842e179 X-Migadu-Flow: FLOW_OUT From: Igor Korotin To: Muchamad Coirul Anwar , Danilo Krummrich Cc: Jonathan Cameron , Miguel Ojeda , Gary Guo , Alice Ryhl , Daniel Almeida , Lars-Peter Clausen , Mark Brown , Brandon StJohn , linux-iio@vger.kernel.org, linux-i2c@vger.kernel.org, rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH v6 0/4] iio: position: add Rust driver for ams AS5600 Date: Wed, 21 Oct 2026 17:59:36 +0100 Message-ID: <179260197668.3127.18219777718091081046@linux.dev> In-Reply-To: <20261016154819.17936-1-muchamadcoirulanwar@gmail.com> References: <20261016154819.17936-1-muchamadcoirulanwar@gmail.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Hi Muchamad, Reviewed the lifetime/teardown contracts you asked about. read_raw() has a problem: it takes parent: &Device and recovers &I2cClient via TryFrom. That conversion just got removed upstream ("rust: i2c: remove TryFrom<&Device> implementation for &I2cClient", use-after-free, unrelated thread), so this won't compile anymore. More importantly, Gary Guo made the point that needing the conversion at all is the actual design issue: a class device shouldn't reach back into a generic parent reference during a callback -- whatever bus-specific resource it needs should be captured once, at registration time, and handed back via its own private data. Concretely, this means dropping devres and letting Data<'bound> carry a borrowed reference directly, which it's designed for (Driver::Data<'bound>: Send + 'bound): pub struct As5600Priv<'a> { client: &'a I2cClient, #[pin] io_lock: Mutex<()>, } unsafe impl Send for As5600Priv<'_> {} unsafe impl Sync for As5600Priv<'_> {} unsafe impl IioDriver for As5600Priv<'_> { fn read_raw(&self, _chan: *const iio_chan_spec, info: IioChanInfo) -> Result { let client = self.client; ... } } In probe(), capture the client once via deref coercion (Core -> Bound) and split the driver struct so the registered IIO device carries the same 'bound lifetime: struct As5600; struct As5600Data<'bound> { _iio_dev: Device, Registered>, } impl Driver for As5600 { type Data<'bound> = As5600Data<'bound>; fn probe<'bound>(dev: &'bound I2cClient>, ...) -> ... { let client: &'bound I2cClient = dev; ... } } register() then just returns Device directly instead of transferring it to parent devres -- that transfer is what forced T: 'static in the first place, which is what made storing the borrowed client impossible and pushed you toward TryFrom. I built this end to end against current rust-next: compiles clean, zero warnings, and zero changes to rust/kernel/i2c.rs. Happy to send the full diff if it's useful as a starting point for v7. Cheers Igor