From patchwork Fri Apr 18 01:41:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056507 Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (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 AD267B676 for ; Fri, 18 Apr 2025 01:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940522; cv=none; b=p2cB94Jx1vFDZtcZBWdjMQYbLzhAA0E8fN9gQDsyVb+qVj8FzIe3aYhHQxjCn18hhCzYAnO58PHOpGWAiiFlhNVFV/N7sBdslcXsoBnl1WqbAxucQncP3RFxsFsCIOcZ1SMyMbaG4ZcRMJl/XWnxqDqHeK0AUqeralfW/ZCi6i0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940522; c=relaxed/simple; bh=kom6gDwOvQlLWIY64LaKg/88QJeZpSqlKMB0/S7dG0Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IA6365dOEoJxUDTcAqwi0XCToPOo7sqQzgHdNXE63QLasDczSXJVvagwvibLq/ZOCcWRhqg7Wli/t2jkEfETHuuVLGJ09SJeRE59PxF+V/Rlt5w88KmOoyUSL/DGT+24T7350QPzvKCSHeeqvi+FpH5rdTxqO8u5n1iKQ2UpkTo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=O3/7knAw; arc=none smtp.client-ip=209.85.128.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="O3/7knAw" Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-707561e5fdcso1197777b3.1 for ; Thu, 17 Apr 2025 18:42:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940519; x=1745545319; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8vZX6b4dOJQJVisyqBob3mx0+uYLldeHEIPiM/4owQ0=; b=O3/7knAweN67wPM4h5vOM9kmaVScSrD/GDJVfuqRJ/GfSzPFRbgbwoLVS6TO3u22I3 sAX7JbbcQb7PMdv7dbWLZuF1uoJNLTkCkGDENR3p/qa+//24xzUA71r2m0U3ghWZpgii tVAvgKVUUuQylQ1vCXCjHFcw/38VblmJovoCatcZk3RGpIhnoSvMHEwjaUeZZ+DXT1qN L358GdaQHHBqOS4xQCUBus3g4w/8/hZpUfQPw+5mnB8/pkdfI0SwQZDAVwQlZes0cinN O+n2vqfAPoLrJO1ouep19XuQPO/+85V3TZErPNpfz8A/agaMfYcEducpF0308sbbkKpK 7Xvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940519; x=1745545319; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8vZX6b4dOJQJVisyqBob3mx0+uYLldeHEIPiM/4owQ0=; b=aBt3aON87pmRjwUo1b73McFzkLqlQ/QlYWhwMyK6x1BWmbiy72EVhDb2uNYkYPrQmo zQY5vvobIoEdyPuI4E/jyMbOVKhwyxdscqpRv6F4XlXA62XUEAa9gv2btGFO/3lCt/qS g8eFhfmHtdVAa/ITqMXtKDHBhaGS6kWgHkoMFyaAMLZyDZNvUrscUvV8wpqqh64y1XG0 +f4KmTM0OaD4/3ruAbyOlq18wH6n2pp5Dh6q2GDPhZxgV+A5zUPEm1AOI7trB1qEOi6g mV7MRQB4RdrSXvZXo0JP/sE7nOS2Qa5QmnCFz1IhdwtsxuAl9IaBGHCXbBrOb6vRaNG2 d15w== X-Forwarded-Encrypted: i=1; AJvYcCU597YlbT90jNhVchbJEytv3zZ5M/fjbPtT/KAqUw0E4tewUveLRQ2GHjZduxPF1UgKRXBLoLPxW0oCwxfYuA==@vger.kernel.org X-Gm-Message-State: AOJu0YwDH9GMfkkIzWjSizygK0DXQUV2Zq5Ip8ZmKm7uy4+baCn2LTNW iCzrlQCjz6RHMELRb39W8xFC1T0atM3+hGJpOKi8psFy4yqfD6VcPCF5iYd9qXc= X-Gm-Gg: ASbGncv08A2/wDO9mmP55noI2wwNXgXUscvQeRRYJQX+Xmt+Q9LLFo5WPlRWgY0kFW6 1DiwKKYGPE+6hw2AxhMsJ7APB2GSiOeC4gM1brtGlT+TDHavpJwby1ch/kGZKrB+kqkotKdVxqR e5catGU6FSKkqTGK3eP5OmReGG0gVQl9Dzl7EXkSM5ASYjlKdEQDtKm5VZ2w21HPtyg8BwqeVPx sjMc6uVkgtfztxAS9RRgh26fw/mnD3OyqLQvJ6uh2GFWX5u8R1HOsUxAPQqLuRd1jOaCZVejVD3 yqYTYZ4fcOeaH2auQYNtd/66kmBbiYfpvo9INMa6nZ/6X4K19u+abPs1MwYd1ZxSNSBQn2IQ8mg Hig11nM7W/WM4tSNhQLXD53qFjaaFPRQAs7tdsv51R+NmyT4= X-Google-Smtp-Source: AGHT+IHKWD99S0F6KCgIeVvybd53+ijSAXdB3OgMVFyeT/tM2oA/5o0gqeKoz8LgS6Bcx3tB8BsaLg== X-Received: by 2002:a05:690c:3685:b0:6ff:1fac:c502 with SMTP id 00721157ae682-706ccce2277mr16272657b3.6.1744940519476; Thu, 17 Apr 2025 18:41:59 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.41.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:41:59 -0700 (PDT) From: Antonio Hickey To: Benno Lossin , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: Antonio Hickey , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 01/18] rust: init: refactor to use `&raw mut` Date: Thu, 17 Apr 2025 21:41:22 -0400 Message-ID: <20250418014143.888022-2-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replacing all occurrences of `addr_of_mut!(place)` with `&raw mut place`. This will allow us to reduce macro complexity, and improve consistency with existing reference syntax as `&raw mut` is similar to `&mut` making it fit more naturally with other existing code. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- rust/kernel/init.rs | 4 ++-- rust/pin-init/src/macros.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs index 8d228c237954..5646b1079776 100644 --- a/rust/kernel/init.rs +++ b/rust/kernel/init.rs @@ -69,7 +69,7 @@ //! ```rust,ignore //! # #![allow(unreachable_pub, clippy::disallowed_names)] //! use kernel::{prelude::*, types::Opaque}; -//! use core::{ptr::addr_of_mut, marker::PhantomPinned, pin::Pin}; +//! use core::{marker::PhantomPinned, pin::Pin}; //! # mod bindings { //! # #![allow(non_camel_case_types)] //! # pub struct foo; @@ -105,7 +105,7 @@ //! unsafe { //! pin_init::pin_init_from_closure(move |slot: *mut Self| { //! // `slot` contains uninit memory, avoid creating a reference. -//! let foo = addr_of_mut!((*slot).foo); +//! let foo = &raw mut (*slot).foo; //! //! // Initialize the `foo` //! bindings::init_foo(Opaque::raw_get(foo)); diff --git a/rust/pin-init/src/macros.rs b/rust/pin-init/src/macros.rs index 361623324d5c..28a91a1e1218 100644 --- a/rust/pin-init/src/macros.rs +++ b/rust/pin-init/src/macros.rs @@ -244,7 +244,7 @@ //! struct __InitOk; //! // This is the expansion of `t,`, which is syntactic sugar for `t: t,`. //! { -//! unsafe { ::core::ptr::write(::core::addr_of_mut!((*slot).t), t) }; +//! unsafe { ::core::ptr::write(&raw mut (*slot).t, t) }; //! } //! // Since initialization could fail later (not in this case, since the //! // error type is `Infallible`) we will need to drop this field if there @@ -258,7 +258,7 @@ //! // of the `unsafe` block, so we bind it here. //! { //! let x = 0; -//! unsafe { ::core::ptr::write(::core::addr_of_mut!((*slot).x), x) }; +//! unsafe { ::core::ptr::write(&raw mut (*slot).x, x) }; //! } //! // We again create a `DropGuard`. //! let __x_guard = unsafe { @@ -459,13 +459,13 @@ //! { //! struct __InitOk; //! { -//! unsafe { ::core::ptr::write(::core::addr_of_mut!((*slot).a), a) }; +//! unsafe { ::core::ptr::write(&raw mut (*slot).a, a) }; //! } //! let __a_guard = unsafe { //! ::pin_init::__internal::DropGuard::new(::core::addr_of_mut!((*slot).a)) //! }; //! let init = Bar::new(36); -//! unsafe { data.b(::core::addr_of_mut!((*slot).b), b)? }; +//! unsafe { data.b(&raw mut (*slot).b, b)? }; //! let __b_guard = unsafe { //! ::pin_init::__internal::DropGuard::new(::core::addr_of_mut!((*slot).b)) //! }; @@ -1215,7 +1215,7 @@ fn assert_zeroable(_: *mut T) {} // SAFETY: `slot` is valid, because we are inside of an initializer closure, we // return when an error/panic occurs. // We also use the `data` to require the correct trait (`Init` or `PinInit`) for `$field`. - unsafe { $data.$field(::core::ptr::addr_of_mut!((*$slot).$field), init)? }; + unsafe { $data.$field(&raw mut (*$slot).$field, init)? }; // Create the drop guard: // // We rely on macro hygiene to make it impossible for users to access this local variable. @@ -1277,7 +1277,7 @@ fn assert_zeroable(_: *mut T) {} // Initialize the field. // // SAFETY: The memory at `slot` is uninitialized. - unsafe { ::core::ptr::write(::core::ptr::addr_of_mut!((*$slot).$field), $field) }; + unsafe { ::core::ptr::write(&raw mut (*$slot).$field, $field) }; } // Create the drop guard: // From patchwork Fri Apr 18 01:41:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056508 Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com [209.85.128.170]) (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 C694B1DEFF5 for ; Fri, 18 Apr 2025 01:42:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940524; cv=none; b=cWmq4vIB2SjM765s0sPPOh69ds4RQeZkOSLc57806ILuqfjGny4L6gDnzDnXy8rx4lbqULHkOBlnPy2NF2FKMR8shQERc8OOtLvKpobL5jvFE1OW093MDji0S/6EJCyNgE61wfleHHE9+qHvEdeatITPjex76KL9O2M3zjpF2/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940524; c=relaxed/simple; bh=vFgDs7+ubz7RHPBpACVH6CG8tZkE7DjyOoCkhUi2Tfs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aOcEfbuTqgd3aHTroP95l+GxlbIglcS8gtFZ3b6zZBHFdGqdyQyoYA52r0gLpfZi9ACCRQeUgHao5Q90mXZz1JgeKDdPQoykuk1ubrSEB6LoMQeXFSwC6OAol2ZAbOyWWi7ezJNYRYogC60qFLA5RfEJmz9ZQKetrml4Wfk+b68= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=R3NHaDH3; arc=none smtp.client-ip=209.85.128.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="R3NHaDH3" Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-7023843e467so12890117b3.2 for ; Thu, 17 Apr 2025 18:42:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940522; x=1745545322; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RnG1j5y3hJrieF33Dur9awTBZJ3Ma29cUTD8J733xik=; b=R3NHaDH33b0+JR+5T5TlAwycWSnK9T+ql3OLHST/s5wlOrtBBJeIxbsR8yNEw+K69H zdW7BE1pQUa+tTzBv8KuwflLP8/8JMczn6bkWw/1G688/O7FP96TxgqJAZu5/NUDOxLZ vSqCgSywbchFrLP0O71Nj589iymmqhJZ9wxfh8NRrziXjMsrRO9bD+rsJyQJPAUd0sTv s3rtIdRSyWRH4dihPOb2EAnW0Yo8r2BrrTr7OrKmTUspnRwmIQ2RSe2vGMAEuNkjhR0m iTnknWuIcKCjHLEdk7rnimo6mUBWRnAElUmAaEZ3LTSQ4CYh10ogY6VFO6HjgTy/D84L bHGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940522; x=1745545322; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RnG1j5y3hJrieF33Dur9awTBZJ3Ma29cUTD8J733xik=; b=ri9KnMIX/CmQUyT9woroHcJapp00ZQoZQGwCCtmrAetzSrmomDodOCoiCVJj41DoLw RVDJs2DZSQ2H28v72kAG420WSae09Guou23jePg4yDx717KAnqEKm9ai2uS1UsWeW3pr dInIrBAPVkudKlUmrOTtkhofrZr5TI7x5lEFbgaXGm/E8L5o4UeIbhZqnaOZojneJLj3 E6SUBxEJrxhtS7C8ZpJWklhLzTptLm1OpWWMgjBop7U7b3KahmIiVsLGLII5Efh4JVUX qY6XjtDGJn4GEBR7Xw1hDAA0MKvWBCjSLphlmfYAieg6+AJ/hmdfOWY4CN2rk2Cqbgkv b0xw== X-Forwarded-Encrypted: i=1; AJvYcCUIDq6nGIv/EFhZ9Tn29QwfItGojxfU5oFmi6jKTZyJqcox4M8EjOMuTWS4lo/ma+yi9WB6DnWrkhEVWQqgzw==@vger.kernel.org X-Gm-Message-State: AOJu0YwBqk2M3yRtxZ3jaYQUmEYr/xs4R1QyL7jWhocNmzh1jEeUwPyO /o93h+2N1zEvFwfCfUccayY4/0+v0YGPYUVGAqk8NbKxJ4k+oQHo+vJ1J0DlQpY= X-Gm-Gg: ASbGncuiUrAXEe0fSfJb8dcIbR9EcBG5lNzunn3HsWCwRIFhBfcgVF8piVjjQA8R0lX Sz5cmjzfMOPijcJK5M8EDe49YNRdKvujcy8o8j6WlG6sl2SRfHFTjwmNSLFBkjP5ldctMz4AHQl PhDjgXlqqr+4Fr9cANB9XmPaoyo2j+6CGoF7WG0Q5JxDn6oGuvOijSAi9Sy9tTyTrUpUi2AzG2u +QzmWLhORNThB+Jb0Twf0urYHfo9FoZZNTGeRu/7jDu1vYL6FX0YyBIvyXQjSHVczHxj2Q5fDER zjz02AX1WBrtGcoYsuxYdTC1NfhiExor4BpP4vNLFUlVshmVNvJk8+DCae+CUWDZD/poBXnwAIH tDr8vd4IvIA4KM5DrkMkFbXLFeXzNX68128ng X-Google-Smtp-Source: AGHT+IEvz+Mx3jUJ1wl3eUSlKxVKhUGwA3+KtvBbpQ8vaWelRCzlqbErvqbmzGUkx/sOEFHgdujGPw== X-Received: by 2002:a05:690c:3392:b0:6fd:a226:fb50 with SMTP id 00721157ae682-706ccd001d8mr16549567b3.13.1744940521571; Thu, 17 Apr 2025 18:42:01 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:01 -0700 (PDT) From: Antonio Hickey To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?B?= =?utf-8?q?j=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: Antonio Hickey , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 02/18] rust: list: refactor to use `&raw [const|mut]` Date: Thu, 17 Apr 2025 21:41:23 -0400 Message-ID: <20250418014143.888022-3-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replacing all occurrences of `addr_of!(place)` and `addr_of_mut!(place)` with `&raw const place` and `&raw mut place` respectively. This will allow us to reduce macro complexity, and improve consistency with existing reference syntax as `&raw const`, `&raw mut` are similar to `&`, `&mut` making it fit more naturally with other existing code. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- rust/kernel/list.rs | 2 +- rust/kernel/list/impl_list_item_mod.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rust/kernel/list.rs b/rust/kernel/list.rs index a335c3b1ff5e..b1f504f6b809 100644 --- a/rust/kernel/list.rs +++ b/rust/kernel/list.rs @@ -176,7 +176,7 @@ pub fn new() -> impl PinInit { #[inline] unsafe fn fields(me: *mut Self) -> *mut ListLinksFields { // SAFETY: The caller promises that the pointer is valid. - unsafe { Opaque::raw_get(ptr::addr_of!((*me).inner)) } + unsafe { Opaque::raw_get(&raw const (*me).inner) } } /// # Safety diff --git a/rust/kernel/list/impl_list_item_mod.rs b/rust/kernel/list/impl_list_item_mod.rs index a0438537cee1..014b6713d59d 100644 --- a/rust/kernel/list/impl_list_item_mod.rs +++ b/rust/kernel/list/impl_list_item_mod.rs @@ -49,7 +49,7 @@ macro_rules! impl_has_list_links { // SAFETY: The implementation of `raw_get_list_links` only compiles if the field has the // right type. // - // The behavior of `raw_get_list_links` is not changed since the `addr_of_mut!` macro is + // The behavior of `raw_get_list_links` is not changed since the `&raw mut` op is // equivalent to the pointer offset operation in the trait definition. unsafe impl$(<$($implarg),*>)? $crate::list::HasListLinks$(<$id>)? for $self $(<$($selfarg),*>)? @@ -61,7 +61,7 @@ unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut $crate::list::ListLinks$(<$ // SAFETY: The caller promises that the pointer is not dangling. We know that this // expression doesn't follow any pointers, as the `offset_of!` invocation above // would otherwise not compile. - unsafe { ::core::ptr::addr_of_mut!((*ptr)$(.$field)*) } + unsafe { &raw mut (*ptr)$(.$field)* } } } )*}; @@ -103,7 +103,7 @@ macro_rules! impl_has_list_links_self_ptr { unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut $crate::list::ListLinks$(<$id>)? { // SAFETY: The caller promises that the pointer is not dangling. let ptr: *mut $crate::list::ListLinksSelfPtr<$item_type $(, $id)?> = - unsafe { ::core::ptr::addr_of_mut!((*ptr).$field) }; + unsafe { &raw mut (*ptr).$field }; ptr.cast() } } From patchwork Fri Apr 18 01:41:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056509 Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) (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 803B71E0B9C for ; Fri, 18 Apr 2025 01:42:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940527; cv=none; b=HkKBhUsaimqDa85VFWbam3p44bSA7ESGP0o8c1rG+IzQ3rZv8SfSqUQDDNHM4Dq1VOJ6Ry+SBV9sMf5n39YzxxkBSi+5v33S1yjQMj2xrXMuSwz7eBjr2rlxff8HTn024otcxQhDOazH3exfi6P7nPp3cxc+nPIgTUzg+KMWLmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940527; c=relaxed/simple; bh=iKnr6e8N56z9qXm9fEUldRgB1x8EQ77GX5xNtNprJqM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a7cgTk5wsJ9jLvBf8uO4D+scaCRklsLpuJTabISRHvla3fk2hTbVZF32IJcg17L2arV/sbOrpJ5VcozvreGPpxUSx4c3cqzP8ybGmcXtSd0fi6BPNVlXO/Z/x2TF9WbgQ9zKGdjV2fi0sGKegiu20XfZ0pDSIxaGA2KC3jh/U1k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=nnou6hUo; arc=none smtp.client-ip=209.85.128.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="nnou6hUo" Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-706cb438672so4577417b3.3 for ; Thu, 17 Apr 2025 18:42:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940524; x=1745545324; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SQWNy7W2o4yDQUOqT2/+qBcYzZtm3FQaQ3Z5pYP4aMw=; b=nnou6hUo0BzPOEUjTPP2e19bu3/uqAoX/73GSHa6FiBnvEGQH8gx5Px9Po/ZEhwo0S g9tdy/o1xHoR10RexTkKSpZqki2gWdZyqmltMhk/zBSBgPKqYFw1uXOlCrW/mDX1fa7k gucW/NyJvWyoU8JV5FBNQpnzjhVN4bciA40bWP8aRpCr/At8SV+7tL4AlBVQgs4Q+lKD 3y19Gm+9VKvelms8ltHtt/yPNr0jOQDVk70jmD6NLouKpyp9phPiqQ8jMLg9FiOcuKpN vBype8p8r9Eeb4AeI9H42j4OW/5uPAaP5hqPrpgFqSUlfDMJ3lhSNU/2uui8Yak1BRMT 4AWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940524; x=1745545324; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SQWNy7W2o4yDQUOqT2/+qBcYzZtm3FQaQ3Z5pYP4aMw=; b=qQALGHCkcD5oVuCpWVSSQ+qI2Q1bY5fymjtvZrqa8I9QmdyybR+cTBoOjZOY869Nmy IVK2NFUvH/VBqay3t6mhnhNLk9iI2eIAtRG5UOmE/Uxfhvjo8qxL/x30SJUZQ9wrSwEM 33WAhyu+nCUo4J+3lgOthFRH5KmuVmX9JCpdDEq2/Yh0+g7r9rwgwks2qGW5EXfHMOLo a9memkw76iXsHQMFNfoeawywKJh10X0S3k90bNcDYV4I2K6sfkm5JObkaMEA7HuNZFgW EluIWS54nU1xfOOE/pJilDQ/oe2XaKnbhaLf9bcnQ1Xt+KXE6mionK8yMi1jpyMnzSOa j4mg== X-Forwarded-Encrypted: i=1; AJvYcCUR5AePoRaGKHj4nt/H2oQHYHTOBcIXg9ULFoWXpP2auSpBQhCOgm4GavQ8Q8/kQ6alf8Yfn0/mMKb7/a5P7A==@vger.kernel.org X-Gm-Message-State: AOJu0YwBSVT41gjKy2fBTIQ1ON1tKqNKGgRvOKEEpT/34/ecGvEG3VDB YUqZ0bGFY9ZsFK/1ASBfsT77O3egaJIqXlYpLF2y23R/dl7Ys6v5QjKyLm3f1UZqaLJTq3TqaaW p X-Gm-Gg: ASbGnctGYYGtdR724iRBLgf6HvbLMbFrZTdc1MD2mi/Q91LwacJBeXE9G8Eivo8eGAF dFj6sJMmfUeJyaq7PWSwtck1/8OGoRr6TGHsmbS4rIZubyf+rgfHXxMJhlPQDP8JzZQ1Y2Y+WHt +s/P5vPDu3qJiVDuzBN8uJ/yTsV4zdnDecfJZuDHxrJ3gYy1KbLekvuYb9C0/X79PZnargMceRL PEoxD06BOEYrQ7U6/lEQWIKAyzPxUBQeSyyraimClA8+vnrbzzg1+fYv1UnsQKYAjfPrHzD0h6r 4szyqGFfOu+BuMtSrIKbkxxxPtbYEWWuo4o5WZGUpHqRxP6kKzV3v9cKWJ2fDNTINKlweQsBh52 sRnk9XgH7yPWFg1EuKkzfnnhNnB3M0adSPROcUKYAfDKjTQE= X-Google-Smtp-Source: AGHT+IF9KFMNEu6jpa97QayMti4TKcnPXsAq4MGAEYM4wdITHEEiEhaIFY7qZGhVB1Nqbo+5GqNr4Q== X-Received: by 2002:a05:690c:d07:b0:6f9:447d:d1a2 with SMTP id 00721157ae682-706ccdc6e66mr14828297b3.29.1744940524334; Thu, 17 Apr 2025 18:42:04 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:03 -0700 (PDT) From: Antonio Hickey To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?B?= =?utf-8?q?j=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: Antonio Hickey , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 03/18] rust: task: remove use of `addr_of!` macro Date: Thu, 17 Apr 2025 21:41:24 -0400 Message-ID: <20250418014143.888022-4-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The use of `addr_of!` here is unnecessary since its immediately dereferenced. The main benefit of `addr_of!` is to avoid intermediate field loads without immediate dereferencing, so there's no benefit in using it here. We can achieve the same behavior by directly accessing the `group_leader` and `pid` fields, which is more idiomatic. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- rust/kernel/task.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs index 9e6f6854948d..554b42c609af 100644 --- a/rust/kernel/task.rs +++ b/rust/kernel/task.rs @@ -259,7 +259,7 @@ pub fn as_ptr(&self) -> *mut bindings::task_struct { pub fn group_leader(&self) -> &Task { // SAFETY: The group leader of a task never changes after initialization, so reading this // field is not a data race. - let ptr = unsafe { *ptr::addr_of!((*self.as_ptr()).group_leader) }; + let ptr = unsafe { (*self.as_ptr()).group_leader }; // SAFETY: The lifetime of the returned task reference is tied to the lifetime of `self`, // and given that a task has a reference to its group leader, we know it must be valid for @@ -271,7 +271,7 @@ pub fn group_leader(&self) -> &Task { pub fn pid(&self) -> Pid { // SAFETY: The pid of a task never changes after initialization, so reading this field is // not a data race. - unsafe { *ptr::addr_of!((*self.as_ptr()).pid) } + unsafe { (*self.as_ptr()).pid } } /// Returns the UID of the given task. From patchwork Fri Apr 18 01:41:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056510 Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) (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 646F21E2848 for ; Fri, 18 Apr 2025 01:42:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940529; cv=none; b=pR0j3ezl+hf3lydCAzWReMGf89N2QTcDQbB3FtG8BGIFSMFkwwWwLWKiJbvxJnJwnTMxizDSe1X1wanjwAxLyf+a5GkudNgPkZ49/QPADxvCBjoe2RC1Pmh0+VvUhUyFALukGOBW3LiXt8pxvbP+gtYIifZHplUG5Jxcz/+fLSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940529; c=relaxed/simple; bh=lWyRs8EwRP9eKktqaEVV7KkDApnFrboXBIw2L8sIYQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SBA+g1vBVnG/Be9EKWpuldJaZkfZSE+RD0EgDP6ejRviph5dLQ7IRKDLJZ3WkDB6he9/7fY8Akq0nCijOdWdji6Xd7T5oE4W5nTrHmfDnLo/d0JIcAqtWwX4BYoJCcUt9aFf6E24hWZwLzr/o4mD6I+D3rS3CrqyECs2xINSa7E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=JXryRGpR; arc=none smtp.client-ip=209.85.128.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="JXryRGpR" Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-7054f0e933cso12537957b3.1 for ; Thu, 17 Apr 2025 18:42:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940527; x=1745545327; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TB1A7cvc79BaS5ylmvvIDJWYgvPRJC5rldZ4aqKNUrc=; b=JXryRGpRZwTZ0nASTeT4LAFvS863myXPM1IMrw4rtKYAPQQ3awSzGP9xhI5wrAY6bO C6FA4QAdsrbAFoJTHEu9sGE000bZy5s7yj347UdQjmaKQntVUMd7/rsxN4Sjf2eYlK3S j8pegQZhkUm1Fb5OLVmcPu0DsasWbybIKDXSdp6VdwXC57kGAnG5HObvtJR0L6GAYUZV udkezFrGEqLZoLup85diRXbZb+mrHzPgNqyDnPf8AZjaMS/JRxmehpp/WKRk90Ow95m2 kXu/DwVftIy5XvZ89qkIJuv7wovD6TIeEqXJ502iZXTJFHPaA674m2IB1SNmumP/WDt+ bFKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940527; x=1745545327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TB1A7cvc79BaS5ylmvvIDJWYgvPRJC5rldZ4aqKNUrc=; b=YNwBIZEX0YlIJPlj55Rh5NAuQXSvjRSTbRHvA4fAaVJuN1sbTQemOfQj2/33tmUsVS M9GAyBRODDigfGhKXNc7tR6zlWl/cATb6oLHddDjle+gZ/KKZECsQ1CNqsmKgFro1oAM H5NfQDLHtAPL4zb/OH0KGCW2pKyNFK0xHZc0+OhpDGQDoyNbZjXq1c0Ju/aFIJK02tBI ufVQjrhjk88HOGiXH6BUw0JxnCOR7TA4yN972qeBESPcCMNoV0+z6T0vykfCEhNj9fiU qIEsp4SP9OikNg3MVZGYby4uNJR4mjaaD2RVsqCzGS/xddXMYdxIwe3a2hKAtLOofq+M hgpw== X-Forwarded-Encrypted: i=1; AJvYcCWMFgSIQY23ODECn5rIrhq+QDQ6wkHk1sr/Q3J+UK4HI9Zdi1PHeGpXbhhyJKgd70PpnLlx17JQZLBXo8WUOw==@vger.kernel.org X-Gm-Message-State: AOJu0YyjWiduLyCF6wojgAQMSzhknis7woA0vedPd984U8EImu43/lBe 1m3EocVr/Qiwd+icbCU5ys+HhbyxQjoM7qu4giN7l6EFJhBUHvzL7hWN2gF3fvo= X-Gm-Gg: ASbGncu7tAPS2dpN8c9mBkL4vk06ZE6SAgsPtLSn7FmixPHh34n6bfrdFg12YAI8mvf /TN7kR9OYQRQk2f7ndi11K3yaQpGuiWAycz++pzQEm0XzHRGQXD7vqcq91od8SB855aLKSfjCBc mLgMQfsB5Ne/+rpge5ROwXfPBVLOSmpAp/TTv+C81CaXcqEpvfORaJpord1pJNUe+QkjnErUZoH 2BTUlsn8nJfnXYpCQ7ttpYIMO7jZB9+F42EGiX53Q5iviIqx8CV7yzyVtlTSYY+BoEcqAaa8DPg rzPtOKBv1v/YOR0h8d8bWGMtzyz01h2KRZp3LjpDV3davNXgjxpGvHiYn4DDZZEdswsr+3Row29 AwEkFiePG+JYF79yxqX5YIkaicpNzbSh9biDSGeqyNoU8uoM= X-Google-Smtp-Source: AGHT+IEaodFbCrH95m8gcG0KxdEwL1rgFoYJnXev+SHNVhhr9Pyu1iRSnvHrOJp3DTWsZlFfG6QnRQ== X-Received: by 2002:a05:690c:a99:b0:6f6:ca9a:e9da with SMTP id 00721157ae682-706ccc88d57mr13984697b3.4.1744940527326; Thu, 17 Apr 2025 18:42:07 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:07 -0700 (PDT) From: Antonio Hickey To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?B?= =?utf-8?q?j=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross Cc: Antonio Hickey , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 04/18] rust: faux: refactor to use `&raw mut` Date: Thu, 17 Apr 2025 21:41:25 -0400 Message-ID: <20250418014143.888022-5-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replacing all occurrences of `addr_of_mut!(place)` with `&raw mut place`. This will allow us to reduce macro complexity, and improve consistency with existing reference syntax as `&raw mut` is similar to `&mut` making it fit more naturally with other existing code. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- rust/kernel/faux.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/kernel/faux.rs b/rust/kernel/faux.rs index 8a50fcd4c9bb..064b4f60af4e 100644 --- a/rust/kernel/faux.rs +++ b/rust/kernel/faux.rs @@ -7,7 +7,7 @@ //! C header: [`include/linux/device/faux.h`] use crate::{bindings, device, error::code::*, prelude::*}; -use core::ptr::{addr_of_mut, null, null_mut, NonNull}; +use core::ptr::{null, null_mut, NonNull}; /// The registration of a faux device. /// @@ -54,7 +54,7 @@ impl AsRef for Registration { fn as_ref(&self) -> &device::Device { // SAFETY: The underlying `device` in `faux_device` is guaranteed by the C API to be // a valid initialized `device`. - unsafe { device::Device::as_ref(addr_of_mut!((*self.as_raw()).dev)) } + unsafe { device::Device::as_ref(&raw mut (*self.as_raw()).dev) } } } From patchwork Fri Apr 18 01:41:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056511 Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (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 58FA81DF72E for ; Fri, 18 Apr 2025 01:42:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940538; cv=none; b=IIxMUkLRNBEVFdxK4wOzcRUNYDZCTG3craXfe5tksKBDIMprRPSqDbqSv18MM2k9FOX8E2k/y/1WCz8M/ZlxZS0MItjmOnhisBrlMCESiLWCfbiqD99yygarg01D30//1p5OK+4/cH6C62Q+T+TbdNrQ+nL0Z3RdslSmbLTHry0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940538; c=relaxed/simple; bh=AsXerO6M3JJeGimaY8r23ZEYRge1XS9d6tD5VYo6WLQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TrnbsjCx/P/jwEyik3GGLe6hDBGA+c1TisT+Ub7dXKd6RAVi0PHOjLoEjTWBSk6waWc3UbHpzl1z+r3IPiQ9dJtBxnLynB9BH12IOUlxOuWl2ALSGjWNAhXuv74SzyjtxCIcj3GA6wcT/fnIQdltG+bqsBRBbzCfrG/XbQNsvVo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=tZHOk7Pz; arc=none smtp.client-ip=209.85.128.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="tZHOk7Pz" Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-700b17551cdso11837147b3.0 for ; Thu, 17 Apr 2025 18:42:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940535; x=1745545335; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3KVr9YoaGaQgWb5xariEP7OGZvSaNc2U9G9atBahdE8=; b=tZHOk7PzZ5hFQbMPVsYyOaQUAZ3JAJ1orsikVgKRG9OEAyR4jScQ7Yr4ElW5hRnL21 OmFOuol0VAqCdbX+Jh/8qGV1MR8S4q+xt5Bb46XcVYPolCbXYZEoXPr3vcyJzXci5ZKt XaYILBnoIimuWv1t21Cql7K6U6bLLLYpePG6ZIGqIPqaAE7KdCmTUs0aNWhyR+hGBD+h ibiSxKauIUoACs7eJ2BAOTUm+wvSY2mfS/pElIV6o2q7HOFO7QlrBy99M+4U4YvZODG9 bhn/m5/jbQ+CPBlhcKGIg4lFz2j4Oz3ITZujljPXixUGDSnnZJ/d8tvBySuCI5rPzrhM 3/wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940535; x=1745545335; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3KVr9YoaGaQgWb5xariEP7OGZvSaNc2U9G9atBahdE8=; b=QZraU3lT3if/u6iJAcQPVNLBWRYWSb3/63b1ApQGLAV4nKXeIeerXZjpISFhiMsnym p46mDhm6qgcj6cSA8XuLpvup7QPnCw6G8I4NWX4GnHgQeNLYFtl9MlnHkIfmu1qaQtPs tUNL4Q5W8mz3JDwsRnnz1waC7Y8gAU8gn3nnxu7n14wK5cXt4DyAwzT/5jbd0jhq7yUC Lnhlahjg2h+xysLtSH/Vr16SoZjMHUzQHSE13SPmECGxYiJUPw42tvDQFBvnI49SlDlF 91A0GqvqP0SmujUcL6Qm6xJe1kTwwQ746YT8p9aWJmDnvv1M/HrGHm5t3BJR8tExdd71 jQEA== X-Forwarded-Encrypted: i=1; AJvYcCU1M+OnkuWYLMEsmtCuWw0F9zOUt/V3LI+MCz73H86ljp5Ld++xPcIWCOck34m0CVEwNd+Xg1Drj4AdtsqBQw==@vger.kernel.org X-Gm-Message-State: AOJu0YxoBB7M4lsbvu+IH+jmGJ0VAGjsMqqQ0kzqkSZVrc+PEF+CWoop 1dSiGb3EuTO/u61i30CjkxPpV67+0oHwOzvm/BL7E5wPehhBuqC1FqKb1F87O24= X-Gm-Gg: ASbGncs1oh/gRlQ0a23GGaC4B7tkZ6LUDdggTWJSHjg2P4yO8N46H+pWP25+aOJrMMP Agk3pQ3HXHYp56CQEcJuoGfUEbSxpPuotiMK4gpGjdQnmBnVh/5idVpSUZMxk/vkhstjfF6BVuY mSnGbZB9b5/gvcCKdDLZ8dAR4rx5k0dKyPQVmaZaZANsuWmTZqiXTUg4/mlUaDVVHBe9QTXNeGs zQwIC6joLCHKUsjBSlywPPcUNX5nlwdmZvzRKhxyZHFT6i92x37EWb5gw2U7lNsqrC++8wCBwEX 2v/C2F1kmgNnd6FyOV//umJpLZl6wnX+oqgbWXydFsJObmWXJNRjs4lHBS8Iou7AqtvOcJqaonL KZSOim3Hyihb1QFaoV9bTtY0SLMqa6N1zFA4V X-Google-Smtp-Source: AGHT+IE/O6gWkQMozzU/sZ0vQ7iAMIJZ80Gw3gnlvoeuFzX09jFzx3stefvWq4XPYCQQb119QbF5Vg== X-Received: by 2002:a05:690c:670b:b0:6fb:9c08:4980 with SMTP id 00721157ae682-706cce0e007mr15660347b3.27.1744940535286; Thu, 17 Apr 2025 18:42:15 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:14 -0700 (PDT) From: Antonio Hickey To: Brendan Higgins , David Gow , Rae Moar , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?B?= =?utf-8?q?j=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: Antonio Hickey , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 05/18] rust: kunit: refactor to use `&raw [const|mut]` Date: Thu, 17 Apr 2025 21:41:26 -0400 Message-ID: <20250418014143.888022-6-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replacing all occurrences of `addr_of!(place)` and `addr_of_mut!(place)` with `&raw const place` and `&raw mut place` respectively. This will allow us to reduce macro complexity, and improve consistency with existing reference syntax as `&raw const`, `&raw mut` are similar to `&`, `&mut` making it fit more naturally with other existing code. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- rust/kernel/kunit.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rust/kernel/kunit.rs b/rust/kernel/kunit.rs index 1604fb6a5b1b..9f8165b15a37 100644 --- a/rust/kernel/kunit.rs +++ b/rust/kernel/kunit.rs @@ -130,9 +130,9 @@ unsafe impl Sync for UnaryAssert {} unsafe { $crate::bindings::__kunit_do_failed_assertion( kunit_test, - core::ptr::addr_of!(LOCATION.0), + &raw const LOCATION.0, $crate::bindings::kunit_assert_type_KUNIT_ASSERTION, - core::ptr::addr_of!(ASSERTION.0.assert), + &raw const ASSERTION.0.assert, Some($crate::bindings::kunit_unary_assert_format), core::ptr::null(), ); @@ -261,7 +261,7 @@ macro_rules! kunit_unsafe_test_suite { // (as documented) must be valid for the lifetime of // the suite (i.e., static). test_cases: unsafe { - ::core::ptr::addr_of_mut!($test_cases) + (&raw mut $test_cases) .cast::<::kernel::bindings::kunit_case>() }, suite_init: None, @@ -283,7 +283,7 @@ macro_rules! kunit_unsafe_test_suite { #[cfg_attr(not(target_os = "macos"), link_section = ".kunit_test_suites")] static mut KUNIT_TEST_SUITE_ENTRY: *const ::kernel::bindings::kunit_suite = // SAFETY: `KUNIT_TEST_SUITE` is static. - unsafe { ::core::ptr::addr_of_mut!(KUNIT_TEST_SUITE) }; + unsafe { &raw mut KUNIT_TEST_SUITE }; }; }; } From patchwork Fri Apr 18 01:41:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056512 Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) (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 D63991E7C2E for ; Fri, 18 Apr 2025 01:42:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940542; cv=none; b=cIWq5PhuN70qdnds9SgL/ddnEbrLyiOOon0t64glAPEesdhiHJAJvMQ8Ag6S/dvY+p6NWkW7IwqWCnQt522JOXONEtv4IwWz2k9xHtrKjgM8AGb2+zwHRUoV4CSp+wibdZPq/bFvZHNIlwh4sCIkf+w7XusjcP6kiLX6IhsDAWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940542; c=relaxed/simple; bh=cRxn5nlMFzHkKXcDkJd0zJyisFZEajZpHXhTkCsE0rA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=leFgS3Ju+PvQg5SU4G9ijcyScXXONL4c+9IGnIlNvCAbfwteypWHUt5MF9XZNUo2ZXk7OWsxpfPM/kQmwgxPWi3D6ITpvmG1lKNRsUNSMZ3EO0C77pgC4duDKWM/FMfkQE7ObTDdx6uFcbPnz0X1bVpqah1p9HZxENlUY0fjiNE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=nhM2J2bA; arc=none smtp.client-ip=209.85.128.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="nhM2J2bA" Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-700b17551cdso11837437b3.0 for ; Thu, 17 Apr 2025 18:42:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940540; x=1745545340; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ry3u1M0EzAmd70j1/Rem5lasv9JVJ9m5YCoAnIZljm8=; b=nhM2J2bA7OKDcTKjkfAB7hGccfY/JzallIBztTgHVggUuShq01aQlNKmOal8AkLzSo 4nqHPJtGq58ejsKt7gqk81IpAxY4e8R82f+MMOVhjcQWrH3lGfJcDD1EyYf+ZdMZS4A4 Zz6THuAmjOrygWpjv2TDVtyQBQsqbVMaBD5KkgGsWe/ydiS9ICkWwiHhHefde1wgfTYL YA4gr0EZ2Lfp5uFVLDWYNhsn/D6n8PQoMZhY1gA8M+3objzshu0w9tqsJO5FnGAOv911 IAv6lwrEL4zUSYb6/msZ8QgHYd4vCooR/LmVCVcXJVdW2Yk12UGT6eiRF0Sv6grFB9iE SZpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940540; x=1745545340; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ry3u1M0EzAmd70j1/Rem5lasv9JVJ9m5YCoAnIZljm8=; b=K1IHhXwZuwQuoiXIR9zBPF/9wCZjFdvuXMlbLuox+s4FZ42N580fE2Wq43Jecb7NgF lefKi1UDmhRNny8ga/mFc48yuIX02bWqpfFi0keRsMMygAGVizKWYbzc89iGMGSN2gV5 3JrRYaQCUomRVHsivLtY0rEXdDOX0Cw/KSBi0ciWc4HCV8YFbEJqo9OYkAH3nGOLkfia Vgchy2w0gQCYOpY6ajE0IoPQplTDcjEvg//9nu8N8s44IbVzmGmP8nvfl21KQJ5sBqwp Nh86nYHwk7A3aKniQDgO9FNbGUzSS3rq0c2ffKVSc5u21yBWzDFaBh75KJAcDoAjTeSe j8zw== X-Forwarded-Encrypted: i=1; AJvYcCX8N0NDDK1URjUcjRfuY0oVYKejDLkjIS22l8P1QL+nFRp2Drk4bpK4GwR43lTBO87e36BVYR3XI81ZQZIW5A==@vger.kernel.org X-Gm-Message-State: AOJu0YyOqPdAHMNnCXDnf7/O0h1bIbGFRWCneCEz6Stkm/3Bn+SY6h+V 7oJD6OPDq071nOsPp4qIYIQmcKevrVM2BXHZzcbHFatKXv1YDLm0WkWsfRv+8zI= X-Gm-Gg: ASbGncsnMMKnGEBatLfphsuY2jy08A1UhoBWktrTK+azqIkdJ/r08uIBwdCJdngOosk NsNF2UNHD6BmK5lyG3hjTW6yH2dkUYLHDQkDGnCdAzzjLGFnDp+FOLrbjVrvaMFVQFjvmOQtFRs /GPJTv2u8h9IDOq2prvia3Kg7S05nGWjTQmRLnHVnb3XUlGRD0MRp6/o/zO/tf9lYKAOkVvscxt yAoU1yzav50b63024Pdh5ulZUWQn6Kl8U6dVYAjsAV+yydFybsqPE4fPJK3Jz4qy/N8naGT3/lF lUawEXiTSAEb/3MsH0+X6Zh1Tx0+N9M1FXHSR5JfZc83aALjFX8vCsOFsr1hjH/+Mdjruh9DDQt 24c2H2WfG4puLn/UlnTy9R+cIennkc+ksNiO3hOmWpaSYUJw= X-Google-Smtp-Source: AGHT+IFrciPglYLYetltVBIt5I65E2xFh+XR+HtHWRbv1ZpAq0Bi5q1Yqh4U6lAfus6mr6hW3ATOcg== X-Received: by 2002:a05:690c:670b:b0:705:a95f:edaf with SMTP id 00721157ae682-706cce10357mr12594357b3.26.1744940539858; Thu, 17 Apr 2025 18:42:19 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:19 -0700 (PDT) From: Antonio Hickey To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?B?= =?utf-8?q?j=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: Antonio Hickey , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 06/18] rust: workqueue: refactor to use `&raw [const|mut]` Date: Thu, 17 Apr 2025 21:41:27 -0400 Message-ID: <20250418014143.888022-7-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replacing all occurrences of `addr_of!(place)` and `addr_of_mut!(place)` with `&raw const place` and `&raw mut place` respectively. This will allow us to reduce macro complexity, and improve consistency with existing reference syntax as `&raw const`, `&raw mut` are similar to `&`, `&mut` making it fit more naturally with other existing code. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- rust/kernel/workqueue.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs index f98bd02b838f..3a8e05ac6bd5 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -401,9 +401,10 @@ pub fn new(name: &'static CStr, key: Pin<&'static LockClassKey>) -> impl PinInit pub unsafe fn raw_get(ptr: *const Self) -> *mut bindings::work_struct { // SAFETY: The caller promises that the pointer is aligned and not dangling. // - // A pointer cast would also be ok due to `#[repr(transparent)]`. We use `addr_of!` so that - // the compiler does not complain that the `work` field is unused. - unsafe { Opaque::raw_get(core::ptr::addr_of!((*ptr).work)) } + // A pointer cast would also be ok due to `#[repr(transparent)]`. We use + // `&raw const (*ptr).work` so that the compiler does not complain that the + // `work` field is unused. + unsafe { Opaque::raw_get(&raw const (*ptr).work) } } } @@ -510,7 +511,7 @@ macro_rules! impl_has_work { unsafe fn raw_get_work(ptr: *mut Self) -> *mut $crate::workqueue::Work<$work_type $(, $id)?> { // SAFETY: The caller promises that the pointer is not dangling. unsafe { - ::core::ptr::addr_of_mut!((*ptr).$field) + &raw mut (*ptr).$field } } } From patchwork Fri Apr 18 01:41:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056513 Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (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 5D8471EF091 for ; Fri, 18 Apr 2025 01:42:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940544; cv=none; b=jn2vUAO01sId3iNnvwI3QBr3maey5wUISR4sfAmzm7u2iC7LFh1rq+SvgW6ZkS2jgoQXMx2xpbYNvcDCJ81bv/mneAQCqfXE2IgmrZwywBQoJ8JY/eSH4vZf9oH19xqhFF1RicmqJmztW94HHiDAU7oBSL0cUPOZcb1wHBuDKTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940544; c=relaxed/simple; bh=tMcIRwiOND2LkFh2ta+lL6MRxkp883Z5u7gsfs1JO5A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KVjzgRRkyGrC0T4uAQF0bX+mskj9Dd+3lxWpijQddHDSfLM2hLcTt6lMSnkLZQD/Z7TOyFVr0P/8aduK+8ayhHpXuvMn8g9XaG/to5wOqX7s+pC4O5p1re7UoIZDnFxTkhsdCuz8EZNnEd/goiVj9ExGsN0u/ziOaycfEDMZWN0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=Rv9a8fo0; arc=none smtp.client-ip=209.85.219.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="Rv9a8fo0" Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-e637edaa652so1199670276.1 for ; Thu, 17 Apr 2025 18:42:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940542; x=1745545342; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FhrJCHjOUAPpl8pOKLpx97O3fapOOv9377RmQCvweOo=; b=Rv9a8fo08tVACpRDd331s7f4rx32nZXqWJozG7lnl5bvwJYOZGn/6Z7eENfCA9a4Sl TIQ0PDPWBfdVbAzqvpMdTKH2SHQ5+d4rhaEoCxuI9k1TmSUIOCZ5FcocZpZ7Xv7EYqO7 u+p1oxBrabrycG30JQjFxCre4t1uwYR1vxC05ZRA4MrKw1u9SFr5tGlOzfyyVTmtqc7c anaLvbCH/8pOODLTc4Xbhdz1mvMCPFmoiTZq08v6H/jNs0AdSTI9qLP9P6iFxTvPUXmQ oJd+IMNCCZlqySZTBW6MFkPwD6Wbl2nWPZXOUunJIWkcXpIiLPziC0gb0mxolwENtCdf ADQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940542; x=1745545342; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FhrJCHjOUAPpl8pOKLpx97O3fapOOv9377RmQCvweOo=; b=PgdTxawYXJih4orNs+1+q94gFvhVsgppCw+v50q3qZKowZDMqZGOVmJUjObFP8oBd0 ot3RC1B9AJsjaGG9/o+p+kFpbDOwI2une2t1eXf4K55Ebx8C2BIdKMVCDepNBqXXFCuP IcJZU/kz/alsk8nG7zvTiy0mRdMZs5Z49S/FyKxHaFTJCcknZy10erP5Xy4MfYdISt9D 4mCUtn/mQCh7Hdz7Zw6nGIwod1Dkhi4BU2wCXHHnhIEdyEjnRXhLvs+oOzUwUhcAKlXW HeczVy3HiQSO1QmzcDnu/9Zv+Tvcks70axlS/wlSoIHjAkJd8aWSUS6nPVGkPmGcnjSA gcHw== X-Forwarded-Encrypted: i=1; AJvYcCX+Za4MjbRMYFs3iTSBNcyF9s4LF7MfVEr/Sy4RgyR76UWiPx+/Ro6zf9HXsCpnesGhzG/I6ew2M1rR9wspcA==@vger.kernel.org X-Gm-Message-State: AOJu0Yy3In9hc4pvbeqbtJYQOG59epAb30J9GSWixwBn85FyDfEt5eJu FbOP+P014rh5AZuEXceC3n2OA/esxuHGYDLMqE28G5xJgNdhxPw3HHaYl5mzl74= X-Gm-Gg: ASbGncvJsjrkx4W+qb+gYjKi+iKyDNfyq88tftXJDNL0s3F6QTAiYm2YIAugQe93OOa JZXLDatPWWT61wWMSW0Zd+x33m21IUGpLm0+9MRy1UGdd3zPaxqj96y6anHn4zkdUxnKbQq5lRe eUETsiPKN3HpDfsQ27DXpbSHeKY2dhVR02OmhTn6kn/GEMYkbIUNO/e/30oafwV5wR+gcqVnSjL jWC1Emo2aLT+vrA6+VdX23X3azyup3qyhzokGX7Pt3lzsQS2Ni1fWU0G9TDu6u9+wqCLjt48GyW NJ5bWuO5hqkXTNq0GAvdH4sV7u2XdNq/G/28zNMwPPcQbZVFH4cOeM1hlHZlMypFJpPbBiVlzCI ZfRKiqED5sQHOf+nhsbBbwu5RhyMCgGnQOQ1f X-Google-Smtp-Source: AGHT+IFJ7xF+dYjlJXmNKGmA+1knxcpHOEgB8ON1tlYplySG+tkiaUTxJnupU3OtBJxR+cTdYbbaqA== X-Received: by 2002:a05:6902:1b09:b0:e60:8a06:1ddd with SMTP id 3f1490d57ef6-e7297e9a9afmr1489461276.36.1744940542126; Thu, 17 Apr 2025 18:42:22 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:21 -0700 (PDT) From: Antonio Hickey To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?B?= =?utf-8?q?j=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: Antonio Hickey , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 07/18] rust: workqueue: replace `raw_get` with pointer cast Date: Thu, 17 Apr 2025 21:41:28 -0400 Message-ID: <20250418014143.888022-8-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that `Work` is initialized via `pin-init`, the `work` field is always used. This allows us to replace the use of unsafe `Opaque::raw_get` with direct pointer casting. Suggested-by: Boqun Feng Link: https://lore.kernel.org/all/20250316061429.817126-1-contact@antoniohickey.com/T/#mc7a4757e8c132f84228b728c7d123d73841501d6 Signed-off-by: Antonio Hickey --- rust/kernel/workqueue.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs index 3a8e05ac6bd5..c5f09b0682bb 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -399,12 +399,8 @@ pub fn new(name: &'static CStr, key: Pin<&'static LockClassKey>) -> impl PinInit /// need not be initialized.) #[inline] pub unsafe fn raw_get(ptr: *const Self) -> *mut bindings::work_struct { - // SAFETY: The caller promises that the pointer is aligned and not dangling. - // - // A pointer cast would also be ok due to `#[repr(transparent)]`. We use - // `&raw const (*ptr).work` so that the compiler does not complain that the - // `work` field is unused. - unsafe { Opaque::raw_get(&raw const (*ptr).work) } + // CAST: `Work` is transparent to `bindings::work_struct`. + ptr.cast_mut().cast() } } From patchwork Fri Apr 18 01:41:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056514 Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) (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 104BC1F8AD3 for ; Fri, 18 Apr 2025 01:42:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940547; cv=none; b=h8UTgBeXpRcK0FWFSpKyta/azrFZxmPDCEKr8G9m+Tg49r/HEnxo1Vua1THjSGWxrnfYLU/tTkAOfgMR8cxmjnLx3OFL4g4Cnk04n5FgINqEZ4iYaFwUSFPl1gn+K/na2gJQfGx3N6IaQ/Hlhu0I5CZg4hGHPh1fTYuD0IhXTNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940547; c=relaxed/simple; bh=ixPIHyOir8cPjkZjuNzSYJZCzjhxKzBneRBShXgOp7g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e5mkq9ob4+iQBJl5l4RvcoGpt9xWMhfAffrAgK8yxRB3DpdAVreKQ0QptjDLhC/YrjfiAVT7YiHGJEq3MlhwcmS8pRqQTdmY1ERYji0lmnh/z0PduSuepqR7bsXay2yAr7VcG/LSerC1B8/G7WKoh7vsz6FdtV1lgpUONagouGE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=lFfyUE45; arc=none smtp.client-ip=209.85.128.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="lFfyUE45" Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-6ff1e375a47so12312647b3.1 for ; Thu, 17 Apr 2025 18:42:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940544; x=1745545344; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mwxScseOQw1FlOZC8ZbLSlfG5B8Iqept6klH4FSUhoA=; b=lFfyUE45HqFgqwImf5FQWOUX9q38b9SGO142kRSgfq6sO5TF3K6oWPLyVIigKbNeHL 0pOQFQ/E359NJ5/obfKtvxKCaB4fHKBijZFJgL0z5WwPBE1Huov7DwyUB5IM05T3WCUr 6Hh1An52e/2+pCplVvZI97bHoFXbPgGe9wiKIKc9ZjtQuca4t9z7Z3Oc0vT3VXM6Rwda ayayQ9rPTZrBNhYuhLQsP09s6nEREcxardSO8lBkGo/eY8vJhcyCiA1zXjNcxMxPAA5q AqOD/Qyw+H2zDBxs6fV4ocNQO2DZAy207OaQgsGNScbqq32JrG8UvzbEulthNQF743EZ k9oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940544; x=1745545344; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mwxScseOQw1FlOZC8ZbLSlfG5B8Iqept6klH4FSUhoA=; b=xAeXfqplU+mengTQvMm2XZQCQ3dHjUSfvIIm3FK9c5YWZQHj/SBa1pzPTO+owCmSxH aE6xGe76Ik7p6YKSxLmbp/dvamLPFnGt93j64I3xGup5kgEOgOzr7U+iI//lPup/E5/e +5AcCVhZl5Ca5vU5zwimYvYwpnpYXBQJZ8Jx6OvBhOiMeeN0pEAjC0mHnDNju4AYy/cz FVeBGijYFMR8/h61+qFT7YcqNIVAF98GwqaW2kWEhmu/TIqVE1WyNOmJJV0dwxBvvyTR tMB9ehducPuqo10yNiCkC+FmX8nx1KCscDT4nukDFkAI8yaAR2HuAUFJYAhh79kUoZWe p54g== X-Forwarded-Encrypted: i=1; AJvYcCWRCmfpaYpC11ejiwYhduVUTkkB5hVFSjEMekHWGjzLwMwg5SBbzguYlx9HQ4GLqOGEp8ft12+Gz4CulrrFkw==@vger.kernel.org X-Gm-Message-State: AOJu0YyOhjRo4EaQgiJMVO8z5WMYUpSewAnyxbeg7emBi+W4jfXf0/EQ GYg6W4/VZKFmQZYqqtfxkTKruABaCldHWWrNaFEWDtRTtTjBj1z2QvxIlLevoI4= X-Gm-Gg: ASbGnctuslHFluDpzUoBiJ48clSymujJSj4/OoeldqpShFzSS93fu5YGBp1Y0/G8R8I ucUVo46N4J9Xzs79NrHOszZYq/nVhwGxwcS0KF/9Ed8jYIU5wrnszqnYdLsXsv155qq53/HmeDx Uw+xdZU1Ji/GQS3Kc75KdXpRgKNQPk3RtCFjMuYkrCvkem3OfAGf2Ef4ZZi5dFsgM/iAmh8nC0y Pud5gmvYNgcZwLVQauDXjvX5GCIVQ8wCjnnTVcmPx3QIZd9/y/UMSOrKYY3HjTj+CbULuZClsyK iwG/3j6fJeaFgb7zJQCR2ZLDJNoR4amYCpj9TVUJ1yOfQ3lGs3wxUD0+YIvoKGx83HGMhTzK1Jj rVU8XIAaDMFGKDU9D8EFGb2u6La3WkSz5oYxv X-Google-Smtp-Source: AGHT+IHwJejReAjzu7zp5ph/fNbSSOSO8a6C6bk5Grburt5rknFWefJSbxGkwUM9NLgxy5QvPNkyGg== X-Received: by 2002:a05:690c:9b0a:b0:702:5689:356e with SMTP id 00721157ae682-706cccfcef6mr16287377b3.12.1744940543891; Thu, 17 Apr 2025 18:42:23 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:23 -0700 (PDT) From: Antonio Hickey To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?B?= =?utf-8?q?j=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: Antonio Hickey , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 08/18] rust: rbtree: refactor to use `&raw mut` Date: Thu, 17 Apr 2025 21:41:29 -0400 Message-ID: <20250418014143.888022-9-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replacing all occurrences of `addr_of_mut!(place)` with `&raw mut place`. This will allow us to reduce macro complexity, and improve consistency with existing reference syntax as `&raw mut` is similar to `&mut` making it fit more naturally with other existing code. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- rust/kernel/rbtree.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/rust/kernel/rbtree.rs b/rust/kernel/rbtree.rs index 5246b2c8a4ff..04dbbeb8318d 100644 --- a/rust/kernel/rbtree.rs +++ b/rust/kernel/rbtree.rs @@ -11,7 +11,7 @@ cmp::{Ord, Ordering}, marker::PhantomData, mem::MaybeUninit, - ptr::{addr_of_mut, from_mut, NonNull}, + ptr::{from_mut, NonNull}, }; /// A red-black tree with owned nodes. @@ -238,7 +238,7 @@ pub fn values_mut(&mut self) -> impl Iterator { /// Returns a cursor over the tree nodes, starting with the smallest key. pub fn cursor_front(&mut self) -> Option> { - let root = addr_of_mut!(self.root); + let root = &raw mut self.root; // SAFETY: `self.root` is always a valid root node let current = unsafe { bindings::rb_first(root) }; NonNull::new(current).map(|current| { @@ -253,7 +253,7 @@ pub fn cursor_front(&mut self) -> Option> { /// Returns a cursor over the tree nodes, starting with the largest key. pub fn cursor_back(&mut self) -> Option> { - let root = addr_of_mut!(self.root); + let root = &raw mut self.root; // SAFETY: `self.root` is always a valid root node let current = unsafe { bindings::rb_last(root) }; NonNull::new(current).map(|current| { @@ -459,7 +459,7 @@ pub fn cursor_lower_bound(&mut self, key: &K) -> Option> let best = best_match?; // SAFETY: `best` is a non-null node so it is valid by the type invariants. - let links = unsafe { addr_of_mut!((*best.as_ptr()).links) }; + let links = unsafe { &raw mut (*best.as_ptr()).links }; NonNull::new(links).map(|current| { // INVARIANT: @@ -767,7 +767,7 @@ pub fn remove_current(self) -> (Option, RBTreeNode) { let node = RBTreeNode { node }; // SAFETY: The reference to the tree used to create the cursor outlives the cursor, so // the tree cannot change. By the tree invariant, all nodes are valid. - unsafe { bindings::rb_erase(&mut (*this).links, addr_of_mut!(self.tree.root)) }; + unsafe { bindings::rb_erase(&mut (*this).links, &raw mut self.tree.root) }; let current = match (prev, next) { (_, Some(next)) => next, @@ -803,7 +803,7 @@ fn remove_neighbor(&mut self, direction: Direction) -> Option> let neighbor = neighbor.as_ptr(); // SAFETY: The reference to the tree used to create the cursor outlives the cursor, so // the tree cannot change. By the tree invariant, all nodes are valid. - unsafe { bindings::rb_erase(neighbor, addr_of_mut!(self.tree.root)) }; + unsafe { bindings::rb_erase(neighbor, &raw mut self.tree.root) }; // SAFETY: By the type invariant of `Self`, all non-null `rb_node` pointers stored in `self` // point to the links field of `Node` objects. let this = unsafe { container_of!(neighbor, Node, links) }.cast_mut(); @@ -918,7 +918,7 @@ unsafe fn to_key_value_raw<'b>(node: NonNull) -> (&'b K, *mut let k = unsafe { &(*this).key }; // SAFETY: The passed `node` is the current node or a non-null neighbor, // thus `this` is valid by the type invariants. - let v = unsafe { addr_of_mut!((*this).value) }; + let v = unsafe { &raw mut (*this).value }; (k, v) } } @@ -1027,7 +1027,7 @@ fn next(&mut self) -> Option { self.next = unsafe { bindings::rb_next(self.next) }; // SAFETY: By the same reasoning above, it is safe to dereference the node. - Some(unsafe { (addr_of_mut!((*cur).key), addr_of_mut!((*cur).value)) }) + Some(unsafe { (&raw mut (*cur).key, &raw mut (*cur).value) }) } } @@ -1170,7 +1170,7 @@ fn insert(self, node: RBTreeNode) -> &'a mut V { // SAFETY: `node` is valid at least until we call `KBox::from_raw`, which only happens when // the node is removed or replaced. - let node_links = unsafe { addr_of_mut!((*node).links) }; + let node_links = unsafe { &raw mut (*node).links }; // INVARIANT: We are linking in a new node, which is valid. It remains valid because we // "forgot" it with `KBox::into_raw`. @@ -1178,7 +1178,7 @@ fn insert(self, node: RBTreeNode) -> &'a mut V { unsafe { bindings::rb_link_node(node_links, self.parent, self.child_field_of_parent) }; // SAFETY: All pointers are valid. `node` has just been inserted into the tree. - unsafe { bindings::rb_insert_color(node_links, addr_of_mut!((*self.rbtree).root)) }; + unsafe { bindings::rb_insert_color(node_links, &raw mut (*self.rbtree).root) }; // SAFETY: The node is valid until we remove it from the tree. unsafe { &mut (*node).value } @@ -1261,7 +1261,7 @@ fn replace(self, node: RBTreeNode) -> RBTreeNode { // SAFETY: `node` is valid at least until we call `KBox::from_raw`, which only happens when // the node is removed or replaced. - let new_node_links = unsafe { addr_of_mut!((*node).links) }; + let new_node_links = unsafe { &raw mut (*node).links }; // SAFETY: This updates the pointers so that `new_node_links` is in the tree where // `self.node_links` used to be. From patchwork Fri Apr 18 01:41:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056515 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) (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 A22CA202984 for ; Fri, 18 Apr 2025 01:42:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940548; cv=none; b=tTcFd+5gkvdNltiRz9mpakliVq7CG/QReCEjlGZFCqNibu7jjcacqu217lFNwxr5MdYyBKFoZAB8RQdCkDN1clh5SwWSJ2cXkz6mxjfqwMNGhRY8UTErJlsaI4lGWnT/lj2B5RVyqN9dXowbLY6S6/GIvvQ8OyMJSUkHdLXyGFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940548; c=relaxed/simple; bh=OjAsY8Aeq5Ueru5ZAiLzHF/EyHc73z1XNs7APpOHEWY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u2hhaAH22neGvlOjXbBYNB+kZIuWiT3A28JNVyU1miCXS/yst2ssY7h0tw6sJOkznlqhks+eKdxynkqJhESEtUXvsaAavTsC3B0LPSaQJD/7Zl8VRfMXNEp3YyqDn5z1Hq4AXspUAAgVhz3cs51lEzeRGx59zoqje+NMiwxs2Kk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=lNSpkuJR; arc=none smtp.client-ip=209.85.128.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="lNSpkuJR" Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-707561e5fdcso1200347b3.1 for ; Thu, 17 Apr 2025 18:42:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940545; x=1745545345; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ACdKqDtHD6BESg+aNrA5JEShMOuHrL3BKvU+zPowCQg=; b=lNSpkuJRc6Z1epKiGSFMcxIF8xXhS/B+f7Dys0qh7GDvBwCQGsJjhZt4hEBWq8DM0a sXMtpLSbG3mZOSk+MCA3kImFHJH1DFosBiqnY8F+T49Ba4gmTDRZKfmg2bk0FQy/rbYL 4NOjEdlPGklM0oANxSRewrDs1PyXlmC58ZPg2ypkDmFSIrxlhCNOF4a3Hf6K27tjqOIB YqvHl+i3zvtNYbrMof3RGMRC9Wo1fIAY541CKWh3j1C6F2W8cMbaSaK7SWvdZpgOwi/E s4jLvUmtNr2EuhIu+1raKQVZ1Pu5Y+e0sXdZAx/OQjGsFWYP7/nQVNlnWV7DzuU96iIR IZzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940545; x=1745545345; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ACdKqDtHD6BESg+aNrA5JEShMOuHrL3BKvU+zPowCQg=; b=Yt1XNKc0Qusy3yGt+dU2p4epn0fti3BdxCXx+CTwfkqcGO4caMDzdos3M7XmxZuSPg BpJ2H7okBOlQhc7ST91Rz2xp0gz99Dyv24KJhxpHGbwKNu2DmBp3R5nZfvKMLjdNDrOo De2ThaVXS504qh2BCY+bZU+UjwchKT7rUgoNjK67nnARFG7P3qcPN5dfX6mdfkwkY9sI 6UNCTZ93nz0hxbe6KOj5IyxXpztDUXcCPSMfF1UDFzbdNlCwCd4uPMGuR7dRyeejxFQZ 8In0OeB5aISHMwIVpDsFJ7UN74a6cQ6Szq434y6mBJ8ELrA1SRzkThSG8ZwU70cvMdkh w4Eg== X-Forwarded-Encrypted: i=1; AJvYcCWWSJPznH1Pf4WoqkaTrHcTMzb9Iqz7LHzbhp8BZHGwPdGlOTSAtTDjbKJmLgLoW6xwDue441lZdKp1rHgK8A==@vger.kernel.org X-Gm-Message-State: AOJu0YwyBfimlbaqKqZH1LwRA4CN0qbUv7apElgxHzQa2VRzQ0vMCP76 mxXAfZTA2ibYFialNROndk6GpY4gVzFEV1rjgFW6levLkLXhak7THMEimNIOEhc= X-Gm-Gg: ASbGncuEgVV0eo0Qt26jZw9rDVQn+wI5Q2HjF7cq/KTUNoJXw/exMj+Qim8C0vmR9AL kXTLZjoKLdb84HhTI+pOfNZij2U1eLr4KVVDtDTYGiG052GKpR9t08Pq8Er0KS+v8Os8iDp4bM/ dgKWYZVn0OMu2MiTNZy/0ACROz08V7Ahka+r6OKrXrJuxxyfpLWTFwm/NcgB5EuSQZpHGcyaOpL RFA2ujh/Gpl8nkKAQ8S7/6AgSaFq4kqGqZzDvFoAFHQVVYtYwvSoYABr3zRSf1xb5mquSQyzvYR Nh4TLo/TerTZB5/mtfUpj4RQJKTxqtHnUmNFWyaPDc8Wi/HqcX4Q/LxRY7QHlStcFRvAqhhQ3KN HBEdjPTcL7qBmJ3CdqEb8GCRdnqayx29vbkAw X-Google-Smtp-Source: AGHT+IFFnPj29gWWWt5rHJCynoVqA+g7Bu3K+6B674boBRW55BGIQRBULHvKIBq0w4As+NszEYgvdg== X-Received: by 2002:a05:690c:3609:b0:6fd:3ff9:ad96 with SMTP id 00721157ae682-706ce084512mr16517447b3.37.1744940545611; Thu, 17 Apr 2025 18:42:25 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:25 -0700 (PDT) From: Antonio Hickey To: FUJITA Tomonori , Trevor Gross , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Danilo Krummrich Cc: Antonio Hickey , netdev@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 09/18] rust: net: phy: refactor to use `&raw mut` Date: Thu, 17 Apr 2025 21:41:30 -0400 Message-ID: <20250418014143.888022-10-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replacing all occurrences of `addr_of_mut!(place)` with `&raw mut place`. This will allow us to reduce macro complexity, and improve consistency with existing reference syntax as `&raw mut` is similar to `&mut` making it fit more naturally with other existing code. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- rust/kernel/net/phy.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index a59469c785e3..757db052cc09 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -7,7 +7,7 @@ //! C headers: [`include/linux/phy.h`](srctree/include/linux/phy.h). use crate::{error::*, prelude::*, types::Opaque}; -use core::{marker::PhantomData, ptr::addr_of_mut}; +use core::marker::PhantomData; pub mod reg; @@ -285,7 +285,7 @@ impl AsRef for Device { fn as_ref(&self) -> &kernel::device::Device { let phydev = self.0.get(); // SAFETY: The struct invariant ensures that `mdio.dev` is valid. - unsafe { kernel::device::Device::as_ref(addr_of_mut!((*phydev).mdio.dev)) } + unsafe { kernel::device::Device::as_ref(&raw mut (*phydev).mdio.dev) } } } From patchwork Fri Apr 18 01:41:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056516 Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (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 6E7F5211474 for ; Fri, 18 Apr 2025 01:42:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940551; cv=none; b=bYJfSKvyNKaYbHhve02TJKyCqk0b4Znbs9L9B7+LkFQ/Vpb0Q0bP/cNnphcThSzIibViQ1zZRPjNl72KPKglQddiXUxmiq/+7Qcw3gSAcsDj3+DHVKUgWN/8V9ViIx8vhggag4d0pIvVhqbkzKYQPP8PIgEFOsRWSNOj4ux7+cY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940551; c=relaxed/simple; bh=rOW1RwC5UHmQ7UKODOM1ogomu8IEggHtksSWry6t9GU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TQwAnMjfWgqKqoLxZWyjXzhWQTXAWFQKX5AAuLmEmp2GjkZNq2Szyh90C7Javfj7FVmdBwe4/HAf6DYXOL/hh43/CDvQSPmzBg0A/zQnp85yXFbFLgox+Fn+S4hlVS05x+iaxPs5Py7XqWwz3kq1NVsBpMEEA672t63eBx+IGSs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=FucNCc8f; arc=none smtp.client-ip=209.85.128.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="FucNCc8f" Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-70576d2faa1so12196777b3.3 for ; Thu, 17 Apr 2025 18:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940549; x=1745545349; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5iSJCb3uqQGBFBpo+xzudBn2hvy1gDWxYIfh6IK0HAI=; b=FucNCc8fYETPkWOCB3I85YGn0njlaV7dEIhuUDIXOzcgBJhLKAcVSEWE3vJHcALbia 7Hok4SlfH9vHShnnjrtJz8BAbSFdpzeO1W2Wbbv7UYM8ycK05jDfLxES5jrwZMSxc8md QouJ2g3DeO19ZWnvb/9UiLRi8RzrKB+ilmabBYqlPQWS53i6SAAKYTVAA70jX6Iw08yp Ovv8wCMR/jDQvxvdQSMoNxHx5zH/+9GpBQijjuJiaqcpgOscZV7kWgy4onBY8VmuHHl6 niKyidMj3VDhsHzrUk/2lIzAaMrsBic2edk0fYOIlNRp/svxaYPrtVFbP7hwbRUpIb/O Ub1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940549; x=1745545349; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5iSJCb3uqQGBFBpo+xzudBn2hvy1gDWxYIfh6IK0HAI=; b=DVlJXZTPRmqxR+BAAo3OtS2+86lYOFEMosEMncYDrrQvSddHOangaBnV6J0+n0xIug ytfNpQOD9jUkGhLhp78pZcuwXEuXM/ncPGUKnlvx3sTAAaEwvao1i0tcBBk5kegbK+BS g3OirP0BvQZsP+gOOZNYnJtEnl0ffrs5kiBRUzzHFUpTH5DX8lO7BBYk9XFJMrK0cONi 5uX4DyzJs50WgnjLfeB2fE+BfFOxS6fNGBLgwh80LipO6FGFSiIuv3q3mASdE4fibe0S pyeChBCyzZ+eTZLUhs/wOBfjDOzShMnpWIVY5LxIGFrxGkB6vtwPW6ZosTGI8R8LAcVL aF+Q== X-Forwarded-Encrypted: i=1; AJvYcCUweJW4cz26oeftvsFPsPLB8UlzxZ/GIVrBf0i0//8+bttdYPciU1Il9l+1fk3Fu3qhylWtG+BV/qo9fp/E0A==@vger.kernel.org X-Gm-Message-State: AOJu0YzC6JET2g9wr/gUYrAhRK2UviB6mpx4UGLY1X0YDlC83Uo+XqQC ySs50MLu98AXOSMot2dxI2C3jgJlwNQxmn490JS7c4ByFjHSdMmkTcu7zxxgDz0= X-Gm-Gg: ASbGncvIU3Rd9lq8nhAglj0kdf9x8w29zMZRxRKT6/Qta3zgWE1C5ZTs/oTGyN8+jz0 m35fIc+WtqXLoV2LOa58VCAz+7k8+WS9K4BIVRigCGUHZzMn3nbrqd/TntdkXQJlWwgW6SWtjUq 5K2l/C1Oj57Z0D8JlZzlvRk2+cAHYeub/7Cdix2hJgFz8zUPTm4FKRTZBjiVWCAjARAAf4pusva AX5ypHLOwiDO2wtNKLmCe0AbHYueUylxyIkya8C5c+MLA3msAul2xnSd3Zq1IuRCqvZbvSpyOZY pq5plDosBB08eFjE8h+LNgwVJs2Z+/fP/bHgqgRL2SrebYyd/KbzFm2IwZjdVmy7KHliXZmaVLk DHAZcbWuQGCjib4r9dB2iqGm50glxLlwzwb7q X-Google-Smtp-Source: AGHT+IFmO8E0eAAldhUU8G3XlJp5JfFC/QaZWRxorj5hPt+AQzy684xlOEx47D7rkBQOVE84JmeuFQ== X-Received: by 2002:a05:690c:9a8a:b0:6fb:8461:e828 with SMTP id 00721157ae682-706ccddb140mr16306967b3.30.1744940549449; Thu, 17 Apr 2025 18:42:29 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:29 -0700 (PDT) From: Antonio Hickey To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?B?= =?utf-8?q?j=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: Antonio Hickey , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 10/18] rust: sync: arc: refactor to use `&raw const` Date: Thu, 17 Apr 2025 21:41:31 -0400 Message-ID: <20250418014143.888022-11-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replacing all occurrences of `addr_of!(place)` with `&raw const place`. This will allow us to reduce macro complexity, and improve consistency with existing reference syntax as `&raw const` is similar to `&` making it fit more naturally with other existing code. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- rust/kernel/sync/arc.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index 8484c814609a..fea85e5342a0 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -263,7 +263,7 @@ pub fn into_raw(self) -> *const T { let ptr = self.ptr.as_ptr(); core::mem::forget(self); // SAFETY: The pointer is valid. - unsafe { core::ptr::addr_of!((*ptr).data) } + unsafe { &raw const (*ptr).data } } /// Return a raw pointer to the data in this arc. @@ -272,7 +272,7 @@ pub fn as_ptr(this: &Self) -> *const T { // SAFETY: As `ptr` points to a valid allocation of type `ArcInner`, // field projection to `data`is within bounds of the allocation. - unsafe { core::ptr::addr_of!((*ptr).data) } + unsafe { &raw const (*ptr).data } } /// Recreates an [`Arc`] instance previously deconstructed via [`Arc::into_raw`]. From patchwork Fri Apr 18 01:41:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056517 Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (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 5D963211A21 for ; Fri, 18 Apr 2025 01:42:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940553; cv=none; b=ZSz1V9DwImmbwX9tFFG5m9AbLZ7bPj9yHSiu4nYDmosWd3virT5DtbYHrR+/iAW6zU15yYuUO1gZ+Q56nKNxaw8Wp4Am45yG+bcj8RdiWd+lpm+j6pVXvpplU9uYphPkX39zadCelGbstYoqvSoi1veaCokVmcGaZbuxKUmiGQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940553; c=relaxed/simple; bh=Ec59Z3Qvws1Qw9XaIFeOZjRAl6VPKpW0Y9E56g+uil4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NGl3s2bk29YoywfadmlEVITWzOv/zvJ/tmIzV/N/LHJoksI30taetUwxc+QZHry/eb2VrWPR73723BoqjZxcjFVIoyM1DoVm7Hq9qtcjaJVDTndKSKW41FIRpXxNoQ0Iinb4iX0ilDj16Uw2/+NSFtLGYqM2OlOkpq5f7Ah0tk0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=REGRrFor; arc=none smtp.client-ip=209.85.128.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="REGRrFor" Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-6f6ca9a3425so16009097b3.2 for ; Thu, 17 Apr 2025 18:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940551; x=1745545351; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6PjIvWcUxbUxFBC4KLvkRiaDLRPa3Rzcaxbmo9IqAl0=; b=REGRrForbY1zlaIrAlyp7EIPjVUoJ3IhcoOeAQAYnvuAGVz47HKs0FOYXEjXYlc7Hg ZGPUM/pFNQ0pHwCee91bxo6cNfYA/kfSkYXIPZ7g537yinXAnx3vZ4iHKlWniOl0Vp5s F1KOmJTAiwqHZwaGrXpb/nAVBwTTh5NUTMqHTLeUTAlaLYNHfKzutumK+4+QSypHkVTs 2UmhqbP0s5DxENB9KdiP8BfDozXh0s7vD7FvCxUi7eRBjO08U6y9FsbTBJUiX7g34Kvz sydiOtqsoOmCJY2JXIEDJ87mcHmV8g0eIMRT0zhG8zuFsldKDTImjd6F//tGR9e4ovXS z/bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940551; x=1745545351; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6PjIvWcUxbUxFBC4KLvkRiaDLRPa3Rzcaxbmo9IqAl0=; b=q+vcyXjtt+wGC3wEetb9f94rrbsCVRXU8jcGVzv8oKUybwjL0TCw7jgybomaNOvL+f 31w8OAgc2EHpMnbZSxe5OkKA9Hn/FYsCP+Yqk6NEQRgVT9krh/rIhqyYSGLZYPJoLWvv sZ6zeMx6rOwG3INNUulQP8+BWvd1mrgJ9xs2uIXUmssH2x9XqzpeGDrH2NP7q/Z4i7y+ MS2wrbHRkuC9tgtib8dwqCogddwHMNXjJob2nn4FzrfC8sjiaViDBC9uc7LNDJiryh2w w4I9L8ddKAdUPmEV+qWVHnRA2DJGHZY82SNZ0qXbpTnpRVIXO1uMNDu9A9jfm+W7vFDA 09lw== X-Forwarded-Encrypted: i=1; AJvYcCXRBzZ4VXNM570Gw7AglhaR/ZzzKqDtwH1Ju3Qy9IbCxj6R9sNb+YlRzZ6m6xEAY/pIbrjSJ3ge3nAXW4nICQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yw27xiiT/cTW3TUrP3i34d1CTh2nWWkSaqDOdVD4oNDZfp/7MO8 IZGwX/MQefRVx8NWJva3rTtPR/fatDe/kzj2R1uIEfCrwB0llDxcOM/al5NutKc= X-Gm-Gg: ASbGncujgPpXpKC00MkPSZKT/cibrCL98v04ttgdpI7YZL/zej1F4sZcql14YN4cPaJ FFmHeyBEP6oMErDRsjLFrS1B3cahci2/12wnrQz/kus/7c79l589RQY8IITIq3lmZ0L/+0GNTXZ EHi9ZjQszlRivT13Xx1W/tc7lgkVIJiS2pZOS+Nq8DGD6Jx8TT/nwfq4sfibSky7Xcl2Crwc7Xu XYzYeInPQWgxZ9SeiISk5hXfIrwX5QGHqPo6Vka9+LWCXtQKl0aaO4By+/N/rPtfzUIorumQcmA r9tEawF7ysmM9g8oTniQAMph5jnxCSDyU8S8PPERGXboJOdJs8ln5shkOGJJge7M7SSVwSYe0m0 YAPhBY3dv2udKuzFGcHujg/Y9Kog3w/HdgIlk X-Google-Smtp-Source: AGHT+IF1IDf4AANAXszAyHxGtAzkDD4UFqIlC4hdRXYFFZRS1Da/UnM1hupPQ/UawPvszZxTmtVOTw== X-Received: by 2002:a05:690c:64c6:b0:703:ad10:a729 with SMTP id 00721157ae682-706ccde3cf9mr14065487b3.28.1744940551265; Thu, 17 Apr 2025 18:42:31 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:30 -0700 (PDT) From: Antonio Hickey To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?B?= =?utf-8?q?j=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: Antonio Hickey , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 11/18] rust: jump_label: refactor to use `&raw const` Date: Thu, 17 Apr 2025 21:41:32 -0400 Message-ID: <20250418014143.888022-12-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replacing all occurrences of `addr_of!(place)` with `&raw const place`. This will allow us to reduce macro complexity, and improve consistency with existing reference syntax as `&raw const` is similar to `&` making it fit more naturally with other existing code. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- rust/kernel/jump_label.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/kernel/jump_label.rs b/rust/kernel/jump_label.rs index 4e974c768dbd..ca10abae0eee 100644 --- a/rust/kernel/jump_label.rs +++ b/rust/kernel/jump_label.rs @@ -20,8 +20,8 @@ #[macro_export] macro_rules! static_branch_unlikely { ($key:path, $keytyp:ty, $field:ident) => {{ - let _key: *const $keytyp = ::core::ptr::addr_of!($key); - let _key: *const $crate::bindings::static_key_false = ::core::ptr::addr_of!((*_key).$field); + let _key: *const $keytyp = &raw const $key; + let _key: *const $crate::bindings::static_key_false = &raw const (*_key).$field; let _key: *const $crate::bindings::static_key = _key.cast(); #[cfg(not(CONFIG_JUMP_LABEL))] From patchwork Fri Apr 18 01:41:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056518 Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (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 5310E2135B9 for ; Fri, 18 Apr 2025 01:42:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940555; cv=none; b=mqu+xN9qXepBy4kYVrJiReVRw5Q2KjUV3aNKg4/xVUzFotQX98bVnBBDzCLZlSf3u9fbU0LbPguLrKvA6spzxUaZpDLJfCXj7eE+Is2o4N+tfvjmoF8OQCeVnK/2D3EUYcDbdqNRGBhKlsCcp2d83LOL/NpvrH+p3mu0NOMc66Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940555; c=relaxed/simple; bh=wpYtq1z+RT5TLl2nVLPE3PEreLoCtFhLIYyj7HZ0L94=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AN0jAGJu/Ajpmb509pvXnPlp/yBcDUo2TZ5Vp0H0mFDl5P4eAIOWF59MCuEhPztjW/vLhG+G2vDFtNl7XVuHHu1nhgiChkBKk1VndA/jHy543rKH/wqy9JQ4puRe7CYbrcokPxJPG/BmMixs3XS75vFEdctaFmtsJIuUavdTs3Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=GC3oe/6b; arc=none smtp.client-ip=209.85.128.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="GC3oe/6b" Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-6ff37565232so12535147b3.3 for ; Thu, 17 Apr 2025 18:42:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940553; x=1745545353; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SpcLRGstQ17pweyurDBkde1oh39X2LM8n24QQtDlTk0=; b=GC3oe/6bFlQGD2Yvn2orB+6JYbOgKzbqs86FJ2nQfy43SeRZV02/6pYU2N8T6aA9Uo cMmv5x4oNPt+aKSIuvEeMoolUMeCLG/64Cks1SCHl3MI5lsVJBoV+hTKsZtu/9be575p qIYI28LeuBzRv0IrwY+Mqx96H22JcNZaISMMVKF7/kmpumkF30kAoHH1J8cQLsfPPNeP FAgdNW17hpA5AXNrYa0AE5WQ1fNsVPrzq79kWzYMpT97OGJNe8Ek+w6Iwxbsxcrc6hbO nuEyro9ypHR4wx1TGbkBbtP5wWLHCp4gGyxsKAx9FH+Rf+MHpxHY48hSRykbwVrveo44 sr3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940553; x=1745545353; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SpcLRGstQ17pweyurDBkde1oh39X2LM8n24QQtDlTk0=; b=IJrgsRPwcGSvbqUtBi265s1alUm/fFKnQaiegp+oa6zM0UwpQtq4+i6DsBLEclca4N aZ8Y6Q1hZZ7kU3wGFjMKCCJ7OusX1oKncRMSN1ccE76hcXcUHfZ1ZcSslcnwfqFFPN/L Q+K0daVCKNIAjgEvcaqbT/DrkSu+DkWnmvYW8UWvM1A5j7BjlOzUNW9wzg17Pi/JaOUs e6E+hTXFvOltMiikYN2OjjgFAR9KCR9Lm3AP9GLD8T2YnNpSzKBjjOQuQV1SFKLbSv1A IyC8iGAKo9rilTBsdLtR9DcHM8qwoytV+WfaRzZz133RvWNUx84vZu/lO/9QnB3dEVXe gJYQ== X-Forwarded-Encrypted: i=1; AJvYcCVMd+WDljCJMymdUx4GJrVxL+QJ3iOsHrOytC1KYTQO6fXFZg30UbipSxjEbDvmsG79W8UgUikaP3o8T6QfyQ==@vger.kernel.org X-Gm-Message-State: AOJu0YyMp97uirXzENRb2C04MiqQWjQVY8NnBV5Mxcmcn6LYWqNWaus9 OgQs+b9jT6Iq/eM5Ndt1puQHurpu2AZUYtJJLwd0Ejrt6wbaK7BszsaRCBoX1is= X-Gm-Gg: ASbGncsEp9AgrNF6+lzaVymZYkN1FhS40YbKP5873pYoAPa6LQqbbUljKQ5o9/RoysJ ud9qhuXFkSN3K1/k/ncGCc3lEwiv3PJLvvjaBpN39UqN2vYewfGzYP2Fq1IcSLIGvTK4sq+DrAE mwhogXNQjos6buWhfLwUc2I//RJfJPpqg3YvD74QdNMxbSB9gBMZcb2tC+0ZBvfHyIFKLxo5vRN q3yR2+g+3QCIfjX+kj/Lk/L/t9nUA2w8hKKpMLzOheppzKmUpLLpXtyVuJtFQaz6PWTzAZaTZSt c1NDxXdW+Zzi/KnBiee4K80MJ6TxxzgMH2WqmU3/LnnTrvwm6hNMcVmUVPRd57nujJ3Hm7JVH6F Jy8qT7W1Z337V6pSRipuVEwzJjhDdXqp02SSg X-Google-Smtp-Source: AGHT+IFU38DAD4VmAwz9QZTIHXxHp74s2uY2I8B+jjZ/AE+BjJgAp18iDLQM+1q2YlQXNsJdM2clww== X-Received: by 2002:a05:690c:6b83:b0:6f9:97f7:a5c4 with SMTP id 00721157ae682-706ccde345cmr14891917b3.29.1744940553169; Thu, 17 Apr 2025 18:42:33 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:32 -0700 (PDT) From: Antonio Hickey To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?B?= =?utf-8?q?j=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: Antonio Hickey , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 12/18] rust: fs: file: refactor to use `&raw const` Date: Thu, 17 Apr 2025 21:41:33 -0400 Message-ID: <20250418014143.888022-13-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replacing all occurrences of `addr_of!(place)` with `&raw const place`. This will allow us to reduce macro complexity, and improve consistency with existing reference syntax as `&raw const` is similar to `&` making it fit more naturally with other existing code. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- rust/kernel/fs/file.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/kernel/fs/file.rs b/rust/kernel/fs/file.rs index 13a0e44cd1aa..dc427613654e 100644 --- a/rust/kernel/fs/file.rs +++ b/rust/kernel/fs/file.rs @@ -331,7 +331,7 @@ pub fn flags(&self) -> u32 { // SAFETY: The file is valid because the shared reference guarantees a nonzero refcount. // // FIXME(read_once): Replace with `read_once` when available on the Rust side. - unsafe { core::ptr::addr_of!((*self.as_ptr()).f_flags).read_volatile() } + unsafe { (&raw const (*self.as_ptr()).f_flags).read_volatile() } } } From patchwork Fri Apr 18 01:41:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056519 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.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 3315021421F for ; Fri, 18 Apr 2025 01:42:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940560; cv=none; b=BxthdRpbZBodRHbotZ32BmPAvgstfvESdeGfL6T2Iqjv1sBW4PP6eeFxlsvW5sgZvQS3AAdc8RnRJGWUJhmay5jagz5IXuXlvsVZmQL/D7T6M0g0/6vbGgRmBzKtxjoZM1uMBuYQZjekM1fgpPXGLpyjeATqrUDaTQ3Zw8+h7gM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940560; c=relaxed/simple; bh=LFMQ+L94zjYiQUw6a1CKQk3d4BxJvPyZVxXJ/gsuLJs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BLPB5w/1MZPzYiki0hLB4gPrsg3U1WlFq6Oh96ypjfWolarVdkVDaLeRGrv6AE8skCQ3raZayeWKobTYlaEKRQhPKCmQN3QWQ+zPHmWxgn48hmPawmXCnqSMqxLjaZ4pyGRFIsQK8Whwmv+PSIjn/Xfa+D6sSadA3V6VwOTkgho= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=yoUtw0aZ; arc=none smtp.client-ip=209.85.128.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="yoUtw0aZ" Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-6ef60e500d7so12234347b3.0 for ; Thu, 17 Apr 2025 18:42:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940556; x=1745545356; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AI1pnhwmE+8xokIyOzrC/UhLGaF117Y++3PU7pcVmz4=; b=yoUtw0aZQGEeg6U++Ax2CrViqTr8jZpgAYzput8aUMEJfbj36UI4pvXkJabtDfCFmG CQSX5Nrf4Wktq4W/2IQz0x7JfJRvl923tBulRpnviphcLCXfv9JQB72MyVi4n0kwq4q7 SfqKWIsl8aqwo3R6MVR+MtJWDNxoojpaQwPHufBY8LZlivKv/+c3GjJK1g0aZn7zppJU e9hms0W7uKC6ZzDvtNYFK5YBG2sDJ9XYEZ3QAs364k/X7bd6LK/cs91RS/75/HEPv0Jv I9wcfa/vhBfDb/yf3qauHB3SjHApIusEapdkK6Yid6WeYcTgIGoP04CFfdqisC2YH3Vb HjQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940556; x=1745545356; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AI1pnhwmE+8xokIyOzrC/UhLGaF117Y++3PU7pcVmz4=; b=eTEXHdCbClNKCcKfYvjQDDG1QGQ5WjDkp8Qy8HK9wwiW/j2CxNdfP4P/1X7TPBnCmA ebIElz3DmeQcleHA46MfG9e49eXVMal5GOjMZwY/vAOqFXHeFbiZhjK6anMuoNMgHLB3 8ykEjG4SdvW87919hT3qLBM25l8OsXcFrDqymmSVJ+39fOiCNhcDv9dlkWiDxchKCc9y 1Zrz5hpsGvSJoRbsEY6Tv5/+/qaw2DMnY13+F+0npSW3JXpAKgwnbG3YHQPt7BUAZVJR z8D0WKyrIgveJvm+oK97hm80wzrkaPsspvGuQVkiuaP3oCXWNGPvyMmTrWHg19HGR7z3 5mUw== X-Forwarded-Encrypted: i=1; AJvYcCWKCUeiUhfjKVP+MzsOAB63VO/Cy7qP4aDENI0C87R48cAcHOSFrS8G5O+xFdgBDAivwzzzua4LqjC1U49iSw==@vger.kernel.org X-Gm-Message-State: AOJu0Ywud7ga23ZGP1zrfWq5KqGv4RgCgA5pAcBvOe8sGjGiA0yGQtN3 Q/mo6q5dVNBtb4VdvKvZCz83+NZwpaxYw1nd4Fig45K/lX+xquxL1YxBgf+Im3M= X-Gm-Gg: ASbGncvyu41hw11cjjkIlPa2Q/MHWSSLp3XpBr2c/qKKSbYd9MdInF5p/aXCi1jGa/W qwa+64rQS2s02jiNqlyKmX39nz6mk/MkK1Nk1HcLM/oNKZBAv+2T1NjOQx3mmjuo61eJT+pObS/ qDmXHyYB80N8k9cb//dtT0qMRrTyeUg5Amb1+qRcJR1CiZde2RWVF6wHv1tsbX8QazhINE3redO SoCHlILBiJVwwgOAcRsPLRafJGjiEiTQxHhfXRxg0FPvKSnnFCA2nYB33LdZCB4k8Wh+H1/RTEz 168/UMo6EK5Mowv658ZGJFCug0Md9zt5l9+tbsN+4I7N3iUFGFr1aftp5HccSvR3+QnfR4Xk4Gl v4OdP4R3TXi0jg6DOH7/HKBAV/+wIBmZqPKab X-Google-Smtp-Source: AGHT+IE5l+Ui/cDtgXp8hu7x1ECrYQ0A04JvbNLyVuB84n6vD9fpD7okMJpooYtF+P7zid0UiyG09Q== X-Received: by 2002:a05:690c:480c:b0:6ef:94db:b208 with SMTP id 00721157ae682-706ccde3c6cmr14428537b3.24.1744940556102; Thu, 17 Apr 2025 18:42:36 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:35 -0700 (PDT) From: Antonio Hickey To: Andreas Hindborg , Boqun Feng , Frederic Weisbecker , Lyude Paul , Thomas Gleixner , Anna-Maria Behnsen , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: Antonio Hickey , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 13/18] rust: time: hrtimer: refactor to use `&raw const` Date: Thu, 17 Apr 2025 21:41:34 -0400 Message-ID: <20250418014143.888022-14-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replacing all occurrences of `addr_of!(place)` with `&raw const place`. This will allow us to reduce macro complexity, and improve consistency with existing reference syntax as `&raw const` is similar to `&` making it fit more naturally with other existing code. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- rust/kernel/time/hrtimer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index ce53f8579d18..d91d2a655baf 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -132,7 +132,7 @@ unsafe fn raw_get(this: *const Self) -> *mut bindings::hrtimer { // SAFETY: The field projection to `timer` does not go out of bounds, // because the caller of this function promises that `this` points to an // allocation of at least the size of `Self`. - unsafe { Opaque::raw_get(core::ptr::addr_of!((*this).timer)) } + unsafe { Opaque::raw_get(&raw const (*this).timer) } } /// Cancel an initialized and potentially running timer. @@ -494,7 +494,7 @@ unsafe fn raw_get_timer( this: *const Self, ) -> *const $crate::time::hrtimer::HrTimer<$timer_type> { // SAFETY: The caller promises that the pointer is not dangling. - unsafe { ::core::ptr::addr_of!((*this).$field) } + unsafe { &raw const (*this).$field } } #[inline] From patchwork Fri Apr 18 01:41:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056520 Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.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 9ED072144B1 for ; Fri, 18 Apr 2025 01:42:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940561; cv=none; b=Kp8/YYJEyad1ePyYaGhl6yWbkDJ5R/uT65RyzGAPsrUO3fu3NWcvJ8HNVOKx9C1uar9VQgy0pQp4U+8mULyZyd8B90UOdEKD5P6N710eU9VomU07USoNx/U4/A/JBrVb0wQV4IMr4A1WWGMK0ia3sz1eLgg9QUmKz9BngV3clZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940561; c=relaxed/simple; bh=FyzfpjuzV37kb8DXdRAf2JVqbI26cGWJdP3ZB4YA9Uc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=haHYeGd49EFJeWTlgWRGyc7xhQjxHVBGNESxFvSbBZpTSvtyksgm1l+NH52ruxrTXdXohqrsxrxyQmVDwukPDX3W6UcXm2uAMWpkv4/5r3YNNGoOakTbwqiX6SZw5EfrYjR+Njvk7jpn627c8Hioy2T7vwzT4u/fxKKOONjW+aQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=wlT+Yzs5; arc=none smtp.client-ip=209.85.128.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="wlT+Yzs5" Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-6ef9b8b4f13so12461537b3.2 for ; Thu, 17 Apr 2025 18:42:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940558; x=1745545358; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/ypjYaS2bCdOwhFfUcatnP6T3YhESxrRRKhPIWxfjEY=; b=wlT+Yzs5oqxQ8z8ppn2k2kKpXKkVUTE/fiMNimu8ArT9FF1paMb6rQs6GYnIY92Efu w4PLktPsOWE3vAE9iTXy4mJj0IKi5HHmQWrcqqSKTPae4rW0XBII/+C2Syy+TnKqfsMV lv5pNERE3yRcyHnb5vxlSoLxNxzt08ZphhnW9noYNNELQcIohHlKgbw1xYzhvBIKY3L1 Yje7OpJyyJ8bXmu27au8AGTErtxnn02H2f1KHkSBWpD3s+o7P/frp+edLGSeoaH1pVoy SWXAptR6C7BeykAHCymK5tLbKvlko0vqJlWzLYrN/yki8I9Z9O6VVSXlh8PIrrm6hJhv uRpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940558; x=1745545358; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/ypjYaS2bCdOwhFfUcatnP6T3YhESxrRRKhPIWxfjEY=; b=NZ9a6V/BusEEisURirZ0CsTstldFBx8Fwcb3UkWCvD9Y2NmZBrp/001/TOstJZGrFj dhYsW76YWLT16dRzlTUVRjWtihxiqhtfGXfH3zURBvLBylmBf+jx2jXB9QHZZpm7akBy 602Rsfuh/+/EYDpeck8vIJ2Z2kMSZpeYwoW3KRD3e4uTm636STVh0aaHM9y829H1KQEC GmJosdHlVAEXevK4PobKSixZiFyMWqMxNcqKdRz4xpn2diErkIO0jm6JKOgI470b2KbX SA13ucGsSfd4vtGOc4pIObYWPtqQln1m2PTKqmuaLarydDkS/+9cZ6bWtcUd1cEVgZoF eh9A== X-Forwarded-Encrypted: i=1; AJvYcCXYFf7gR1kX7Z0du7OP6/JlmX73OlIqeqDx8rhCLg05Rh2SAZVY7HBpiAr+mgONHERuNx1K9FBtuWWX9xm2eA==@vger.kernel.org X-Gm-Message-State: AOJu0YzqnbKaDdV8WqygrliiYi/JLooRuJla4vs3B5D/W3I+6wZXuzU8 lXZ3HjRfoluM82u0kL8aMHmjLBISFnfNArfcZdO5mc3TxNg0U92dvjR707u92oA= X-Gm-Gg: ASbGnctW7iEp/re04DabjDx/Bf/ocZVMU0xPnhoooQxJ2HmYmP6hUp3dVQplVxbnb+A 2yLRzER4WjLM/vbYZqgl1fBCfuJ7/iAsOTXPlp2Q3G1woXj5dLhky9hO8Sd1NSriYpcSTnG/Ccx r2xsD/M7HOu9b5bOhwbh751ojovJeCKNh2EL2KNrXeCjEgRux2oaHXDOi4apRGUl5RuymL/r1pX pbiCvMo1oEsMFtHDxay5ywNCGkzCxJfAD5pLie5A6DzLfC4wYjKpX5H9+pFM38eEFJfFto56SQr 7IyYeB/zXNqhJ7PL3MuxMscabLuH+jyiyXay+X0oa2dRgfSpA5b9srAbYnqYpZIn0gwHXOKzAUJ n7VFIhR9xLCU/+qbjhdRU3zoK2U6fBPJYKGfs X-Google-Smtp-Source: AGHT+IEHJ+6Pf1f8ODH1sVykiKxg8GkjoeffCbwbuKrlLP91ZhaDAEvmG3W3nEPzfRzvLTxyNUCQWA== X-Received: by 2002:a05:690c:6a0f:b0:702:627e:a787 with SMTP id 00721157ae682-706cce2592amr16062067b3.29.1744940558537; Thu, 17 Apr 2025 18:42:38 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:38 -0700 (PDT) From: Antonio Hickey To: Bjorn Helgaas , 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 Cc: Antonio Hickey , linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 14/18] rust: pci: refactor to use `&raw mut` Date: Thu, 17 Apr 2025 21:41:35 -0400 Message-ID: <20250418014143.888022-15-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replacing all occurrences of `addr_of_mut!(place)` with `&raw mut place`. This will allow us to reduce macro complexity, and improve consistency with existing reference syntax as `&raw mut` is similar to `&mut` making it fit more naturally with other existing code. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- rust/kernel/pci.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index c97d6d470b28..4ad82f10a8b3 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -17,11 +17,7 @@ types::{ARef, ForeignOwnable, Opaque}, ThisModule, }; -use core::{ - marker::PhantomData, - ops::Deref, - ptr::{addr_of_mut, NonNull}, -}; +use core::{marker::PhantomData, ops::Deref, ptr::NonNull}; use kernel::prelude::*; /// An adapter for the registration of PCI drivers. @@ -459,7 +455,7 @@ impl AsRef for Device { fn as_ref(&self) -> &device::Device { // SAFETY: By the type invariant of `Self`, `self.as_raw()` is a pointer to a valid // `struct pci_dev`. - let dev = unsafe { addr_of_mut!((*self.as_raw()).dev) }; + let dev = unsafe { &raw mut (*self.as_raw()).dev }; // SAFETY: `dev` points to a valid `struct device`. unsafe { device::Device::as_ref(dev) } From patchwork Fri Apr 18 01:41:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056521 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) (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 F0E2B21480D for ; Fri, 18 Apr 2025 01:42:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940563; cv=none; b=kuqRbhQw5yY29NxMRe6651cuodEgMqXwTMnmzZVl7meOIxXkt8vE63vrdwJpdG0P3UA3UetU08v3h3X8QEyU+BlanGou+3o8hH6NB0XNG4w1kk5yrvJRiSSQlpGZrKPhq0AAImySYOjwkyaQOSzsVO/6ol0bDqkejPMCr7XXKlo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940563; c=relaxed/simple; bh=mxkonQb4LEedhuMKi5Pw7VG6wYzo4QhHEDDHw/ahhNw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X85AIlUcU5TL5jl/rWjliyIvSPROCqIO4U3/e5IijdMWNGuGXqYpnFIqmvPL9NPcJdOl2a50L+96Kj6c9tv8D7UtfV/E6eq9BtC9Cr3oeOqT2Xx2yEN6qiP2vTMpoPYIRwkgftXvXOKFO6zdJ9H4BYPCjTbQI3yIQX94ybeN4lg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=Dh2uUTPe; arc=none smtp.client-ip=209.85.128.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="Dh2uUTPe" Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-7054f0e933cso12540687b3.1 for ; Thu, 17 Apr 2025 18:42:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940561; x=1745545361; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wvrUONsdYqifW3LOJLRHijkTAOBVJ3SwPF5uqNxQa5I=; b=Dh2uUTPeR4b+Ip3vV//ROyObxAQndf0SN4auWgQ2vKL+56HdFtr0eUUjmPMrQKaM8P ahXwDWAPQ49NOmfg08xGVHl3vI8pgBzCkselgESvuL2EMH3QUCZFC4og9FF8Po8nDW9c byZFlyjDxHe2sgGnHnc4FFwesBopyt1+/gZ3vDoNorJziPh4oyOCb6iwAIWOeKqPB6CE +boYdE0CDOegH4BnI+GoU9kE9a7PvNx0mvUhGD+JA77vGtT2nUO136BbswE0yUNU2pP5 5Chzu0u0zwWn7cG0MunTi+Q6UadhAIuSXf/7OSIQY5T+2n/Bq6UNphPCrzn7mVILO5U+ wjlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940561; x=1745545361; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wvrUONsdYqifW3LOJLRHijkTAOBVJ3SwPF5uqNxQa5I=; b=Yk4/t8SWFcUEs/F/KFIuLDj4BOQaLsXDOit1kGizFQrEXfHqjPGWIiwiyjgAcihCrC 4GrTgiPfAiyqqaNOoYVSHKyBcJWZNk1du69ORCf75Dn8ShSNRhnG1rCVZlT4nnsXdhlG 0SFPLkEtbYnKFl8HEKx3xcFXmEp0tOawLa0wr9BPo7wjG7y45B2oBFda0A7iXu8c/2K5 6l6bcp8fVB2AdgZ+UdT1iWyLrUMDalVeN6dxry+yb3KIVXkTC3I9Wj18o/ISY8OXO5iK krcxR5tX+5RFcq9smzWdGDJyYGBnyAIqliSA51Lqi1+pubcl6RRnw442M41PquGcE8xf W32Q== X-Forwarded-Encrypted: i=1; AJvYcCVLifqMXARKZl84cr6YMZ/WZmgRkQDeQfQuN/wXotqCLZpP9gZl5bFep2BGpDwnkJaNQgonRzK5m7zWYmmEaA==@vger.kernel.org X-Gm-Message-State: AOJu0Yw3oErNxjGBVVZFZjSohEhXAhL6cySRUxOgR/SGVM6oXrXocQnd F/UT/5LogUT4CYncYausVhf/uTh4BVtiJ2Rbumm7nGUL7H4mkPJ+Y/TulVOUrMI= X-Gm-Gg: ASbGncs0ks0w6xen0/ocKlIp+s1CzVexsLPyaNHEvp7sgy52PcwClNk1FrA2EUB5UnR SsHjMeoTVga0UnpduQPHECowilJ8rPHW644qsPvo+HYHTc2FkS78n0lqdGWsVQFG3mCdYtkx3/5 7Aq7jd/HI/voqztd+N0IRGAwHfkvbsIzZDxCitKUF1JRj6mdsVc3kRVylXSOZEC32HoOEsR5uv3 a2hPf7H0PqtPrtTzP4TsP2B/9UUF5JsYdkXW4Wpgolyt3veeEwiyrPA6PrQkbDKlQQPjjWrMfEm t7SHtDMnhfnFjs1Zdh8pHzBPABwfRrSW9tAiuk0oqF8D8BqdYfI+nNDhdBR14kxa//kcNjykLdB x3T7Aw8HUC87qXpE3J5L/oJpuArJeLjzsVKZ5 X-Google-Smtp-Source: AGHT+IFkKZHhFoZlAnFPe99KVOPEEaQXKoe8aM2D5jFVeHQd5CUKhcAsOgQI6LgtRf0mamiE3y+N3g== X-Received: by 2002:a05:690c:6c03:b0:6f7:55a2:4cd8 with SMTP id 00721157ae682-706ccc88282mr14975767b3.5.1744940560942; Thu, 17 Apr 2025 18:42:40 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:40 -0700 (PDT) From: Antonio Hickey To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?B?= =?utf-8?q?j=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross Cc: Antonio Hickey , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 15/18] rust: platform: refactor to use `&raw mut` Date: Thu, 17 Apr 2025 21:41:36 -0400 Message-ID: <20250418014143.888022-16-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replacing all occurrences of `addr_of_mut!(place)` with `&raw mut place`. This will allow us to reduce macro complexity, and improve consistency with existing reference syntax as `&raw mut` is similar to `&mut` making it fit more naturally with other existing code. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- rust/kernel/platform.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index 4917cb34e2fe..f0f316b639e8 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -14,11 +14,7 @@ ThisModule, }; -use core::{ - marker::PhantomData, - ops::Deref, - ptr::{addr_of_mut, NonNull}, -}; +use core::{marker::PhantomData, ops::Deref, ptr::NonNull}; /// An adapter for the registration of platform drivers. pub struct Adapter(T); @@ -227,7 +223,7 @@ impl AsRef for Device { fn as_ref(&self) -> &device::Device { // SAFETY: By the type invariant of `Self`, `self.as_raw()` is a pointer to a valid // `struct platform_device`. - let dev = unsafe { addr_of_mut!((*self.as_raw()).dev) }; + let dev = unsafe { &raw mut (*self.as_raw()).dev }; // SAFETY: `dev` points to a valid `struct device`. unsafe { device::Device::as_ref(dev) } From patchwork Fri Apr 18 01:41:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056522 Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (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 2C2A61E0B9C for ; Fri, 18 Apr 2025 01:42:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940566; cv=none; b=nG0dcL7Xs/fQteCPGfWnxiEWtHk/IOm24XVIAtvxiS9Yqsl2wX+Y+D3MHs35E0LFTEZkOdDr28yJSTlMjcaMjVd2irIW1Vz6xcoBbZ1Utk6G+d0hZqLQXicl6k3fzEigF1mNU1WQgwAwNtcUdXDQn3LehCLAvrwVvmDmss++QyY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940566; c=relaxed/simple; bh=Vwy36Ffl1DT6zz2igWNVCn3+TcrjRpJfR4hfiCOhhes=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RiU5m58WvIIoQ1Ks0qoLqTg9xDikklWH7ymDAOLp1fafp1jY7JcyRBNCDec0XCXDitPAgnBv3aDWEMVjj3t5Pdx/OROKgkHBQJpVCa0/6iBjq4xT6MZYJKaiIRsYrQqU154gEd5Wehcpc4Kzv5pBkwIZt9YDg2iKoVDjN64jpR0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=hMXExIai; arc=none smtp.client-ip=209.85.128.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="hMXExIai" Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-6ff4faf858cso10260317b3.2 for ; Thu, 17 Apr 2025 18:42:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940564; x=1745545364; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zF4RhtkUiDGLOyYG++VtWMWiCEIKK28FF1uyz34QswM=; b=hMXExIaiaicZPqGjWQ0SYF89RAbFbGnR1JZ0fVakDTkHobP8zcqZE49hA+iiQRlay+ ffs8iNI8cpDIeAhBr2t26wOKL8pN6zEiGG5g367PgRilnMp6HQZKPLVyQZC2mpdC2WRO /Ax3kWqnM3VSobOuvH3bSk1xSb+TPeFnUnPtzHSqUGOSoDFEVLn80R39+SSoYpfU/I2/ G2X+w9VS7aWyD4Qt0mRB6Y6zfn+LjBWqwKGMo059gwq8DFb6onT0YlJAzI45nI5slJw+ jmKU2vJAkPdP/4r5PxTIBfKb6ycat6CM5MXmsraiDwaEAiwTgSaDIL5/T5robUbPmscL 4FHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940564; x=1745545364; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zF4RhtkUiDGLOyYG++VtWMWiCEIKK28FF1uyz34QswM=; b=Hrjn+h/ZPb+c3bmDIH7Mbuo7mH6pMBnG8jTH33gdz1rYfo+o/jh9tEhIanK2zSXkAl Q0D6XaZCGF1WVdsOcE0IWKlFQ4tWwRlP0uj4yHP2T2IahWbyaIAxG6iZBfqHUJdwR6KB SKatxgrz60YR+hv50Yj/E9JKhOVX2OIhZHoJxIqGFdPwuW80aUfwBzXpTFM5i7ZIOkLR 9m45AS6ge0A+4WHLWA9/YAnV+HOhe0rgMEu1+LsqdpAPuiY7BF2U5FpoVIrav6Cx+Lhu xQCKl1Ejjsmdeq/89qK9emdgnE3m93y9+rnVqehk3p8CWfYU/q3AdrW5sWIBjXPxjfq4 YPVw== X-Forwarded-Encrypted: i=1; AJvYcCWMvuyj8BAfna+Tywrk2UCAbC1e4/InumPX2uUkrBjaXboTuB67d6KRvKqnT3pR1iJ3cMXhS7/ih5KU2rKNrQ==@vger.kernel.org X-Gm-Message-State: AOJu0YzGg52+nxzh7n0g6QSmnbmxNsjh/g2ZpIlIa0mC4UnL5a1PZNtU UPRdJyqax9w3BqpeGR8H5CXW7H9IdMUbUxVGCUXUxLzJcuRlbt8OqVL5MJyx1jY= X-Gm-Gg: ASbGncu4RJuaTlaOczqYxCRnUB8cJpalYjg0yiXIoznF1lGNMu1qwcTtkzEUdidwgSx 6hxfY1B29HABhFdLbPrZ7xNOopZKeGLu7gHJC7Jg2Y0t83jUitlV40HfpeCR0RHq4TDW+uken8y wlhOAdPoKNQ8b8uOEktPtvLnpOO/sa403oVDLYdZi7i3CVvDV9SglDJakIPnrfGKBDQ0wHYFbm0 C11tqmFQeTDr3D9w8S3mQXeQgZdUvr2+V5fr/UZxbqTjVpmxrQr/n2O0rIlfoBMgD/r0Ra5sLJK BsojqkKceQMi0vqbi7ruDBMMF0kWpgQPH8Syu417WgFPpc4pKLsU7o+Q/vHrqLflob2u09JJeTz iuIAcXq2pqRf9YdeVO8cd0a9YW+FXyv4ES22H X-Google-Smtp-Source: AGHT+IGOfJZrq4SGhm601peohIgL80Conyklam8qQuR6Ew+Qk/SwIRI8plqLe2b/3lKSy4c4eP/GsA== X-Received: by 2002:a05:690c:6ac5:b0:705:a92d:cb7c with SMTP id 00721157ae682-706ccdc6e71mr14108907b3.24.1744940563880; Thu, 17 Apr 2025 18:42:43 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:43 -0700 (PDT) From: Antonio Hickey To: Abdiel Janulgue , Danilo Krummrich , Daniel Almeida , Robin Murphy , Andreas Hindborg , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross Cc: Antonio Hickey , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 16/18] rust: dma: refactor to use `&raw [const|mut]` Date: Thu, 17 Apr 2025 21:41:37 -0400 Message-ID: <20250418014143.888022-17-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replacing all occurrences of `addr_of!(place)` and `addr_of_mut!(place)` with `&raw const place` and `&raw mut place` respectively. This will allow us to reduce macro complexity, and improve consistency with existing reference syntax as `&raw const`, `&raw mut` are similar to `&`, `&mut` making it fit more naturally with other existing code. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- rust/kernel/dma.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs index 8cdc76043ee7..8a63c0e83c92 100644 --- a/rust/kernel/dma.rs +++ b/rust/kernel/dma.rs @@ -333,7 +333,7 @@ macro_rules! dma_read { // dereferenced. The compiler also further validates the expression on whether `field` // is a member of `item` when expanded by the macro. unsafe { - let ptr_field = ::core::ptr::addr_of!((*item) $($field)*); + let ptr_field = &raw const ((*item) $($field)*); $crate::dma::CoherentAllocation::field_read(&$dma, ptr_field) } }}; @@ -384,7 +384,7 @@ macro_rules! dma_write { // dereferenced. The compiler also further validates the expression on whether `field` // is a member of `item` when expanded by the macro. unsafe { - let ptr_field = ::core::ptr::addr_of_mut!((*item) $(.$field)*); + let ptr_field = &raw mut ((*item) $(.$field)*); $crate::dma::CoherentAllocation::field_write(&$dma, ptr_field, $val) } }; From patchwork Fri Apr 18 01:41:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056523 Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) (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 6161221505C for ; Fri, 18 Apr 2025 01:42:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940569; cv=none; b=VG1/G+G999GsGKLWp+nSXT3l54bkhnxN4RdRHhckudiMXXP0yOOFhKBEMRaed4mWMef/kwoGeHLJGDF2tVsBAK/mwUe5dxMBUHlasi5rmwC4hmQaji6SDrlRM/v+xzIIuxBXtKY/CcoS+KFWBGsS/tv3EDR1atcuw2iw1k/Xcp4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940569; c=relaxed/simple; bh=66w5Al5Imrsz5hvbCFFqfSu+FK8G3lQg6TXeGP8s+iA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bDbT9F1TfvBAN+WN7OJNkzxUr4bfs+JSZGgGCKKUTVsWyEILNPpMLjs21mgZSsfYxYudrXaJSMv4sPwmOemOzyP/wWpDqp50UPXFq1F+5jlLJQIVHX06oNyJW+LL0C5FIKL+lIKPwZb5MG+ECRasgtzqhRbP49ROQ+PUOOKK2S0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=1igMc2AJ; arc=none smtp.client-ip=209.85.128.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="1igMc2AJ" Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-702599fa7c5so17235357b3.1 for ; Thu, 17 Apr 2025 18:42:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940566; x=1745545366; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KG1FX1ranOgzfEQWfQ6ONypjLKpYZeGLhyGYRDWOj0I=; b=1igMc2AJhXZytcEi0Tm8WpAFNb5dsOc37va7CM+1KcYzvKQabzOYtvFni6XCJMhXMK m/YkUbq6n7CRvHRJoSIU37LinIctE/Jm6aHqXH3wYDwX1/rWDBnupNYT6728jMkNBpK4 EPmpHG19KKrP77KKWE5Bxuf5X0fDCZx56RyugTalENW+izZqjm5IWM61pvbQN5rdEoh6 1fOhedm0ebK5m2aV+rDMBnZNZRLW5k9kvt5rrkHhMUVnqJjE5Xmf1bOwTpMdICE5XSe6 gI3YfVqanRYEZcQGeoiH9Z4MJr/GN5OzUtnEh4YCcNeoVohCiECy67dGkuXxgeDQZVJ1 1onQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940566; x=1745545366; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KG1FX1ranOgzfEQWfQ6ONypjLKpYZeGLhyGYRDWOj0I=; b=Q+GSN9no9aSaEl088dgngDHXCVaU0qWFXQFYC+QjfgQEUbb3OKL0ENMwf56FzYsrUh CmE08CtUnX1RFlZWRaCz2ykh30xOH/vW4ldorKIvMBpa5TfNs6O/ptvqxJxXI+cWshdA FkWZPKRPr9jrVBayOE9ZRL2QJD22oVIW/8mAh4B1oZV1VY9mpY4ZzKjfq1LurSf94CJQ bsLHNpElgp6og6rYZcDyF0jIX32rXpXVumBLe8KTUxbNPf0OGwKq23drd/zyaGj1VzXh HwwRi8eDaWbp/XZ2ZLxvcalCrzOX727Le5BH8sN9qcnt15Szm13m1DO1iSW8SkESEuS1 xsfw== X-Forwarded-Encrypted: i=1; AJvYcCUq5xnA5YCfh+YC8wQSz+0f57Bt6J/V5as1+z+dgLkSN65sFdQ0+HRXIQXY/xOcfYSwWSDo9RnEf/MMsPccIw==@vger.kernel.org X-Gm-Message-State: AOJu0Yyu1m2Xwg6/JSvl007KFohFNBa6Ygx7+QbsYD8QzQYucANJGGq2 GHiPXHmnqB1vYRt8Wz6MlE6zplLca/Y2GZHos4zVYGrkUp3AVQ42BAAKbQ22hPA= X-Gm-Gg: ASbGncuqKtrZ0/9V/2OYjgyTNiv+p8O3V3gzgyYVTg4rKGfWRGAVxp6PFnQ+38FmM1M m0TPBoTSnswLDK/HqfowAZed3pa35FCpcylRj/xhUM7KW/v2Jlx9/DIoZDYIqJ2/1NRRR4s1mue 1pp/Z4ciowWwkfH01u+ru7h4kI3yLV+Unsj2PnYoOEwW0SdKF2bmzoyhPrTvc2Ny3zRvdciL1nL gs3W9FupMZDmiO0Up9CvKPhWEJAb7euxxwHug2467jlLLoPs5/j6adLv2CqdtAe5Xsv5caTIcAQ BnDyXXXnyKiRFrPgmUX6L8NpqHdq0ztzSs+N4xgsXEDgNEL6MYp2qp4T3fNVX7ihmurXHg/dJg3 tlFL4hATbbo2xl8v+XnuW3w2bUAu3bNmoFIWX X-Google-Smtp-Source: AGHT+IEQ0mGUH9sjetr7NY5sXJ8/VLVK70qyuSik19yD6EJGi5DmNmFBRWOM9b05eHxeXtZYr+xuDg== X-Received: by 2002:a05:690c:940e:b0:6fe:4ee5:a6d5 with SMTP id 00721157ae682-706ca335ad7mr34942287b3.0.1744940566187; Thu, 17 Apr 2025 18:42:46 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:45 -0700 (PDT) From: Antonio Hickey To: Benno Lossin , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: Antonio Hickey , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 17/18] rust: pin-init: refactor to use `&raw mut` Date: Thu, 17 Apr 2025 21:41:38 -0400 Message-ID: <20250418014143.888022-18-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replacing all occurrences of `addr_of_mut!(place)` with `&raw mut place`. This will allow us to reduce macro complexity, and improve consistency with existing reference syntax as `&raw mut` is similar to `&mut` making it fit more naturally with other existing code. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- rust/pin-init/README.md | 3 +-- rust/pin-init/src/lib.rs | 7 +++---- rust/pin-init/src/macros.rs | 16 ++++++++-------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/rust/pin-init/README.md b/rust/pin-init/README.md index 3d04796b212b..1ab4ad0144f3 100644 --- a/rust/pin-init/README.md +++ b/rust/pin-init/README.md @@ -142,7 +142,6 @@ actually does the initialization in the correct way. Here are the things to look ```rust use pin_init::{pin_data, pinned_drop, PinInit, PinnedDrop, pin_init_from_closure}; use core::{ - ptr::addr_of_mut, marker::PhantomPinned, cell::UnsafeCell, pin::Pin, @@ -181,7 +180,7 @@ impl RawFoo { unsafe { pin_init_from_closure(move |slot: *mut Self| { // `slot` contains uninit memory, avoid creating a reference. - let foo = addr_of_mut!((*slot).foo); + let foo = &raw mut (*slot).foo; let foo = UnsafeCell::raw_get(foo).cast::(); // Initialize the `foo` diff --git a/rust/pin-init/src/lib.rs b/rust/pin-init/src/lib.rs index 05c44514765e..36391738835c 100644 --- a/rust/pin-init/src/lib.rs +++ b/rust/pin-init/src/lib.rs @@ -166,7 +166,6 @@ //! # #![feature(extern_types)] //! use pin_init::{pin_data, pinned_drop, PinInit, PinnedDrop, pin_init_from_closure}; //! use core::{ -//! ptr::addr_of_mut, //! marker::PhantomPinned, //! cell::UnsafeCell, //! pin::Pin, @@ -205,7 +204,7 @@ //! unsafe { //! pin_init_from_closure(move |slot: *mut Self| { //! // `slot` contains uninit memory, avoid creating a reference. -//! let foo = addr_of_mut!((*slot).foo); +//! let foo = &raw mut (*slot).foo; //! let foo = UnsafeCell::raw_get(foo).cast::(); //! //! // Initialize the `foo` @@ -698,7 +697,7 @@ macro_rules! stack_try_pin_init { /// /// ```rust /// # use pin_init::*; -/// # use core::{ptr::addr_of_mut, marker::PhantomPinned}; +/// # use core::marker::PhantomPinned; /// #[pin_data] /// #[derive(Zeroable)] /// struct Buf { @@ -712,7 +711,7 @@ macro_rules! stack_try_pin_init { /// let init = pin_init!(&this in Buf { /// buf: [0; 64], /// // SAFETY: TODO. -/// ptr: unsafe { addr_of_mut!((*this.as_ptr()).buf).cast() }, +/// ptr: unsafe { (&raw mut (*this.as_ptr()).buf).cast() }, /// pin: PhantomPinned, /// }); /// let init = pin_init!(Buf { diff --git a/rust/pin-init/src/macros.rs b/rust/pin-init/src/macros.rs index 28a91a1e1218..14ab121443f0 100644 --- a/rust/pin-init/src/macros.rs +++ b/rust/pin-init/src/macros.rs @@ -251,7 +251,7 @@ //! // is an error later. This `DropGuard` will drop the field when it gets //! // dropped and has not yet been forgotten. //! let __t_guard = unsafe { -//! ::pin_init::__internal::DropGuard::new(::core::addr_of_mut!((*slot).t)) +//! ::pin_init::__internal::DropGuard::new(&raw mut (*slot).t) //! }; //! // Expansion of `x: 0,`: //! // Since this can be an arbitrary expression we cannot place it inside @@ -262,7 +262,7 @@ //! } //! // We again create a `DropGuard`. //! let __x_guard = unsafe { -//! ::pin_init::__internal::DropGuard::new(::core::addr_of_mut!((*slot).x)) +//! ::pin_init::__internal::DropGuard::new(&raw mut (*slot).x) //! }; //! // Since initialization has successfully completed, we can now forget //! // the guards. This is not `mem::forget`, since we only have @@ -462,12 +462,12 @@ //! unsafe { ::core::ptr::write(&raw mut (*slot).a, a) }; //! } //! let __a_guard = unsafe { -//! ::pin_init::__internal::DropGuard::new(::core::addr_of_mut!((*slot).a)) +//! ::pin_init::__internal::DropGuard::new(&raw mut (*slot).a) //! }; //! let init = Bar::new(36); //! unsafe { data.b(&raw mut (*slot).b, b)? }; //! let __b_guard = unsafe { -//! ::pin_init::__internal::DropGuard::new(::core::addr_of_mut!((*slot).b)) +//! ::pin_init::__internal::DropGuard::new(&raw mut (*slot).b) //! }; //! ::core::mem::forget(__b_guard); //! ::core::mem::forget(__a_guard); @@ -1223,7 +1223,7 @@ fn assert_zeroable(_: *mut T) {} $crate::macros::paste! { // SAFETY: We forget the guard later when initialization has succeeded. let [< __ $field _guard >] = unsafe { - $crate::__internal::DropGuard::new(::core::ptr::addr_of_mut!((*$slot).$field)) + $crate::__internal::DropGuard::new(&raw mut (*$slot).$field) }; $crate::__init_internal!(init_slot($use_data): @@ -1246,7 +1246,7 @@ fn assert_zeroable(_: *mut T) {} // // SAFETY: `slot` is valid, because we are inside of an initializer closure, we // return when an error/panic occurs. - unsafe { $crate::Init::__init(init, ::core::ptr::addr_of_mut!((*$slot).$field))? }; + unsafe { $crate::Init::__init(init, &raw mut (*$slot).$field)? }; // Create the drop guard: // // We rely on macro hygiene to make it impossible for users to access this local variable. @@ -1254,7 +1254,7 @@ fn assert_zeroable(_: *mut T) {} $crate::macros::paste! { // SAFETY: We forget the guard later when initialization has succeeded. let [< __ $field _guard >] = unsafe { - $crate::__internal::DropGuard::new(::core::ptr::addr_of_mut!((*$slot).$field)) + $crate::__internal::DropGuard::new(&raw mut (*$slot).$field) }; $crate::__init_internal!(init_slot(): @@ -1286,7 +1286,7 @@ fn assert_zeroable(_: *mut T) {} $crate::macros::paste! { // SAFETY: We forget the guard later when initialization has succeeded. let [< __ $field _guard >] = unsafe { - $crate::__internal::DropGuard::new(::core::ptr::addr_of_mut!((*$slot).$field)) + $crate::__internal::DropGuard::new(&raw mut (*$slot).$field) }; $crate::__init_internal!(init_slot($($use_data)?): From patchwork Fri Apr 18 01:41:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Hickey X-Patchwork-Id: 14056524 Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) (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 1E358217701 for ; Fri, 18 Apr 2025 01:42:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940574; cv=none; b=s4r0DKsYLF+yBSVio+ajYJWaLkTIghlFF52xJ2j264EWJsR0iKZURIC2+lhf864jvdcPDO7EmOvQarC1f9j/+CF8yuPaGsE2Zp4CY6H/L83kjekwcA0N8/EWFSIhycvG6r2Ei3VSUP/yEp+rslaSiAn9P1+bLwbej2bq2bnqpKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744940574; c=relaxed/simple; bh=/wpo3AJH76G0D8d6eO4aADK4qMN5wuurt9VWTjkkxHw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HRqAqC0WQGmQuJlV+vMIJSFFDm5NqTCOArMIcVV+tK7Hcoy/OTehkXB+ieF0HG0i+FjDFRas+hYYan8wHrNGtfxvK3ApOiFp2cfKzPWBlCNcbxbszJDZZDwwo5TcmP9OKS+1H20VIe5VVgPV/ZhYLMgif22aR6g1AWvtcUKTIyQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com; spf=pass smtp.mailfrom=byte-forge.io; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b=b5C6rgv/; arc=none smtp.client-ip=209.85.128.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=antoniohickey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=byte-forge.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=byte-forge-io.20230601.gappssmtp.com header.i=@byte-forge-io.20230601.gappssmtp.com header.b="b5C6rgv/" Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-6feb229b716so13785177b3.3 for ; Thu, 17 Apr 2025 18:42:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=byte-forge-io.20230601.gappssmtp.com; s=20230601; t=1744940572; x=1745545372; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lMrN3Fgq1s8yx9+yzOmhCcKYbou3Yw819UYNCZPiTyA=; b=b5C6rgv/DU6qL4HKx3s0DFz8uHXENrHYgnACgkOhnexwqcY0sZDOzrSJfdg709g6mP BFXO01gdkyPTSxAswbbXcr3sJITI/O16vbGp5G8lnsVsXf5HJhyf7Njf8YbQyNpBvPLo rsi1pJLeslupCTzerWnPF+MYN1lRLZZAehQNcOB3nuI11eQWR+K8wja5UZfwHpCSs6Xj a05xsxHIYBBAOcbwL+mVRjISL6dtkQ/yeUZu4y4DYWOEcL7cpCwrf6B2RXFQurkPICTJ 6/SEgwM5K40ciIPozUkdYEXLb+jQBWA6BGSSk4bdD8iTSm6Y8+rreWiK06KiEBnD28S3 uJkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744940572; x=1745545372; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lMrN3Fgq1s8yx9+yzOmhCcKYbou3Yw819UYNCZPiTyA=; b=GDT2LKkGoAhN5xqK+ri+hSZBFkeaCp+RpKiDVCy9a8PHDlVnJZdHrfGRieWhZqW+3E sqReaNrMOOU9p+rfd7TKCqwZiuu1212jOxoZYlVE6J1bn7jPLHbaBliZJuWQJcnfrF3g hyIlEeJPYVB61wK0X2o3/0ldwZQ7hYv1O2ZIVpIyHw3IGE6yksvcHrNp39FLD+plRDST QcpRnUFDqUBQha04PSvZvxKLbpe4FHLwRzdHbIK5zn2MrCHBXddlVWzYcXMcPb0n7Gu5 F4wPbc+XtP++mRWInOa14k9RDrtY0OJ+kLgHT+F6GdJcY4WtDIsPjPom8v39FXFLkTTC x4Sw== X-Forwarded-Encrypted: i=1; AJvYcCWL7kplHIZ9dMwATklajfRmBaj1NiECC7mTmqutEzw/2R5AbNguh6UfkbENtRY2vglIFrPij1/tmceyZfJqOg==@vger.kernel.org X-Gm-Message-State: AOJu0Yx6D0IyeUzOgWeKHAWzBMc+3M1u0b6eEkXL29bVUpA+I900PQHs h6/r90emujCeMl3mZNkL/7d9PVYIeJjMbKJwYT7CMenuVoXVwNoGqQTuSxBsgTE= X-Gm-Gg: ASbGncv2bXdq/7UYic9UeYtzccIpJ3Qyyi6jPnefBiz40BnfU3OB120udOyhKvhTvPQ /dTdpERj8+fEmP1obd/nPTrzkiEFNk3EbpBphnW1s+KkgRWgdlgaJXMqYaLJi6r2c7shsPy87PO T7oPbCgZxZgtJO1OQi/4TAoc+DIJot9U4U4nR96VZtFCkm79YYvMUsovvA6FNxZ5QEmaicmj4cz 3ctrSHJdyUpWk5PlnmrZqqM8Aoi5qj57l9blgSe/6KlzMqJ6X1dCYo/KaEf/83/qX95KLpaiz5O d9l0afa7RiIXrlD/M5D/hq+9tICK9pJTXM4b4ytrP+c46g3rOm+35u7pIB2CMRRgFGILt8d7mZ8 3SF6c4dGcTfLu7rInwkDaUmy0gR1sDDKARsjXZoo+240bU4o= X-Google-Smtp-Source: AGHT+IH02BN+95qDUcaVS2ybaCgcg+oKHZ+qn+L+ISKmk228G2SJ0hPgywUHQgDia3GpE6KgNe9f0w== X-Received: by 2002:a05:690c:4c11:b0:702:6276:9446 with SMTP id 00721157ae682-706ccf4ae83mr14736327b3.34.1744940572066; Thu, 17 Apr 2025 18:42:52 -0700 (PDT) Received: from Machine.localdomain (107-219-75-226.lightspeed.wepbfl.sbcglobal.net. [107.219.75.226]) by smtp.gmail.com with ESMTPSA id 00721157ae682-706ca44fd13sm2804597b3.20.2025.04.17.18.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 18:42:51 -0700 (PDT) From: Antonio Hickey To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?B?= =?utf-8?q?j=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: Antonio Hickey , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 18/18] rust: clippy: disallow `addr_of[_mut]!` macros Date: Thu, 17 Apr 2025 21:41:39 -0400 Message-ID: <20250418014143.888022-19-contact@antoniohickey.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250418014143.888022-1-contact@antoniohickey.com> References: <20250418014143.888022-1-contact@antoniohickey.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With the `raw_ref_op` feature enabled we no longer want to allow use of the `addr_of!` and `addr_of_mut!` macros. We instead want to use `&raw const` and `&raw mut` to get raw pointers to a place. Note that this lint isn't currently reliable, but we enable it nevertheless because: 1. Document that one shouldn't use the `addr_of[_mut]!` macros. 2. When the lint becomes useful we will already have it enabled. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Link: https://github.com/rust-lang/rust-clippy/issues/11431 Signed-off-by: Antonio Hickey --- .clippy.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.clippy.toml b/.clippy.toml index 815c94732ed7..b7d87377a468 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -8,4 +8,8 @@ disallowed-macros = [ # The `clippy::dbg_macro` lint only works with `std::dbg!`, thus we simulate # it here, see: https://github.com/rust-lang/rust-clippy/issues/11303. { path = "kernel::dbg", reason = "the `dbg!` macro is intended as a debugging tool" }, + # With `raw_ref_op` feature enabled we no longer want to allow use of `addr_of!` + # and `addr_of_mut!` macros, but instead suggest use of `&raw const` or `&raw mut`. + { path = "core::ptr::addr_of_mut", reason = "use `&raw mut` instead `addr_of_mut!`" }, + { path = "core::ptr::addr_of", reason = "use `&raw const` instead `addr_of!`" }, ]