From nobody Tue Oct 7 12:25:21 2025 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09DD61FF5F9; Wed, 9 Jul 2025 19:31:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752089479; cv=none; b=Ya9g46KQa+UwL0TNyBOquure7ZiatWcaw+px78Djbq2PR9w7UuA7zFQ8hlMBnrVaeqXYclAJ0EVlJUdBbw4/gIqHvhUweeWTJdmXtPQ2VHl5+jVeDoQJM1f0GP8eyL+PydpllyOgT6vnCZJL6Nlc7dOcOSweoCGFtiwVuX8tK/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752089479; c=relaxed/simple; bh=ad0JLCjojYueo3Sm2psnrCMmwWyDVQ5VOKEoot7PSzs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bJy2XnmXlqIDcv6tPdHs4TsMMf79XJQnkRpdicngZvWoRs86KRsIqGdIsA9rycESkmpZX03nmJUC7I9VOyz4qM+QplgclF9TZFxHd6bL0SB8m0n2YQ1h3R0zOe4ChgmBwWdmvc35KrJtglxKTcjYeiK2vtwCssQmu/r6xntDBXs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fK9+ZfmZ; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fK9+ZfmZ" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7d0976776dcso26393585a.2; Wed, 09 Jul 2025 12:31:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752089477; x=1752694277; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ldMka5dibqXZ7WdzcWGUOI29OAgjt9RZ/4NFPnclSgw=; b=fK9+ZfmZh9hDhM4+nW0eJ8h/fyyAN2hZ7SzHbEV8iBf/hjGXCDu8DlC/4zWhoY+l3P yS/4z5BVDT7IIrSkWYPAosebG4MiIY9AG+fpGbeb7hqpedaEZhCNCiW0kSYV94ef6uu9 c5BEdK/DA423HuVYJFG+uAALB4D0wvRg1NCo9JFsh/aB01tga7gv/Yln9t/1m27qSmYK WAlcBpNL6A5v/84KtgmAl21wD4OWO8xGuW1o/61YQnRG7GhUepYjX+1AUj3Bbz1OxGho 6Xt4YFCp9o9nLJ0EYhoUU6vnHR9xnG7kXsXLf+gNHeB8IJUzMeWeUAwxuEQTIK0TPix4 Fdgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752089477; x=1752694277; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ldMka5dibqXZ7WdzcWGUOI29OAgjt9RZ/4NFPnclSgw=; b=YIksf8BqbE7wE5dZAuyafIk5NPBqhlz5FsT5/uHjHO1ROIUgoCx7FmTnpWKH9eiw9X St+MLZWHYYEyDJkC6WFaEt9Vb5DQTp6nDVV3A8ZUv2yGrIOajHDBEYMEgnVa5mxpFoN9 MwKgRA5OD8DF6GjmcbsJhg7bUY99On5sf8KIFV1gEN0saW2q2WkUqXrgJUcPJadrj4sX pmnGrmTGnsYxyFLer9XeaF/TFvFtBI6EgzJdXbeyWTycPbR5b/8r54Z/B2jada1EssGe FwO2Pgn3FD3s+8n+S7il1D8kjGTFBQ5YZGUObiPPySX/3Y0P342WOVL79bdosNAJccul XamA== X-Forwarded-Encrypted: i=1; AJvYcCUjDEIva7ympd85/gDsPkhFMp5CxOWOFqPyfS9vu3uYljeX/TsLrpQvIBpXhFUggFnlVPfMIQ9eNtCy@vger.kernel.org, AJvYcCXVTUH7iRbd6ui4b2dSk68dPd8Fu+YFBvNxKnh5NXuhWyEzFx7feIPdevFQ57ggIwHQ4MxszhBylEdD7QE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4FsmIaD9eL5tTfb5uxnw2iwPivKzgeo4TprX8UPCxAeDRrG1l oDKI/qa+2tr3trXPUW9R0t9ZCHpU3M8kOcRB+pVeOcGyiR4Aei1SOCOj X-Gm-Gg: ASbGncuHUlqGnK4t5UCaJHK5rzt+wiNlmGk6UisaUvCMvU+LkwTzvQUAgyDcFHQCrrH uvJ8Ltp6ud26LaOruU3/u+mVKBmwo5iXGKmTa+oRzqEY6tvU+r4O78mKgAGMfn9jHUbQsF2gnzQ 820R0h/64v9yVCx9gtYkk+bDIdTYi8OTgB23i1j3mtgYfbYn72QlZOZ0NpPbMzMgMwTi1jbA+jS SoGnUISpppoL66K4WGXGNOr+IIXcX88lTiGU2fd4lvl28CCcR6Gv7qTCkiKxsREqKtUmPe0rec2 9UabDP7aC7FeGrct/BvOUhMWgzWaYtcw9k5PE8GpGg2cXOfxhcVWeS0li0PxKI0ameGrRaDPQpk LD2G3/pWX8A88iaFHz/lxWjcjY7QO5V4WemelOnpnd7CW6PR9dsaz7At8hQ== X-Google-Smtp-Source: AGHT+IEH1UwHra46hpBf3iMMwE4Hix+6e2RpwFrxKVfp8/PjbWTFld0HMynQTrUS+cTLlcMEytOZ3A== X-Received: by 2002:a05:620a:2729:b0:7db:665b:67ce with SMTP id af79cd13be357-7db80d77003mr436568785a.38.1752089476730; Wed, 09 Jul 2025 12:31:16 -0700 (PDT) Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ([148.76.185.197]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7d5dbd94242sm991741285a.9.2025.07.09.12.31.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jul 2025 12:31:16 -0700 (PDT) From: Tamir Duberstein Date: Wed, 09 Jul 2025 15:31:11 -0400 Subject: [PATCH v4 1/6] rust: list: simplify macro capture Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250709-list-no-offset-v4-1-a429e75840a9@gmail.com> References: <20250709-list-no-offset-v4-0-a429e75840a9@gmail.com> In-Reply-To: <20250709-list-no-offset-v4-0-a429e75840a9@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Tamir Duberstein , Christian Schrefl X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openssh-sha256; t=1752089473; l=2683; i=tamird@gmail.com; h=from:subject:message-id; bh=ad0JLCjojYueo3Sm2psnrCMmwWyDVQ5VOKEoot7PSzs=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgtYz36g7iDMSkY5K7Ab51ksGX7hJgs MRt+XVZTrIzMVIAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QE1tdh31f5IvmitGCzPAfgKxFcjqOlJkrOMeCtjq7MkCeqe49/K0841BDiovf24hPTEDJ2iQ3xM LL+jDomP+TAk= X-Developer-Key: i=tamird@gmail.com; a=openssh; fpr=SHA256:264rPmnnrb+ERkS7DDS3tuwqcJss/zevJRzoylqMsbc Avoid manually capturing generics; use `ty` to capture the whole type instead. Reviewed-by: Christian Schrefl Tested-by: Alice Ryhl Reviewed-by: Alice Ryhl Signed-off-by: Tamir Duberstein --- rust/kernel/list/impl_list_item_mod.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/rust/kernel/list/impl_list_item_mod.rs b/rust/kernel/list/impl= _list_item_mod.rs index 1f9498c1458f..6bfa59fde17b 100644 --- a/rust/kernel/list/impl_list_item_mod.rs +++ b/rust/kernel/list/impl_list_item_mod.rs @@ -43,7 +43,7 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut List= Links { macro_rules! impl_has_list_links { ($(impl$(<$($implarg:ident),*>)? HasListLinks$(<$id:tt>)? - for $self:ident $(<$($selfarg:ty),*>)? + for $self:ty { self$(.$field:ident)* } )*) =3D> {$( // SAFETY: The implementation of `raw_get_list_links` only compile= s if the field has the @@ -51,9 +51,7 @@ macro_rules! impl_has_list_links { // // The behavior of `raw_get_list_links` is not changed since the `= addr_of_mut!` macro is // equivalent to the pointer offset operation in the trait definit= ion. - unsafe impl$(<$($implarg),*>)? $crate::list::HasListLinks$(<$id>)?= for - $self $(<$($selfarg),*>)? - { + unsafe impl$(<$($implarg),*>)? $crate::list::HasListLinks$(<$id>)?= for $self { const OFFSET: usize =3D ::core::mem::offset_of!(Self, $($field= ).*) as usize; =20 #[inline] @@ -85,18 +83,14 @@ pub unsafe trait HasSelfPtr macro_rules! impl_has_list_links_self_ptr { ($(impl$({$($implarg:tt)*})? HasSelfPtr<$item_type:ty $(, $id:tt)?> - for $self:ident $(<$($selfarg:ty),*>)? + for $self:ty { self.$field:ident } )*) =3D> {$( // SAFETY: The implementation of `raw_get_list_links` only compile= s if the field has the // right type. - unsafe impl$(<$($implarg)*>)? $crate::list::HasSelfPtr<$item_type = $(, $id)?> for - $self $(<$($selfarg),*>)? - {} + unsafe impl$(<$($implarg)*>)? $crate::list::HasSelfPtr<$item_type = $(, $id)?> for $self {} =20 - unsafe impl$(<$($implarg)*>)? $crate::list::HasListLinks$(<$id>)? = for - $self $(<$($selfarg),*>)? - { + unsafe impl$(<$($implarg)*>)? $crate::list::HasListLinks$(<$id>)? = for $self { const OFFSET: usize =3D ::core::mem::offset_of!(Self, $field) = as usize; =20 #[inline] --=20 2.50.0 From nobody Tue Oct 7 12:25:21 2025 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D6E4242D79; Wed, 9 Jul 2025 19:31:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752089482; cv=none; b=ZzebjTXUpUxJQs211CGpS0eYgJ1b3OHdtdLscXBAUGOhy0EDuZDNwcGquiGrcQQLTCWHNeaaaCKcKuMVxqCmIlX+k+6LVncWWAX1TrLgJ5BAdE/wDkHkNbtnnAmdLFvX3He4GEMn+URk35+fUJJPq89JdYTM/3/lE6gh+z/hSD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752089482; c=relaxed/simple; bh=rfVTctJezhzHZeEc5LPnMWXQzcKkJ7KvGm+Y0/Cjgfo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lFJ0XWQu8GZ7kUk8/KEpr9XtzrKgQGzHC27XF4/bEHOOGQSVp+XjmHLvUyc+CObkNVL5ifW3afnABpJuh8JE10iXZstSMj8JCf0/3fT0W04bX3HxuvvpAgQzV2x5MRb8suaHAqcJ6JyoWYKUeEs+724JrF1rY3Ls+QBJDWvCouY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kKao+NZb; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kKao+NZb" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7d09f11657cso27771185a.0; Wed, 09 Jul 2025 12:31:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752089478; x=1752694278; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=uU1W1AJg1khtiFXJRn+2wHqncOyahEVL95tTLku4mAQ=; b=kKao+NZbdUgpBhmC/pZ85COgnCAr8OW+zBcBRXnTmaO5Y6m0ay3ukmRdvuuKx8JcMX /Y4bmvD8jdobn7cVQ23laGyQa7D0bFWiN7LHsV9C3GXgHKINqbqJZDZidrGG32C7sZ00 Tsw/i6vswWOcsyD704iMqLVIuxyfP1V4gw0200yGGrcIXjC6OUZW3KKM6oabngENjS5C Q5YIeXdyd2E+OJXFXyxM2STOT6jjxSryrQPKdF3hBs/8B4uFEB7ez5cynx1xo+bvhdaf igd/1VJHiIOqfA56giNDwLsGXL5yIm9dhId7Ez0/LRnFBEB8CQAkwY2Jksic5zaEqcL0 rxmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752089478; x=1752694278; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uU1W1AJg1khtiFXJRn+2wHqncOyahEVL95tTLku4mAQ=; b=eHpcX2F2xDYj/9SptGsAY29fbiLPZdk5maDdqOuFhcPVsByDvOiGVmkehAS67zNf5x Ie09m/X+TFFB1bG59W5T13L/T4/BUBfi/YWp4rsto3hL3Nltp+5f02gQkAZI5dTb2iMQ j9lbiziWxvOkh4pyuO7ko3LbOSoz5FjM6ncFGeGREebdghzBVoodZuysM35Ia983Iqv6 595vmDMiZmo7N+nDH/lQZWI+k68QOUoiJA7iT/ZxrwuZWh15bRAcaIrCdyJL2GNUp8a4 vdrEiPu1M6sXcBIKUPlBAhyNcRCxMXNBU//W6f28JREGt3StmqNXv3OrPSbTMi1WPdd8 TnbA== X-Forwarded-Encrypted: i=1; AJvYcCWsQYrTOsbM806mvwPAH1wIgf/ZFnOt9lZa6cqFcCACfHvQeledcbykzp1yZGzur/5bq5cSrgysmS2v3H8=@vger.kernel.org, AJvYcCXC4aDcB0WDLRkoDOMjJ54b9JSFgssDCFjCUTpdSAXAI3Pi6MNLTIgfFTLpeGcwIwxtxP3fU+PdpYms@vger.kernel.org X-Gm-Message-State: AOJu0Yxf9vjHLXmWwgPhexf/03qxStVHJ3pBavLy0MaY4Yj1WWFlU/Uv JFfnNhe3OIHd7FvW+lvqdMo+3BVuEnt3YVHoadtcY4eC/cbcWgQ7YHWZ X-Gm-Gg: ASbGncthBwTHrPCoIGZOFivqGPtdNedgCv05Y0o1QvD3Wbj4wzyntlHgJ50D3dHXlNp fJVUK6DJ5VqPqt++pUg9OviEb7Is1ZCsR2K8OnM0xm0ifsiYG8I3b7kb1acYewbd14pYfG6/L3P ysl1WtdCDb4W3ELxP5s1CqUmlQzjWEs1v5Eb2uCWW1v0tba3fr68MMfwSHjFptm6MVgcSHNKw57 GhRVigk2tI1/8fceOyc+6x2gXcKg+vYt/acyJgzI2XqqJZNGLk4wwIo/tevN22vk1GSP/GC5v4S Iy7gKIf1VlTelFuzBVOE5FrTMnIdgKh52cOJihxL7J++WmNnZE0ADh7VYoHtyEXm9UEXJcx3jU+ eggesiNfWl+wW4n+QtHK5sHe/7K4u4dTWMtg6FEdRV9GGWNy9URkONgGf6g== X-Google-Smtp-Source: AGHT+IHtE81Yi1qqk14P+6gFZL5CG2GxZBneBQnMHdbbF1n7EJNN9SgbLROegV+i4KvIoNtw8epZRA== X-Received: by 2002:a05:620a:2983:b0:7d4:4e61:4673 with SMTP id af79cd13be357-7db7b121330mr593331685a.6.1752089478056; Wed, 09 Jul 2025 12:31:18 -0700 (PDT) Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ([148.76.185.197]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7d5dbd94242sm991741285a.9.2025.07.09.12.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jul 2025 12:31:17 -0700 (PDT) From: Tamir Duberstein Date: Wed, 09 Jul 2025 15:31:12 -0400 Subject: [PATCH v4 2/6] rust: list: use consistent type parameter style Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250709-list-no-offset-v4-2-a429e75840a9@gmail.com> References: <20250709-list-no-offset-v4-0-a429e75840a9@gmail.com> In-Reply-To: <20250709-list-no-offset-v4-0-a429e75840a9@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Tamir Duberstein , Christian Schrefl X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openssh-sha256; t=1752089473; l=2752; i=tamird@gmail.com; h=from:subject:message-id; bh=rfVTctJezhzHZeEc5LPnMWXQzcKkJ7KvGm+Y0/Cjgfo=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgtYz36g7iDMSkY5K7Ab51ksGX7hJgs MRt+XVZTrIzMVIAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QL1ZR8D35HlhcB8KU6JS+PqXmdvxlK17TMj0KLv7v6m4hGnzFRq5ijCNp+ca9cdS+ZrZ+xAjzcB d6c4smvwgmgY= X-Developer-Key: i=tamird@gmail.com; a=openssh; fpr=SHA256:264rPmnnrb+ERkS7DDS3tuwqcJss/zevJRzoylqMsbc Refer to the type parameters of `impl_has_list_links{,_self_ptr}!` by the same name used in `impl_list_item!`. Capture type parameters of `impl_list_item!` as `tt` using `{}` to match the style of all other macros that work with generics. Reviewed-by: Christian Schrefl Tested-by: Alice Ryhl Reviewed-by: Alice Ryhl Signed-off-by: Tamir Duberstein --- rust/kernel/list/impl_list_item_mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rust/kernel/list/impl_list_item_mod.rs b/rust/kernel/list/impl= _list_item_mod.rs index 6bfa59fde17b..27feaf849c48 100644 --- a/rust/kernel/list/impl_list_item_mod.rs +++ b/rust/kernel/list/impl_list_item_mod.rs @@ -41,7 +41,7 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut List= Links { /// Implements the [`HasListLinks`] trait for the given type. #[macro_export] macro_rules! impl_has_list_links { - ($(impl$(<$($implarg:ident),*>)? + ($(impl$({$($generics:tt)*})? HasListLinks$(<$id:tt>)? for $self:ty { self$(.$field:ident)* } @@ -51,7 +51,7 @@ macro_rules! impl_has_list_links { // // The behavior of `raw_get_list_links` is not changed since the `= addr_of_mut!` macro is // equivalent to the pointer offset operation in the trait definit= ion. - unsafe impl$(<$($implarg),*>)? $crate::list::HasListLinks$(<$id>)?= for $self { + unsafe impl$(<$($generics)*>)? $crate::list::HasListLinks$(<$id>)?= for $self { const OFFSET: usize =3D ::core::mem::offset_of!(Self, $($field= ).*) as usize; =20 #[inline] @@ -81,16 +81,16 @@ pub unsafe trait HasSelfPtr /// Implements the [`HasListLinks`] and [`HasSelfPtr`] traits for the give= n type. #[macro_export] macro_rules! impl_has_list_links_self_ptr { - ($(impl$({$($implarg:tt)*})? + ($(impl$({$($generics:tt)*})? HasSelfPtr<$item_type:ty $(, $id:tt)?> for $self:ty { self.$field:ident } )*) =3D> {$( // SAFETY: The implementation of `raw_get_list_links` only compile= s if the field has the // right type. - unsafe impl$(<$($implarg)*>)? $crate::list::HasSelfPtr<$item_type = $(, $id)?> for $self {} + unsafe impl$(<$($generics)*>)? $crate::list::HasSelfPtr<$item_type= $(, $id)?> for $self {} =20 - unsafe impl$(<$($implarg)*>)? $crate::list::HasListLinks$(<$id>)? = for $self { + unsafe impl$(<$($generics)*>)? $crate::list::HasListLinks$(<$id>)?= for $self { const OFFSET: usize =3D ::core::mem::offset_of!(Self, $field) = as usize; =20 #[inline] --=20 2.50.0 From nobody Tue Oct 7 12:25:21 2025 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D747242D7A; Wed, 9 Jul 2025 19:31:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752089481; cv=none; b=Bt1hpI4vctJL5+V2BXNaP6omZHFOiNcrfZU4pwfzeamwgVlw5THyNrwo0J16MsBk3dkrgLQVo3VVehmsOP0x21IGTh+C24JGd8IdHA9R+oOvAcxOdYZCRNOwKo7oi/TnFyL/ZRNuyoX5Pohldl8ub9hPM8qYEnBpqM39Vr5b4RU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752089481; c=relaxed/simple; bh=BzxsdrZ2gtJ7sd/WRv6JQx15k276m3sIML3wx+BFdbI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BNdp7NTIv4aJUR/W0IKvADRzMQdwcLdDwx+wESWckWp87njA5EY10UJ5EsdR2hfl/wBlxHSlJvjLBMFDRXN+rxmT8EHuGCe4HdcEzsv9lAnaxf7XotGt84NijbdIuJ0ZUNc2U+9BDqozGSoOf5OSmb6zV8MkoncGWhTE0WUAHEA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Hv1MUjq5; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Hv1MUjq5" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7d0a2220fb0so27166085a.3; Wed, 09 Jul 2025 12:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752089479; x=1752694279; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=IS3q5kNqrEANinnk2Dyg6SnvCsCPgNsMH+95sAwdenk=; b=Hv1MUjq5JgU+XsxXcwCUG/XqFGhTT2injKHJBN0GedBXefbzIVEKtrtwGfOIrcGfCU CvJqTIflH5xveXNkphe0z3TPQEBllxoCxo56m1/i7C9cza8R/c3EmyjlPUAScE1ebxs1 rdiHeK2pNUMCOOL17hvcOSQZk8VZuCQqOqAGSLYARqd/I06ZZr3lzPf9N1SJmr3oAMam gNAtZnfH26PTolJBnSXuA4FG4EUsN2KWepsGvjd5tFAa+xwX0drri/RlM6EcqgGyd2bg hu/QLs2sIb5rzt8UWE220yuAV2/bx9SnBra0GqskuyskX7gXEpxrOkxZaBmo2RaJxGLN Cxqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752089479; x=1752694279; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IS3q5kNqrEANinnk2Dyg6SnvCsCPgNsMH+95sAwdenk=; b=h0Vsm9ere8+tkvi0F34quvuyxg+EPKC3wS8x7NvdoGEHegkm3wTbvn7qSkXyvrqSR0 5HVqtrWTHRrdaCGUM62DlPfOZ/Du8UCG2QlIKatGTRHC0oAyejHsHlZ+rwZ1HMdi9tL7 b1cy9adsxm4kcfIhkkvwC/CD84XXNpIhSvNpWpPsAV32krH04N0FohW0ydNxKwjZTulB Vni6gLXz41tBzgi0P85cxQz9vbHuO0NWN5q81nAkolwCXGhsPFgSZYOJzal5Oc+JkPhQ RBVehfhr8D5Wu/HKmAnOGsYLzvqjDmueFUGhXKasmMCP4lNyZFVV4Vq+4Uf/AbJV0gd4 Hrmg== X-Forwarded-Encrypted: i=1; AJvYcCW7N15717QnlksVw/AflDkpNfT0xLMCZHtRnPRtgJGjCh+Ku7FCtphmZ+jLMzH/Q5kQDkUMIVFpHgGdNTo=@vger.kernel.org, AJvYcCWC6jo6cVcxvv7+iVkYWk3e1EQasexpJ9sKC62IGxBdf8RCE37Rq2IKZinp/TcUuc8vYDzjvhpW/oT8@vger.kernel.org X-Gm-Message-State: AOJu0Yx8l6UdNEl4CMLMD6bRG8yuAkU2lUdteR6wiytj4R2Tz0mFLgIY rN3S+aF89NkRv8P4jnJghBRwUHoOiykvmO6v++wJvF9fmylEpRkGymbfHv63fRFYwgJrDQ== X-Gm-Gg: ASbGnctCFMp3TWN28cyA+6pUyaPy3HdTvBTmKWlZJn10SbG03frBq8u+kKreSDoiS3Q ES+aY1VY0T8rDe+bH7FMNt7BVvDRRwyIqOvbl7/gXDbILFVtE+POxbUDVskfYrUBDW2UZhF9jNC v2PDZOU9rkKLJ3uI26b3a7MTQGyH/nSuKkUJ53X8C2u1OjDp+VrVvImVUt03/GNfb4MQKBwA3oQ HcmKXyeLxb5CYIzkDz1oR2vlus7dnhhPTi4qQeys4x3DdgdwYboW9t5hQyKd7s2Ruh/xK+N+pzu 4649AfZKYH1EnUQfEwjUWHK7iRuMxoTPfwHNg3PkmY3qVU64ODKJPlEc71pUNzoU98kW2kIF7O8 RYgcNzMB/Os/mcDmtWsjO+hr2xDMA0yBCsNetSaZLYJkU3XarlTdb80zuoHuPpPi/g1Zi X-Google-Smtp-Source: AGHT+IGdQOu4PjbwkS+xHnFLfgJqtktLatg01q6v02y434AbtH1/W3pF4tprIcB6Xw9wmMwdeuyThg== X-Received: by 2002:a05:620a:19a0:b0:7d0:a128:e30a with SMTP id af79cd13be357-7dcca01047emr789885a.2.1752089479142; Wed, 09 Jul 2025 12:31:19 -0700 (PDT) Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ([148.76.185.197]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7d5dbd94242sm991741285a.9.2025.07.09.12.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jul 2025 12:31:18 -0700 (PDT) From: Tamir Duberstein Date: Wed, 09 Jul 2025 15:31:13 -0400 Subject: [PATCH v4 3/6] rust: list: use consistent self parameter name Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250709-list-no-offset-v4-3-a429e75840a9@gmail.com> References: <20250709-list-no-offset-v4-0-a429e75840a9@gmail.com> In-Reply-To: <20250709-list-no-offset-v4-0-a429e75840a9@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Tamir Duberstein , Christian Schrefl X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openssh-sha256; t=1752089474; l=2223; i=tamird@gmail.com; h=from:subject:message-id; bh=BzxsdrZ2gtJ7sd/WRv6JQx15k276m3sIML3wx+BFdbI=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgtYz36g7iDMSkY5K7Ab51ksGX7hJgs MRt+XVZTrIzMVIAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QEcO9tFR42lIexUJhkTHQcbAYxc4+4L2TznqVFNnwwkLdXNMHlp9FM374PMMaSQ2uqTorxAwRTh wXzX6nJqdHgc= X-Developer-Key: i=tamird@gmail.com; a=openssh; fpr=SHA256:264rPmnnrb+ERkS7DDS3tuwqcJss/zevJRzoylqMsbc Refer to the self parameter of `impl_list_item!` by the same name used in `impl_has_list_links{,_self_ptr}!`. Reviewed-by: Christian Schrefl Tested-by: Alice Ryhl Reviewed-by: Alice Ryhl Signed-off-by: Tamir Duberstein --- rust/kernel/list/impl_list_item_mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rust/kernel/list/impl_list_item_mod.rs b/rust/kernel/list/impl= _list_item_mod.rs index 27feaf849c48..050299380330 100644 --- a/rust/kernel/list/impl_list_item_mod.rs +++ b/rust/kernel/list/impl_list_item_mod.rs @@ -114,12 +114,12 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut = $crate::list::ListLinks$(<$ #[macro_export] macro_rules! impl_list_item { ( - $(impl$({$($generics:tt)*})? ListItem<$num:tt> for $t:ty { + $(impl$({$($generics:tt)*})? ListItem<$num:tt> for $self:ty { using ListLinks; })* ) =3D> {$( // SAFETY: See GUARANTEES comment on each method. - unsafe impl$(<$($generics)*>)? $crate::list::ListItem<$num> for $t= { + unsafe impl$(<$($generics)*>)? $crate::list::ListItem<$num> for $s= elf { // GUARANTEES: // * This returns the same pointer as `prepare_to_insert` beca= use `prepare_to_insert` // is implemented in terms of `view_links`. @@ -178,12 +178,12 @@ unsafe fn post_remove(me: *mut $crate::list::ListLink= s<$num>) -> *const Self { )*}; =20 ( - $(impl$({$($generics:tt)*})? ListItem<$num:tt> for $t:ty { + $(impl$({$($generics:tt)*})? ListItem<$num:tt> for $self:ty { using ListLinksSelfPtr; })* ) =3D> {$( // SAFETY: See GUARANTEES comment on each method. - unsafe impl$(<$($generics)*>)? $crate::list::ListItem<$num> for $t= { + unsafe impl$(<$($generics)*>)? $crate::list::ListItem<$num> for $s= elf { // GUARANTEES: // This implementation of `ListItem` will not give out exclusi= ve access to the same // `ListLinks` several times because calls to `prepare_to_inse= rt` and `post_remove` --=20 2.50.0 From nobody Tue Oct 7 12:25:21 2025 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79215243378; Wed, 9 Jul 2025 19:31:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752089483; cv=none; b=kWeeEjtirHprdAjhYx+IY7EUHLc7AHGuRKl8lOZ+g/dX2r7e+aY34S9a2x5fAI2uN3JmXYTMb/Z5cJBnS/g11D7DndQ1q78Bsf4ZkoLhFQ+9ZabFuUGFcDO1eOH+R7ENua64fjpPy5AXaxvPLbOBpD1Neb1NSmM0g7cvMvnaRN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752089483; c=relaxed/simple; bh=+/OtAaGDpV4UJ40Bzj2NyhOOSjckTGuVHZjo7qrtKq8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T4aV2xllj6F5byij+yaJ8cxLQ0+XTwXrv7mPQH02AemnHWj/QVG7dO0UGltxGJKBrRcFxG0dvAchDQqm77IHEyM2mHiWZUPEX9/Sb7eri1wxYoqnPQGuXXpJHDcjjVWAYmzudXhhJa4A3FmlbXa7ucP2uGoWOwKb0aJNwdRfyYI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=P7DPBAw0; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P7DPBAw0" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-7d9f5bf544cso27295385a.0; Wed, 09 Jul 2025 12:31:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752089480; x=1752694280; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=cSaOrQSOQ/YLPFSVJBn7bVwB69tP2YNrYHZvxht3dSE=; b=P7DPBAw0NdmBSTAznIZP4mh59oUU1khhQ9QvZI1g8Onn6tEr1uo/OHii8O3D3hsGso UgvyiBn/kHidmM9RCuoUrV8wreMUreiC0R6J2fqnE2fsew061yFFiJQbBJTaU/gm18Cc /3trC8TuMLLQ78D4jGxPbtDtsyKUHwC+5XEzpaLZ7qapOnp9QY8CSA/R8q12mJSqQpqX 2coB6oDA6lKGikgctSQZeDGzITUPsWQJJGwYOKhVrz62LgVzLnz1YnmOANCa2QeEifQR 23RbQ0JQzznWHJEnK2mPcWk9VgKX46EBaoNXGEK3p6wi9rgrFeuZvN8qxD3GOReY3XDV 5sow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752089480; x=1752694280; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cSaOrQSOQ/YLPFSVJBn7bVwB69tP2YNrYHZvxht3dSE=; b=mfX2gkM7yBEpmhWakYF5++fuxDCxWnJSoPs/Me5stcFxnWvMpvtD+OkHo5rP+eoUr1 xLN/+tfyQ/8i1lpcT8kis7m/gzxLz04KjiGGCwT6sXnJoosoRPyFeFLsjyJf3Z06PElW qAwK0H7qWUHiy26lQGsgi0xoSmgx0rbxK3phn02EeYvAtzFKFV3NKNepIgrJVbNBuM+S xigcql3vVaa5FgcidcDjFVpHfJMVOFM2vAJA+fIenS/SgJOiC3yiJCZAh7hZEWhlh9a6 5yvVN0EFPXRH2nw7OT1NX9LgUqXNmcowTXoHqG3IMn2ADL1n+AwIwtCU9ga0V/f44KL8 Q7pw== X-Forwarded-Encrypted: i=1; AJvYcCWp5TNSWp0VSP8hqopoEMz8fdUNzIJpsIrSxw+DjekWD8KuB1ld0qCL/nyPqtgZYXfnfa8jVBM6eLrA@vger.kernel.org, AJvYcCXH38J9DvZ83IDNDx75Qn6vaGA/xkNyfYhhnvpJjJ546gqqjttFJAPNSf4sydgYw0wrOaLnh2E1kD2Jtv8=@vger.kernel.org X-Gm-Message-State: AOJu0Ywm1uylejgk4vzQOyZP+NpWYUR0pS/Z+ZaHDijDUY6ndeYPJOKL GVusoR6GZO/EWWv1FEJNdiOI0K7FPuVd+2SjJ57C/3raqlfagF/Robed X-Gm-Gg: ASbGncvawOp6vzsXJmB39uXI86DTo6tgYwWkexPe5DbzIiQZcmzy3u6A5RQ0+8WDgDU mcBuioQclz7OXRzVKAOsQeAu0PJNzS+2oYZ2T22K8eErab6KBkIb1SAQY5fkNDc8PhUhEkQpWg1 EzE6eLtGqSGPiPk2Y00v+NAn0ILFSY2hLWuTbXcJ5j8tqukXuC/DIXp+25CLlGtlITCA+8LkpNo ajxml91aGWdBBmzCQ8y4Ygu3xSY3bxMNPmeITIe7dchJU5K7dG7Roi7zVAmFtqcD4Hg4cqCmvIF 4MLLECkt5r4LlUOkClTUgAHSXHLBQUJrXY6x/TAleisuai2/xaPtGlRr/B+dHC5llWQ8CNRLbzc 6J0GAYwSZcJzERG6ylOQ0j8SnVYEa/S5A2boH1tKp65g5bdKSpAuuW8+Vcg== X-Google-Smtp-Source: AGHT+IHEh6B6b0eKQFJTeHG1DYBHbKPc/AHXwXbCtA8nW6xzzsDc0yIk20y6+7wgq3QIr4rrabDsZw== X-Received: by 2002:a05:620a:444b:b0:7ce:e010:88b9 with SMTP id af79cd13be357-7db7b80e1ddmr561496485a.13.1752089480235; Wed, 09 Jul 2025 12:31:20 -0700 (PDT) Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ([148.76.185.197]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7d5dbd94242sm991741285a.9.2025.07.09.12.31.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jul 2025 12:31:19 -0700 (PDT) From: Tamir Duberstein Date: Wed, 09 Jul 2025 15:31:14 -0400 Subject: [PATCH v4 4/6] rust: list: use fully qualified path Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250709-list-no-offset-v4-4-a429e75840a9@gmail.com> References: <20250709-list-no-offset-v4-0-a429e75840a9@gmail.com> In-Reply-To: <20250709-list-no-offset-v4-0-a429e75840a9@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openssh-sha256; t=1752089474; l=2377; i=tamird@gmail.com; h=from:subject:message-id; bh=+/OtAaGDpV4UJ40Bzj2NyhOOSjckTGuVHZjo7qrtKq8=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgtYz36g7iDMSkY5K7Ab51ksGX7hJgs MRt+XVZTrIzMVIAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QN2TNDZfV95jOttUvC0uhemNcK7YBmuSsjOaHsf7GMgdOkuAXnfs6E/15hO4ic87HkWNyMNmemw 0iIq3Q8/FMwg= X-Developer-Key: i=tamird@gmail.com; a=openssh; fpr=SHA256:264rPmnnrb+ERkS7DDS3tuwqcJss/zevJRzoylqMsbc Use a fully qualified path rooted at `$crate` rather than relying on imports in the invoking scope. Tested-by: Alice Ryhl Reviewed-by: Alice Ryhl Signed-off-by: Tamir Duberstein --- rust/kernel/list/impl_list_item_mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rust/kernel/list/impl_list_item_mod.rs b/rust/kernel/list/impl= _list_item_mod.rs index 050299380330..32087aee4c87 100644 --- a/rust/kernel/list/impl_list_item_mod.rs +++ b/rust/kernel/list/impl_list_item_mod.rs @@ -4,8 +4,6 @@ =20 //! Helpers for implementing list traits safely. =20 -use crate::list::ListLinks; - /// Declares that this type has a `ListLinks` field at a fixed offset. /// /// This trait is only used to help implement `ListItem` safely. If `ListI= tem` is implemented @@ -27,11 +25,11 @@ pub unsafe trait HasListLinks { /// /// The provided pointer must point at a valid struct of type `Self`. /// - /// [`ListLinks`]: ListLinks + /// [`ListLinks`]: crate::list::ListLinks // We don't really need this method, but it's necessary for the implem= entation of // `impl_has_list_links!` to be correct. #[inline] - unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut ListLinks { + unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut crate::list::List= Links { // SAFETY: The caller promises that the pointer is valid. The impl= ementer promises that the // `OFFSET` constant is correct. unsafe { ptr.cast::().add(Self::OFFSET).cast() } @@ -222,7 +220,9 @@ unsafe fn prepare_to_insert(me: *const Self) -> *mut $c= rate::list::ListLinks<$nu // this value is not in a list. unsafe fn view_links(me: *const Self) -> *mut $crate::list::Li= stLinks<$num> { // SAFETY: The caller promises that `me` points at a valid= value of type `Self`. - unsafe { >::raw_get_list_links(= me.cast_mut()) } + unsafe { + >::raw_get_li= st_links(me.cast_mut()) + } } =20 // This function is also used as the implementation of `post_r= emove`, so the caller --=20 2.50.0 From nobody Tue Oct 7 12:25:21 2025 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C412C2459F8; Wed, 9 Jul 2025 19:31:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752089484; cv=none; b=b+0IbpCMnw17erPt6P4suXZ27rI968rdZLxFT1XgqgOGER/CTi1gaWjJ2blY4fTrDXRH6IIIvMvMllAQPhu9RUo69nH9FKqZDgDD5l442vnIxXQOaVzO0Dyq8+4xgKyhlvAGD/he1RkKl5z0puGL4lHicVXFOXN6+cmaE7k3gA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752089484; c=relaxed/simple; bh=3DNAJWvLRtEJowZIvRUsC3Fczpnq2whgqr5slNeRHe8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Z+a/hAmAKTCCsT4qK0KW5cIZdQDCpy22x46JHFMSVdL7IJwQE+G5aVv5bu4j1QxH2e+pdltx87bBPr7JA3S/HuGFD1dpAEoTFXupnZ4lKwqTvANzXhGbzSvJb9OzDQk/syGA1k/ewH1HP5AQc/kWXq66oevNO41J3I3Yu4BVBtI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TCcTE6/R; arc=none smtp.client-ip=209.85.222.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TCcTE6/R" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7d5bf3300e0so24564485a.0; Wed, 09 Jul 2025 12:31:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752089482; x=1752694282; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=J8yQiVm26KnYiDPwr+Fn0NC/lRVqVNayR01QyLZe95Y=; b=TCcTE6/RhwQ7yObZzW2oYrHPG7WK6874HJp7MWsGFeNJ8lEpwZLtNEhqh+BNlYiz9q UdDUXRkmKoLboE1c81kuBkUsDwhr/oB+HupMTqmCoPgkdiIxsz4eXU8J6u8JiWSDx/BT Lx0OlY5deykKN1rb5DyJ4DLzFn9Dl+VQAuziVx8n84BXtdFQ06V93RUB6VKMFUPKEZxS iYmDtuQpaByFT/hNkKUk9o8R5lBsBZiR1A1OYtDBF25fbP/FCT+mJ8qvUK/9mPQmX3P1 VovHGZgWatNKti3FeV5eVg9H4JSmJwXxUME0NP9aNIeIMwcOwbmlXnkaLo0bdofW3yDq t1BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752089482; x=1752694282; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J8yQiVm26KnYiDPwr+Fn0NC/lRVqVNayR01QyLZe95Y=; b=A3S7Qbqjng5rvM2+wboNv+Em92kQ63NFwNiAgydgbkOyJQri2ARDTVCcAenuYqguVv miADe59nJ4MBX3ws93HdMkQKQtaZtGjLiA+Y4hVQOUo1Fw4FKrGr0fFj/xk5pt8ehGde JYPFUUjhKKLYVLP3QrbqEOZKXDfrz+OjICzkDgAXug2b5gs8D1SyD3FlXgW519TZuG3/ M7DFzHU6H8L5LEUWsSy5s2tGD9D5rmfiocBILFqmYqIzZCk1wu4hpjvxQTL5QgtFLeO4 ND9ByYKKarptnxErUqdfHd8F7KcFTSF29Pz9ercrh6fx0KWj4V2gpVFuHPlQJxzKhni+ duMg== X-Forwarded-Encrypted: i=1; AJvYcCXogc2DPHH0EZ6OS0c0fouEEmJhlyV7BckOJFiHlL85P/8Al6Ds+pYBBa19OL+3wJG5H5XA2wgi2HW4@vger.kernel.org, AJvYcCXxc8KWuZgc8ve4jyjsys/+mk7YjpzhH+WZ0wYKdamsZlB84Gida8YiQu87q265mOz2MQ0/W50k7uHN5Qk=@vger.kernel.org X-Gm-Message-State: AOJu0YwRpp/WIgrjFThFzhLyzZVlL2Rm3EaPXH1wvTqxQgyMEl4McCUp t9bfqk8kSUCtkeYL7qVIvfbcRBn07MP5Ku2gzci+QmL3SHbasf5VVoah+O7sk7xJVJ8= X-Gm-Gg: ASbGncvCtZzGZ+adK6p6TefwCJm803YKxcA+ueZV0SEfTOwwMmW1lEU5pG3wTJJy7Sl QSdORohF87oZ10pdl/3HvklBCcD2BgbIbhmKtCOstii0wKEnN46L7IzDOKO3/JUJKGolxvjvN1o WsdHHlasMs9J1XhQYaG1M1xER9TSBxMw8xySqF+gfdVzWt/Mv8y/hUEkuTForyIM9w9E0qZBZMv yRL7ChPsRsY9JBAZcKP0D287xB4AVTbniTPRJoSfRis5BiR8oqmNtaAhN6weDvfJkOtdO4cOiaC AkW08ZCAQm32TXDcvicFsXKysqz5+M/IdsuITdhmHf+flPyY4ivNqfQgYgJu/4BS06EA08IqvZ/ ssZ/oImTmaxKsvrlp+RsN5hDobXvSL9AIYpYU6OBCetvHrg7+kO9w4k0uQA== X-Google-Smtp-Source: AGHT+IHstsMLtpHJtmUeLaN3AyaPEQ9RkpBEHln6ZY+SMqs1MuqjLI0CBdNKRfIwAn8Gw5NogZG6Eg== X-Received: by 2002:a05:620a:a81c:b0:7dc:c315:a399 with SMTP id af79cd13be357-7dcc315ad52mr12561485a.46.1752089481346; Wed, 09 Jul 2025 12:31:21 -0700 (PDT) Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ([148.76.185.197]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7d5dbd94242sm991741285a.9.2025.07.09.12.31.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jul 2025 12:31:20 -0700 (PDT) From: Tamir Duberstein Date: Wed, 09 Jul 2025 15:31:15 -0400 Subject: [PATCH v4 5/6] rust: list: add `impl_list_item!` examples Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250709-list-no-offset-v4-5-a429e75840a9@gmail.com> References: <20250709-list-no-offset-v4-0-a429e75840a9@gmail.com> In-Reply-To: <20250709-list-no-offset-v4-0-a429e75840a9@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openssh-sha256; t=1752089474; l=4790; i=tamird@gmail.com; h=from:subject:message-id; bh=3DNAJWvLRtEJowZIvRUsC3Fczpnq2whgqr5slNeRHe8=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgtYz36g7iDMSkY5K7Ab51ksGX7hJgs MRt+XVZTrIzMVIAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QNp9mno1xwwB7+iVCKPc5wW+/gokOKXsP1KF6DjEXqwqfOhx6a5wQE+CUiGxj+K1mwUan2FJ5Gx UP+jDpst8gw4= X-Developer-Key: i=tamird@gmail.com; a=openssh; fpr=SHA256:264rPmnnrb+ERkS7DDS3tuwqcJss/zevJRzoylqMsbc There's a comprehensive example in `rust/kernel/list.rs` but it doesn't exercise the `using ListLinksSelfPtr` variant nor the generic cases. Add that here. Generalize `impl_has_list_links_self_ptr` to handle nested fields in the same manner as `impl_has_list_links`. Tested-by: Alice Ryhl Reviewed-by: Alice Ryhl Signed-off-by: Tamir Duberstein --- rust/kernel/list/impl_list_item_mod.rs | 96 ++++++++++++++++++++++++++++++= ++-- 1 file changed, 93 insertions(+), 3 deletions(-) diff --git a/rust/kernel/list/impl_list_item_mod.rs b/rust/kernel/list/impl= _list_item_mod.rs index 32087aee4c87..6b67c0ecc57b 100644 --- a/rust/kernel/list/impl_list_item_mod.rs +++ b/rust/kernel/list/impl_list_item_mod.rs @@ -82,20 +82,20 @@ macro_rules! impl_has_list_links_self_ptr { ($(impl$({$($generics:tt)*})? HasSelfPtr<$item_type:ty $(, $id:tt)?> for $self:ty - { self.$field:ident } + { self$(.$field:ident)* } )*) =3D> {$( // SAFETY: The implementation of `raw_get_list_links` only compile= s if the field has the // right type. unsafe impl$(<$($generics)*>)? $crate::list::HasSelfPtr<$item_type= $(, $id)?> for $self {} =20 unsafe impl$(<$($generics)*>)? $crate::list::HasListLinks$(<$id>)?= for $self { - const OFFSET: usize =3D ::core::mem::offset_of!(Self, $field) = as usize; + const OFFSET: usize =3D ::core::mem::offset_of!(Self, $($field= ).*) as usize; =20 #[inline] unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut $crate::l= ist::ListLinks$(<$id>)? { // SAFETY: The caller promises that the pointer is not dan= gling. let ptr: *mut $crate::list::ListLinksSelfPtr<$item_type $(= , $id)?> =3D - unsafe { ::core::ptr::addr_of_mut!((*ptr).$field) }; + unsafe { ::core::ptr::addr_of_mut!((*ptr)$(.$field)*) = }; ptr.cast() } } @@ -109,6 +109,96 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut $= crate::list::ListLinks$(<$ /// implement that trait. /// /// [`ListItem`]: crate::list::ListItem +/// +/// # Examples +/// +/// ``` +/// #[pin_data] +/// struct SimpleListItem { +/// value: u32, +/// #[pin] +/// links: kernel::list::ListLinks, +/// } +/// +/// kernel::list::impl_has_list_links! { +/// impl HasListLinks<0> for SimpleListItem { self.links } +/// } +/// +/// kernel::list::impl_list_arc_safe! { +/// impl ListArcSafe<0> for SimpleListItem { untracked; } +/// } +/// +/// kernel::list::impl_list_item! { +/// impl ListItem<0> for SimpleListItem { using ListLinks; } +/// } +/// +/// struct ListLinksHolder { +/// inner: kernel::list::ListLinks, +/// } +/// +/// #[pin_data] +/// struct ComplexListItem { +/// value: Result, +/// #[pin] +/// links: ListLinksHolder, +/// } +/// +/// kernel::list::impl_has_list_links! { +/// impl{T, U} HasListLinks<0> for ComplexListItem { self.links.= inner } +/// } +/// +/// kernel::list::impl_list_arc_safe! { +/// impl{T, U} ListArcSafe<0> for ComplexListItem { untracked; } +/// } +/// +/// kernel::list::impl_list_item! { +/// impl{T, U} ListItem<0> for ComplexListItem { using ListLinks= ; } +/// } +/// ``` +/// +/// ``` +/// #[pin_data] +/// struct SimpleListItem { +/// value: u32, +/// #[pin] +/// links: kernel::list::ListLinksSelfPtr, +/// } +/// +/// kernel::list::impl_list_arc_safe! { +/// impl ListArcSafe<0> for SimpleListItem { untracked; } +/// } +/// +/// kernel::list::impl_has_list_links_self_ptr! { +/// impl HasSelfPtr for SimpleListItem { self.links } +/// } +/// +/// kernel::list::impl_list_item! { +/// impl ListItem<0> for SimpleListItem { using ListLinksSelfPtr; } +/// } +/// +/// struct ListLinksSelfPtrHolder { +/// inner: kernel::list::ListLinksSelfPtr>, +/// } +/// +/// #[pin_data] +/// struct ComplexListItem { +/// value: Result, +/// #[pin] +/// links: ListLinksSelfPtrHolder, +/// } +/// +/// kernel::list::impl_list_arc_safe! { +/// impl{T, U} ListArcSafe<0> for ComplexListItem { untracked; } +/// } +/// +/// kernel::list::impl_has_list_links_self_ptr! { +/// impl{T, U} HasSelfPtr> for ComplexListItem { self.links.inner } +/// } +/// +/// kernel::list::impl_list_item! { +/// impl{T, U} ListItem<0> for ComplexListItem { using ListLinks= SelfPtr; } +/// } +/// ``` #[macro_export] macro_rules! impl_list_item { ( --=20 2.50.0 From nobody Tue Oct 7 12:25:21 2025 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16197248896; Wed, 9 Jul 2025 19:31:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752089486; cv=none; b=Fkm5md/2XUapcpKdC5Uf7weRnzWIpL6MrNckcTKCwY5hetTic1cr6fvCealN6YSxrxAlmK6dewAHruBD/8XAJKDrNEVc0LVVAWZxAJse3f6sFAFWxhs6tANhMpaqxShzRfkwaB9pWbIhv+v3e2oE8hzlfz64B86YGkACUbi+hdE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752089486; c=relaxed/simple; bh=5c0+Kp0dk2LV9AtGDQqctb3Y3HsxEO6S12AXZrnX7D0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dxXO6aN3JFmjqaymKlR5vqOeRJ21l2yvZK4Dh2MaEW3AnFeio+znBMqCX2QD53cAC7s6qKUjWlCTZBy2AYa9CaYmCKb5qWz+tP5xg9IJmqA5ErdxfuUsM5j1zSLswC8M8kjxSTEmfxgSc1+HKO3pXK8mgXl301E9MQUwmNuZlKY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lum6fhPP; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lum6fhPP" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7d0a0bcd3f3so34787385a.1; Wed, 09 Jul 2025 12:31:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752089483; x=1752694283; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=lPvvUtMn6FMSojwzOoVnq0sNVnnhaypantewDXL1/Uo=; b=lum6fhPP1VLD0cXTJLAZS5UpypbUeNebEQ1GjF0bVixGwkf8Ta+aNV0XL4D0WhzbEW 1XxlZ+uAMYY0NrCxWUq7bDla1KT87AkdBXonp7ka9JZtxkchccpX5vvKmgqjdV4/DWro cBjYgcA9yaw0i6zZ9TGGMHB+99EKmFtCw9K9uR5kdMMTFJokJIKwvZd6XTeNEjc8OWWy l/d/qZkeJPFOO0GpKI0AEKrzB/k3nVD/N+tntfutRgqaKnlBgriKo0UPIcDGfoj9voc7 DMpQGOUwhgpkAfyPmdT90QRZuT2u4o9tU+Ml6kbdxI0D3RA+TwE535R+pIY9mWXdHXXC KXsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752089483; x=1752694283; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lPvvUtMn6FMSojwzOoVnq0sNVnnhaypantewDXL1/Uo=; b=AlBtqVHdukJhc35QzHy4rRpbscb0IMgnPdBzpG/u7bWWmIIYWD48+w1n+/cx89+bHO 4bEvxfkDRwj/0HAJ38a2cSxrKwrfeZZw0HCYTpQcwMDTzIvqXgfTRT6c1cC1gIvcxLX+ nVxLwMeZlFHjWC9rtZ0BiFTgTVPx34XIVxClkBmh+rX8sYPoi40iotusibqkxH5ye1tq wsovljhX8wWriAHvmOSrawXBCJcYzKFX+A2zYOyS8o1ZvtYhwg0/2KBcI+TbWxq7RipV Lrtg17OVK7KmydOfQOfAsagIso9Trs1odTV8nsdldTxe519OwTLNsnJ+ts2CtuSF6OuF w5tQ== X-Forwarded-Encrypted: i=1; AJvYcCWG08YJrvVlVFyJ1GyNyq8tVWa2LDIYVKTP359jbr6Vn706MOHxkofv8vxo8/3NQJAFUxTqIkcDmtPZSD8=@vger.kernel.org, AJvYcCXc3p16UH4BtaKIz0T0nUQoFJfCSq1bDCAppz+3zP5uHCY93TTS4IVUVoLAI6tA/aXAGP+AJ9UpaSaU@vger.kernel.org X-Gm-Message-State: AOJu0YxsNtXyf6/tJfr6JZlzCukm84PO2FNn99eYBs5hZZqPJYwr9Rjr Uj9vZkDnZGEXMYE06nG9kzGPB4UPe300JkDj1qVqJK3Oo5v50GIMrPtg X-Gm-Gg: ASbGnctV0xJ2QIEExhC+6tKNXO8speeg2SSDNPrvp7pa5x63rkDY39eVES2kPsJky1t AO2QDwXUXMYCZXUEt6zaT6bWQi11dRHQeK6sIkaSYYZvBzdFlMxqXmT0R+SbOuCqP14/S3mcSxz JcDOwQ8mGHTbT55n0V3HqUEx56xp9yWel19hRtynn0iKfx3XXJI+fwo1UMmoT1sLxTprpOKxHtM 6ivIyCZGm7Wf7Tba8bd12Yzodr3HPcknkkwd5tYE0TjakpTTiVTlKIV9dLPgf3vJp+MmiiSNGNq DgsOF16oBIQJwOAaQo9B7qaLHYq4LuCYAyQI5eDp6i6edqN3haYjhv+N5i1wWNhlvscJNUV8z1b QYhARGeCorw7GXkJgDD76QPCN2udJKSyfGS0gAsLIpne8kiIlv/QavyBANw== X-Google-Smtp-Source: AGHT+IGuRaNDw30blY6z1T2xdHvb4jUkDGnjxBAjU3HaQ0bg5z/+uWL+1mHHJ2BvPgtOf6L2GtD7hQ== X-Received: by 2002:a05:620a:2a07:b0:7ce:b799:8eaf with SMTP id af79cd13be357-7dc990fb7ccmr120568785a.3.1752089482675; Wed, 09 Jul 2025 12:31:22 -0700 (PDT) Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ([148.76.185.197]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7d5dbd94242sm991741285a.9.2025.07.09.12.31.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jul 2025 12:31:22 -0700 (PDT) From: Tamir Duberstein Date: Wed, 09 Jul 2025 15:31:16 -0400 Subject: [PATCH v4 6/6] rust: list: remove OFFSET constants Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250709-list-no-offset-v4-6-a429e75840a9@gmail.com> References: <20250709-list-no-offset-v4-0-a429e75840a9@gmail.com> In-Reply-To: <20250709-list-no-offset-v4-0-a429e75840a9@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openssh-sha256; t=1752089474; l=18659; i=tamird@gmail.com; h=from:subject:message-id; bh=5c0+Kp0dk2LV9AtGDQqctb3Y3HsxEO6S12AXZrnX7D0=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgtYz36g7iDMSkY5K7Ab51ksGX7hJgs MRt+XVZTrIzMVIAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QK7RD2dEgJ+ubwbB/JeabE5GZ9ejahfntwf94x7Vhx+MdhnsicjZDzJI/YbPxd/fgDNktlV3+Pk nhzC8KXUaoQw= X-Developer-Key: i=tamird@gmail.com; a=openssh; fpr=SHA256:264rPmnnrb+ERkS7DDS3tuwqcJss/zevJRzoylqMsbc Replace `ListLinksSelfPtr::LIST_LINKS_SELF_PTR_OFFSET` with `unsafe fn raw_get_self_ptr` which returns a pointer to the field rather than requiring the caller to do pointer arithmetic. Implement `HasListLinks::raw_get_list_links` in `impl_has_list_links!`, narrowing the interface of `HasListLinks` and replacing pointer arithmetic with `container_of!`. Modify `impl_list_item` to also invoke `impl_has_list_links!` or `impl_has_list_links_self_ptr!`. This is necessary to allow `impl_list_item` to see more of the tokens used by `impl_has_list_links{,_self_ptr}!`. A similar API change was discussed on the hrtimer series[1]. Link: https://lore.kernel.org/all/20250224-hrtimer-v3-v6-12-rc2-v9-1-5bd3bf= 0ce6cc@kernel.org/ [1] Tested-by: Alice Ryhl Reviewed-by: Alice Ryhl Signed-off-by: Tamir Duberstein --- rust/kernel/list.rs | 23 +++--- rust/kernel/list/impl_list_item_mod.rs | 143 +++++++++++++++--------------= ---- 2 files changed, 79 insertions(+), 87 deletions(-) diff --git a/rust/kernel/list.rs b/rust/kernel/list.rs index fe58a3920e70..d976b31d1639 100644 --- a/rust/kernel/list.rs +++ b/rust/kernel/list.rs @@ -57,14 +57,11 @@ /// } /// } /// -/// impl_has_list_links! { -/// impl HasListLinks<0> for BasicItem { self.links } -/// } /// impl_list_arc_safe! { /// impl ListArcSafe<0> for BasicItem { untracked; } /// } /// impl_list_item! { -/// impl ListItem<0> for BasicItem { using ListLinks; } +/// impl ListItem<0> for BasicItem { using ListLinks { self.links }; } /// } /// /// // Create a new empty list. @@ -320,9 +317,6 @@ unsafe impl Send for L= istLinksSelfPtr {} unsafe impl Sync for ListLinksSelfPtr {} =20 impl ListLinksSelfPtr { - /// The offset from the [`ListLinks`] to the self pointer field. - pub const LIST_LINKS_SELF_PTR_OFFSET: usize =3D core::mem::offset_of!(= Self, self_ptr); - /// Creates a new initializer for this type. pub fn new() -> impl PinInit { // INVARIANT: Pin-init initializers can't be used on an existing `= Arc`, so this value will @@ -337,6 +331,16 @@ pub fn new() -> impl PinInit { self_ptr: Opaque::uninit(), } } + + /// Returns a pointer to the self pointer. + /// + /// # Safety + /// + /// The provided pointer must point at a valid struct of type `Self`. + pub unsafe fn raw_get_self_ptr(me: *const Self) -> *const Opaque<*cons= t T> { + // SAFETY: The caller promises that the pointer is valid. + unsafe { ptr::addr_of!((*me).self_ptr) } + } } =20 impl, const ID: u64> List { @@ -711,14 +715,11 @@ fn next(&mut self) -> Option> { /// } /// } /// -/// kernel::list::impl_has_list_links! { -/// impl HasListLinks<0> for ListItem { self.links } -/// } /// kernel::list::impl_list_arc_safe! { /// impl ListArcSafe<0> for ListItem { untracked; } /// } /// kernel::list::impl_list_item! { -/// impl ListItem<0> for ListItem { using ListLinks; } +/// impl ListItem<0> for ListItem { using ListLinks { self.links }; } /// } /// /// // Use a cursor to remove the first element with the given value. diff --git a/rust/kernel/list/impl_list_item_mod.rs b/rust/kernel/list/impl= _list_item_mod.rs index 6b67c0ecc57b..289101e0ab5e 100644 --- a/rust/kernel/list/impl_list_item_mod.rs +++ b/rust/kernel/list/impl_list_item_mod.rs @@ -4,21 +4,18 @@ =20 //! Helpers for implementing list traits safely. =20 -/// Declares that this type has a `ListLinks` field at a fixed offset. +/// Declares that this type has a [`ListLinks`] field. /// -/// This trait is only used to help implement `ListItem` safely. If `ListI= tem` is implemented +/// This trait is only used to help implement [`ListItem`] safely. If [`Li= stItem`] is implemented /// manually, then this trait is not needed. Use the [`impl_has_list_links= !`] macro to implement /// this trait. /// /// # Safety /// -/// All values of this type must have a `ListLinks` field at the given= offset. +/// The methods on this trait must have exactly the behavior that the defi= nitions given below have. /// -/// The behavior of `raw_get_list_links` must not be changed. +/// [`ListItem`]: crate::list::ListItem pub unsafe trait HasListLinks { - /// The offset of the `ListLinks` field. - const OFFSET: usize; - /// Returns a pointer to the [`ListLinks`] field. /// /// # Safety @@ -26,14 +23,7 @@ pub unsafe trait HasListLinks { /// The provided pointer must point at a valid struct of type `Self`. /// /// [`ListLinks`]: crate::list::ListLinks - // We don't really need this method, but it's necessary for the implem= entation of - // `impl_has_list_links!` to be correct. - #[inline] - unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut crate::list::List= Links { - // SAFETY: The caller promises that the pointer is valid. The impl= ementer promises that the - // `OFFSET` constant is correct. - unsafe { ptr.cast::().add(Self::OFFSET).cast() } - } + unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut crate::list::List= Links; } =20 /// Implements the [`HasListLinks`] trait for the given type. @@ -46,14 +36,15 @@ macro_rules! impl_has_list_links { )*) =3D> {$( // SAFETY: The implementation of `raw_get_list_links` only compile= s if the field has the // right type. - // - // The behavior of `raw_get_list_links` is not changed since the `= addr_of_mut!` macro is - // equivalent to the pointer offset operation in the trait definit= ion. unsafe impl$(<$($generics)*>)? $crate::list::HasListLinks$(<$id>)?= for $self { - const OFFSET: usize =3D ::core::mem::offset_of!(Self, $($field= ).*) as usize; - #[inline] unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut $crate::l= ist::ListLinks$(<$id>)? { + // Statically ensure that `$(.field)*` doesn't follow any = pointers. + // + // Cannot be `const` because `$self` may contain generics = and E0401 says constants + // "can't use {`Self`,generic parameters} from outer item". + if false { let _: usize =3D ::core::mem::offset_of!(Self, = $($field).*); } + // SAFETY: The caller promises that the pointer is not dan= gling. We know that this // expression doesn't follow any pointers, as the `offset_= of!` invocation above // would otherwise not compile. @@ -64,12 +55,15 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut $c= rate::list::ListLinks$(<$ } pub use impl_has_list_links; =20 -/// Declares that the `ListLinks` field in this struct is inside a `Li= stLinksSelfPtr`. +/// Declares that the [`ListLinks`] field in this struct is inside a +/// [`ListLinksSelfPtr`]. /// /// # Safety /// -/// The `ListLinks` field of this struct at the offset `HasListLinks::OFFSET` must be -/// inside a `ListLinksSelfPtr`. +/// The [`ListLinks`] field of this struct at [`HasListLinks::raw_= get_list_links`] must be +/// inside a [`ListLinksSelfPtr`]. +/// +/// [`ListLinksSelfPtr`]: crate::list::ListLinksSelfPtr pub unsafe trait HasSelfPtr where Self: HasListLinks, @@ -89,8 +83,6 @@ macro_rules! impl_has_list_links_self_ptr { unsafe impl$(<$($generics)*>)? $crate::list::HasSelfPtr<$item_type= $(, $id)?> for $self {} =20 unsafe impl$(<$($generics)*>)? $crate::list::HasListLinks$(<$id>)?= for $self { - const OFFSET: usize =3D ::core::mem::offset_of!(Self, $($field= ).*) as usize; - #[inline] unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut $crate::l= ist::ListLinks$(<$id>)? { // SAFETY: The caller promises that the pointer is not dan= gling. @@ -120,16 +112,12 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut = $crate::list::ListLinks$(<$ /// links: kernel::list::ListLinks, /// } /// -/// kernel::list::impl_has_list_links! { -/// impl HasListLinks<0> for SimpleListItem { self.links } -/// } -/// /// kernel::list::impl_list_arc_safe! { /// impl ListArcSafe<0> for SimpleListItem { untracked; } /// } /// /// kernel::list::impl_list_item! { -/// impl ListItem<0> for SimpleListItem { using ListLinks; } +/// impl ListItem<0> for SimpleListItem { using ListLinks { self.links= }; } /// } /// /// struct ListLinksHolder { @@ -143,16 +131,12 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut = $crate::list::ListLinks$(<$ /// links: ListLinksHolder, /// } /// -/// kernel::list::impl_has_list_links! { -/// impl{T, U} HasListLinks<0> for ComplexListItem { self.links.= inner } -/// } -/// /// kernel::list::impl_list_arc_safe! { /// impl{T, U} ListArcSafe<0> for ComplexListItem { untracked; } /// } /// /// kernel::list::impl_list_item! { -/// impl{T, U} ListItem<0> for ComplexListItem { using ListLinks= ; } +/// impl{T, U} ListItem<0> for ComplexListItem { using ListLinks= { self.links.inner }; } /// } /// ``` /// @@ -168,12 +152,8 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut $= crate::list::ListLinks$(<$ /// impl ListArcSafe<0> for SimpleListItem { untracked; } /// } /// -/// kernel::list::impl_has_list_links_self_ptr! { -/// impl HasSelfPtr for SimpleListItem { self.links } -/// } -/// /// kernel::list::impl_list_item! { -/// impl ListItem<0> for SimpleListItem { using ListLinksSelfPtr; } +/// impl ListItem<0> for SimpleListItem { using ListLinksSelfPtr { sel= f.links }; } /// } /// /// struct ListLinksSelfPtrHolder { @@ -191,21 +171,23 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut = $crate::list::ListLinks$(<$ /// impl{T, U} ListArcSafe<0> for ComplexListItem { untracked; } /// } /// -/// kernel::list::impl_has_list_links_self_ptr! { -/// impl{T, U} HasSelfPtr> for ComplexListItem { self.links.inner } -/// } -/// /// kernel::list::impl_list_item! { -/// impl{T, U} ListItem<0> for ComplexListItem { using ListLinks= SelfPtr; } +/// impl{T, U} ListItem<0> for ComplexListItem { +/// using ListLinksSelfPtr { self.links.inner }; +/// } /// } /// ``` #[macro_export] macro_rules! impl_list_item { ( $(impl$({$($generics:tt)*})? ListItem<$num:tt> for $self:ty { - using ListLinks; + using ListLinks { self$(.$field:ident)* }; })* ) =3D> {$( + $crate::list::impl_has_list_links! { + impl$({$($generics)*})? HasListLinks<$num> for $self { self$(.= $field)* } + } + // SAFETY: See GUARANTEES comment on each method. unsafe impl$(<$($generics)*>)? $crate::list::ListItem<$num> for $s= elf { // GUARANTEES: @@ -221,20 +203,19 @@ unsafe fn view_links(me: *const Self) -> *mut $crate:= :list::ListLinks<$num> { } =20 // GUARANTEES: - // * `me` originates from the most recent call to `prepare_to_= insert`, which just added - // `offset` to the pointer passed to `prepare_to_insert`. Th= is method subtracts - // `offset` from `me` so it returns the pointer originally p= assed to - // `prepare_to_insert`. + // * `me` originates from the most recent call to `prepare_to_= insert`, which calls + // `raw_get_list_link`, which is implemented using `addr_of_= mut!((*self)$(.$field)*)`. + // This method uses `container_of` to perform the inverse op= eration, so it returns the + // pointer originally passed to `prepare_to_insert`. // * The pointer remains valid until the next call to `post_re= move` because the caller // of the most recent call to `prepare_to_insert` promised t= o retain ownership of the // `ListArc` containing `Self` until the next call to `post_= remove`. The value cannot // be destroyed while a `ListArc` reference exists. unsafe fn view_value(me: *mut $crate::list::ListLinks<$num>) -= > *const Self { - let offset =3D >:= :OFFSET; // SAFETY: `me` originates from the most recent call to `p= repare_to_insert`, so it - // points at the field at offset `offset` in a value of ty= pe `Self`. Thus, - // subtracting `offset` from `me` is still in-bounds of th= e allocation. - unsafe { (me as *const u8).sub(offset) as *const Self } + // points at the field `$field` in a value of type `Self`.= Thus, reversing that + // operation is still in-bounds of the allocation. + $crate::container_of!(me, Self, $($field).*) } =20 // GUARANTEES: @@ -251,25 +232,28 @@ unsafe fn prepare_to_insert(me: *const Self) -> *mut = $crate::list::ListLinks<$nu } =20 // GUARANTEES: - // * `me` originates from the most recent call to `prepare_to_= insert`, which just added - // `offset` to the pointer passed to `prepare_to_insert`. Th= is method subtracts - // `offset` from `me` so it returns the pointer originally p= assed to - // `prepare_to_insert`. + // * `me` originates from the most recent call to `prepare_to_= insert`, which calls + // `raw_get_list_link`, which is implemented using `addr_of_= mut!((*self)$(.$field)*)`. + // This method uses `container_of` to perform the inverse op= eration, so it returns the + // pointer originally passed to `prepare_to_insert`. unsafe fn post_remove(me: *mut $crate::list::ListLinks<$num>) = -> *const Self { - let offset =3D >:= :OFFSET; // SAFETY: `me` originates from the most recent call to `p= repare_to_insert`, so it - // points at the field at offset `offset` in a value of ty= pe `Self`. Thus, - // subtracting `offset` from `me` is still in-bounds of th= e allocation. - unsafe { (me as *const u8).sub(offset) as *const Self } + // points at the field `$field` in a value of type `Self`.= Thus, reversing that + // operation is still in-bounds of the allocation. + $crate::container_of!(me, Self, $($field).*) } } )*}; =20 ( $(impl$({$($generics:tt)*})? ListItem<$num:tt> for $self:ty { - using ListLinksSelfPtr; + using ListLinksSelfPtr { self$(.$field:ident)* }; })* ) =3D> {$( + $crate::list::impl_has_list_links_self_ptr! { + impl$({$($generics)*})? HasSelfPtr<$self> for $self { self$(.$= field)* } + } + // SAFETY: See GUARANTEES comment on each method. unsafe impl$(<$($generics)*>)? $crate::list::ListItem<$num> for $s= elf { // GUARANTEES: @@ -284,13 +268,15 @@ unsafe fn prepare_to_insert(me: *const Self) -> *mut = $crate::list::ListLinks<$nu // SAFETY: The caller promises that `me` points at a valid= value of type `Self`. let links_field =3D unsafe { >::view_links(me) }; =20 - let spoff =3D $crate::list::ListLinksSelfPtr::= ::LIST_LINKS_SELF_PTR_OFFSET; - // Goes via the offset as the field is private. - // - // SAFETY: The constant is equal to `offset_of!(ListLinksS= elfPtr, self_ptr)`, so - // the pointer stays in bounds of the allocation. - let self_ptr =3D unsafe { (links_field as *const u8).add(s= poff) } - as *const $crate::types::Opaque<*const Self>; + let container =3D $crate::container_of!( + links_field, $crate::list::ListLinksSelfPtr, inner + ); + + // SAFETY: By the same reasoning above, `links_field` is a= valid pointer. + let self_ptr =3D unsafe { + $crate::list::ListLinksSelfPtr::raw_get_self_ptr(conta= iner) + }; + let cell_inner =3D $crate::types::Opaque::raw_get(self_ptr= ); =20 // SAFETY: This value is not accessed in any other places = than `prepare_to_insert`, @@ -331,12 +317,17 @@ unsafe fn view_links(me: *const Self) -> *mut $crate:= :list::ListLinks<$num> { // `ListArc` containing `Self` until the next call to `post_= remove`. The value cannot // be destroyed while a `ListArc` reference exists. unsafe fn view_value(links_field: *mut $crate::list::ListLinks= <$num>) -> *const Self { - let spoff =3D $crate::list::ListLinksSelfPtr::= ::LIST_LINKS_SELF_PTR_OFFSET; - // SAFETY: The constant is equal to `offset_of!(ListLinksS= elfPtr, self_ptr)`, so - // the pointer stays in bounds of the allocation. - let self_ptr =3D unsafe { (links_field as *const u8).add(s= poff) } - as *const ::core::cell::UnsafeCell<*const Self>; - let cell_inner =3D ::core::cell::UnsafeCell::raw_get(self_= ptr); + let container =3D $crate::container_of!( + links_field, $crate::list::ListLinksSelfPtr, inner + ); + + // SAFETY: By the same reasoning above, `links_field` is a= valid pointer. + let self_ptr =3D unsafe { + $crate::list::ListLinksSelfPtr::raw_get_self_ptr(conta= iner) + }; + + let cell_inner =3D $crate::types::Opaque::raw_get(self_ptr= ); + // SAFETY: This is not a data race, because the only funct= ion that writes to this // value is `prepare_to_insert`, but by the safety require= ments the // `prepare_to_insert` method may not be called in paralle= l with `view_value` or --=20 2.50.0