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 719BD27815B; Thu, 11 Sep 2025 20:46:33 +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=1757623593; cv=none; b=A57kENbMfEUxGr2eg0BBBe+8m28G5E4O98bSeTeHgUrvz1Yfbz+SqVHvoCr0SaPn1xyb58pWaoluwHdDUXvhzgKptnGygq7lX3zgsUcmQXGx8eTsK2NAIzfsSIORRyI3PapSLFGJkedepmsWEQwWS7B5FR50NU6tejBvUBOnDwY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757623593; c=relaxed/simple; bh=FDVsLPvFCZn3mFoZlnMxuCM29yOEw+dWElg/JjBhpjE=; h=Mime-Version:Content-Type:Date:Message-Id:To:From:Subject:Cc: References:In-Reply-To; b=TosNw36n9ycUdBSsDuJh3r+3y+2bOHuLeNiQy/7YYgacMpdDGR6N7CcSrs/9kANA8Av/UeqLMiVKOwvzqABJ+0vReifJOrVqqAF7MhxymO5OqLiue2QX31HTUDXjgXlGMRM0XA92aPHDoZ46lKJg1K3WuSFzo1tm9629eL80h+k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BAGg7oco; 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="BAGg7oco" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FB1EC4CEF0; Thu, 11 Sep 2025 20:46:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757623593; bh=FDVsLPvFCZn3mFoZlnMxuCM29yOEw+dWElg/JjBhpjE=; h=Date:To:From:Subject:Cc:References:In-Reply-To:From; b=BAGg7oco2daxLPPYifOeEcYlXL4bIK4vbyI5LUvmdWP1oE1ZeZlmqcGoOw+tlzZZo l2EwBYW66pyJIKLAOk4uWbCQSLlOo/xTH577SQcI0PjHghvhYUDrnJKFlyLbY7sS26 L+2+/9UEZB0JXsyzHAvHI385GW9eP/DgFdShJtqkDCS7NRqv6vBmASqq1/6ZCqnsYj 2QdPjXK26P8/RQu99cdbt0l/eqYwAPMwnPaDz/bwlqtNh7Idh7iHnxC44ez0U6Wbcu 6Qnbji0wALUBy9OWpQ6hx2gJpqbCd4H6UtePRUfPzHuFm8IyFOROv0NnprLFDamgSu xTixZZ3/NoRaw== Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 11 Sep 2025 22:46:27 +0200 Message-Id: To: "Igor Korotin" From: "Danilo Krummrich" Subject: Re: [PATCH v5 3/3] samples: rust: add Rust I2C sample driver Cc: "Miguel Ojeda" , "Alex Gaynor" , "Wolfram Sang" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_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" , , , References: <20250911154717.96637-1-igor.korotin.linux@gmail.com> <20250911155048.97364-1-igor.korotin.linux@gmail.com> In-Reply-To: <20250911155048.97364-1-igor.korotin.linux@gmail.com> On Thu Sep 11, 2025 at 5:50 PM CEST, Igor Korotin wrote: > +// NOTE: The code below is expanded macro module_i2c_driver. It is not u= sed here > +// because we need to manually create an I2C client in `init()`. T= he macro > +// hides `init()`, so to demo client creation on adapter SAMPLE_I2= C_ADAPTER_INDEX > +// we expand it by hand. > +type Ops =3D kernel::i2c::Adapter; Not a huge fan of this type alias, but up to you. :) > +#[pin_data] > +struct DriverModule { > + #[pin] > + _driver: kernel::driver::Registration>, > + _reg: i2c::Registration, > +} > + > +impl kernel::InPlaceModule for DriverModule { > + fn init( > + module: &'static kernel::ThisModule, > + ) -> impl ::pin_init::PinInit { > + kernel::try_pin_init!(Self { > + _reg <- { > + let adapter =3D i2c::I2cAdapter::::get(SAMPLE_I2= C_ADAPTER_INDEX)?; Just i2c::I2cAdapter::get() is fine. > + > + i2c::Registration::new(adapter.as_ref(), &BOARD_INFO) Does i2c_new_client_device() grab a reference count of the adapter? If not,= you have to store an ARef within your i2c::Registration as well. > + }, > + _driver <- kernel::driver::Registration::new(::NAME,module,), > + }) > + } > +}