From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D107F20ED; Fri, 4 Jul 2025 19:54:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751658883; cv=none; b=OJFNAkfEgIO+/CvAQhw53xnRA5EZD092UU4w7WnkBre1lsn+O7H0PhdF9g2anmybAAkJkO4NvLmmzRpWctO5rbLshrWV5tfzBNCg3j/zTMMx6mJAQwGsMdvSqbk+Aefsf80hKoZyY0m4Z0MeF5/wxsHfMwYtVBsXd0Q+JVX3DDE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751658883; c=relaxed/simple; bh=s7U7qyBLUL5BDR4GTAY51LdYayf6TDmHVnDdpE1qlJU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QgplrHTwWciaU4phMVcjoQmwbgblVJouIbrQ8xsWSfbtQDW21jWPTu2FtF2Iw0EPINwGqH9m4y85Z1+trJZHx6WLjv+/te2qqH9fMHBvVygKG9WhyhpHXAPbeiolpvzrHzz8pk/bBTt+D3rBEZswGvDJ5xYqHpGxPw6B32dwpCo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NNV3r66o; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NNV3r66o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D2ACC4CEE3; Fri, 4 Jul 2025 19:54:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751658883; bh=s7U7qyBLUL5BDR4GTAY51LdYayf6TDmHVnDdpE1qlJU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NNV3r66oF3swXeOHxfSifBKL6RwPgAVBfzFoj9HFE67v5sg1Z8a1Ac0SXshLhLV1f 3B6qORGtSxNXwc01JBc6MOrwiC9kDdArXEw2uC0xhW8YqVdkOz81QOBZ2XJnZN+PAv KE6OvEtrmUYzsgFpvLaLgVRezDOA7NzuQ0fOFUnzqHS8U3XrUlKT/khuR3RgEq56nK CCNkVCf8uOVJF9zfT4C8/DTLsHkhEjZ7cij3mubuvv96LE/cgMbUkejb1E0qI+MwMa 6vWkWSH+gwdScBaM40kZDU7RF0LrTo3nfu3AcZjJxofMNPjXLZhNIXtXv69ohexNhv 9pwz4L04ekoPw== Date: Fri, 4 Jul 2025 21:54:36 +0200 From: Danilo Krummrich To: Igor Korotin Cc: Miguel Ojeda , Alex Gaynor , Wolfram Sang , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Greg Kroah-Hartman , Viresh Kumar , Asahi Lina , Wedson Almeida Filho , Alex Hung , Tamir Duberstein , Xiangfei Ding , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-i2c@vger.kernel.org Subject: Re: [PATCH v2 2/4] rust: i2c: add manual I2C device creation abstractions Message-ID: References: <20250704153332.1193214-1-igor.korotin.linux@gmail.com> <20250704153912.1197034-1-igor.korotin.linux@gmail.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250704153912.1197034-1-igor.korotin.linux@gmail.com> On Fri, Jul 04, 2025 at 04:39:12PM +0100, Igor Korotin wrote: > -pub struct Device( > +pub struct Device( > Opaque, > PhantomData, > + PhantomData, > ); I see what you're doing here, but I think you're thinking this way too complicated. I recommend not to reuse the Device type to register a new I2C client device, it's adding too much complexity without any real value. You also don't want the DeviceContext types for a device registration, since the registration will never have any other DeviceContext than device::Normal (see also my comment on the sample module). DeviceContext types are only useful for &Device (i.e. references) given out for a specific scope, such as probe(), remove(), etc. The only thing you really want to do is to register a new I2C client device, get a i2c::Registration instance and call i2c_unregister_device() when the i2c::Registration is dropped. This is exactly the same use-case as we have in the auxiliary bus. I highly recommend looking at what auxiliary::Registration does [1]. Also note that if you want a reference to the device in the i2c::Registration, you can also add a i2c::Registration::device() method that returns an &i2c::Device, which through into() you can obtain an ARef from. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/rust/kernel/auxiliary.rs?h=v6.16-rc4#n299