From nobody Sun Feb 8 17:43:42 2026 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 2C47330F53B; Wed, 7 Jan 2026 10:35:51 +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=1767782152; cv=none; b=YpwDsa+mkGgXqC9omsqsHjpng8/1i2dWgqgwpxp8omM1c030RxKGjZifseQLRQNTqSWOfz9AejPqtPa5RpealSgGWUHDtzgaLNNuLwqoXHE2QSjYuOV+NGtCmNceQDw9k2IJTIKNQ9mHArtrlV7KP5y3BFAskXL8Si78Ci1qvDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767782152; c=relaxed/simple; bh=OABHPQQlfV11ZUpM0ZvmkayXerwyi+tSxR6IpM/FE2I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rkpwvxBgLm6wsqHHHIK3H9hylUHOKkD0N1hVn1Xfjot+fWOGZAXRrMDX3Fj5OxCfresQdZj1ZrgtCm4qcKhDgEeZ8ewy6tSW+/4eU9hPXikxvUdI3OO3Voq1I4aLegBIBdrZK7dM1GBNP9BxjdlAqWQVjdpe8OvmcwIYNGbY17A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iFFGYRPa; 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="iFFGYRPa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46DB8C16AAE; Wed, 7 Jan 2026 10:35:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767782151; bh=OABHPQQlfV11ZUpM0ZvmkayXerwyi+tSxR6IpM/FE2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iFFGYRPaXJz8BmGlymkAz/+ywO+rmGRdvutVFoK1d5DSMszcfg7IjbZn8w7+MUUZk 33/9fLLuLZ9qzcbd/SyEUQRVb9boXqrIIoJxAQ5xr3xRVVuR8da5lil3icSxsqK6zi WO41N/VRmO0vgaDaZ5/tfcGEXp7xzbrDxsoLvaw0KNj0eXQaFvzn8RVDxai9ROhxYp 3lnRP7GSGXJOvG8m+b4RP1qNnIOlh1ftr4uxmCyHf0+KYcCA/9vpLWpzOIPSMxdL5n DEJE0hWBHiQh/MSxjbqpXJHl+gnhg0gCiM1aPeQ3jCRzkn4/el1zm8Sw147UdGW99W glVNKOBRGuzLQ== From: Danilo Krummrich To: gregkh@linuxfoundation.org, rafael@kernel.org, igor.korotin.linux@gmail.com, ojeda@kernel.org, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, david.m.ertman@intel.com, ira.weiny@intel.com, leon@kernel.org, bhelgaas@google.com, kwilczynski@kernel.org, wsa+renesas@sang-engineering.com Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-pci@vger.kernel.org, linux-usb@vger.kernel.org, linux-i2c@vger.kernel.org, Danilo Krummrich Subject: [PATCH 5/6] rust: driver: add DriverData type to the generic Driver trait Date: Wed, 7 Jan 2026 11:35:04 +0100 Message-ID: <20260107103511.570525-6-dakr@kernel.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260107103511.570525-1-dakr@kernel.org> References: <20260107103511.570525-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@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" Add an associated type DriverData to the Driver trait indicating the type of the driver's device private data. Signed-off-by: Danilo Krummrich --- rust/kernel/auxiliary.rs | 2 ++ rust/kernel/driver.rs | 4 ++++ rust/kernel/i2c.rs | 2 ++ rust/kernel/pci.rs | 2 ++ rust/kernel/platform.rs | 2 ++ rust/kernel/usb.rs | 2 ++ 6 files changed, 14 insertions(+) diff --git a/rust/kernel/auxiliary.rs b/rust/kernel/auxiliary.rs index e712d1b89dc3..cb26238e95b0 100644 --- a/rust/kernel/auxiliary.rs +++ b/rust/kernel/auxiliary.rs @@ -25,10 +25,12 @@ =20 // SAFETY: // - `bindings::auxiliary_driver` is a C type declared as `repr(C)`. +// - `T` is the type of the driver's device private data. // - `struct auxiliary_driver` embeds a `struct device_driver`. // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `st= ruct device_driver`. unsafe impl driver::Driver for Adapter { type DriverType =3D bindings::auxiliary_driver; + type DriverData =3D T; const DEVICE_DRIVER_OFFSET: usize =3D core::mem::offset_of!(Self::Driv= erType, driver); } =20 diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs index 4b0c53b7d22a..77c1f7434897 100644 --- a/rust/kernel/driver.rs +++ b/rust/kernel/driver.rs @@ -108,11 +108,15 @@ /// /// Implementors must guarantee that: /// - `DriverType` is `repr(C)`, +/// - `DriverData` is the type of the driver's device private data. /// - `DriverType` embeds a valid `struct device_driver` at byte offset `D= EVICE_DRIVER_OFFSET`. pub unsafe trait Driver { /// The specific driver type embedding a `struct device_driver`. type DriverType: Default; =20 + /// The type of the driver's device private data. + type DriverData; + /// Byte offset of the embedded `struct device_driver` within `DriverT= ype`. /// /// This must correspond exactly to the location of the embedded `stru= ct device_driver` field. diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs index 56f1ed8163a0..6a3923a8b8a7 100644 --- a/rust/kernel/i2c.rs +++ b/rust/kernel/i2c.rs @@ -94,10 +94,12 @@ macro_rules! i2c_device_table { =20 // SAFETY: // - `bindings::i2c_driver` is a C type declared as `repr(C)`. +// - `T` is the type of the driver's device private data. // - `struct i2c_driver` embeds a `struct device_driver`. // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `st= ruct device_driver`. unsafe impl driver::Driver for Adapter { type DriverType =3D bindings::i2c_driver; + type DriverData =3D T; const DEVICE_DRIVER_OFFSET: usize =3D core::mem::offset_of!(Self::Driv= erType, driver); } =20 diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 68466150ef20..fe63b53d55d6 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -52,10 +52,12 @@ =20 // SAFETY: // - `bindings::pci_driver` is a C type declared as `repr(C)`. +// - `T` is the type of the driver's device private data. // - `struct pci_driver` embeds a `struct device_driver`. // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `st= ruct device_driver`. unsafe impl driver::Driver for Adapter { type DriverType =3D bindings::pci_driver; + type DriverData =3D T; const DEVICE_DRIVER_OFFSET: usize =3D core::mem::offset_of!(Self::Driv= erType, driver); } =20 diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index 56d9e968634e..af94fb58aafb 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -28,10 +28,12 @@ =20 // SAFETY: // - `bindings::platform_driver` is a C type declared as `repr(C)`. +// - `T` is the type of the driver's device private data. // - `struct platform_driver` embeds a `struct device_driver`. // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `st= ruct device_driver`. unsafe impl driver::Driver for Adapter { type DriverType =3D bindings::platform_driver; + type DriverData =3D T; const DEVICE_DRIVER_OFFSET: usize =3D core::mem::offset_of!(Self::Driv= erType, driver); } =20 diff --git a/rust/kernel/usb.rs b/rust/kernel/usb.rs index a9a9d2298d87..b09fe8bcca13 100644 --- a/rust/kernel/usb.rs +++ b/rust/kernel/usb.rs @@ -29,10 +29,12 @@ =20 // SAFETY: // - `bindings::usb_driver` is a C type declared as `repr(C)`. +// - `T` is the type of the driver's device private data. // - `struct usb_driver` embeds a `struct device_driver`. // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `st= ruct device_driver`. unsafe impl driver::Driver for Adapter { type DriverType =3D bindings::usb_driver; + type DriverData =3D T; const DEVICE_DRIVER_OFFSET: usize =3D core::mem::offset_of!(Self::Driv= erType, driver); } =20 --=20 2.52.0