From patchwork Sun Mar 9 16:00:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamir Duberstein X-Patchwork-Id: 14008633 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (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 AAC4B1DF73C; Sun, 9 Mar 2025 16:01:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741536067; cv=none; b=t4G0ANpC9w1CFJA6gn08SHbo336vkLmslSeh7m+IS4viXOjvXGYpEBAlVIiIiCiBd/4slKRTV8YwmPx23lSJgReOpZ0+2m0+LRX2xIPvzIgFDpy4rfaukWc8knaDpGiNIvQqN2Ho0v/BG0awAV6gz1bZvr9TvWpAyI5yKNtFhAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741536067; c=relaxed/simple; bh=VZFIg4TXh9XzX0Mrmu1nOAtjzO8svjTQp2SnjUn+WA4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ow4ZsaIiOarHm8v+x/2kxChJgNe/0/fNm1Hl866OiXTWXwTbQuRX4CzAbnhp/1nvvzbzHb5cjmDHZ4TOm7iauVmI8zDy+jPwuAnV13QiUNVcz7YXJKS22uJzI0CsfyIQ0vy0Fe/gyyWqVJmsAQRA8XhAuqOxV1KErN133SxHPXs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ArVidusR; arc=none smtp.client-ip=209.85.219.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ArVidusR" Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6e8ec399427so24625266d6.2; Sun, 09 Mar 2025 09:01:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741536064; x=1742140864; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=RBllPpz7VEqR2WvVX+a/3v656rUk6jfALJLaE9Z8g2Q=; b=ArVidusRaKsapsfajZG0yrRyr88v4E+jPIznT2F9hSef2YkryiBqbDH24Bykvc9gBJ ulBokpHZjA+rpDfWXpvQ8qxMCvaF4KXdywg4h5hz4fLKh2Xgig8kq81tyNDk7GNSVI9h kRwUTDHDR7JpWT+fM1jcYqHayX4tMJ7B6rwXYxDwLIvp8rKTCYQqnucHhHXk4haNrG8R TO7Ce214Bt3J47drbpdSYil5oK7bbGNGjJs+GvURuBHa8mXbQqe2nWYx102ChGkxymL/ 2kRlKkgc2xEi8jCqZPTIIHQJueUBj2ORfhPaPgHdyZ7zYZVwWD1I7gc2ajcxNnPStDZJ an4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741536064; x=1742140864; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RBllPpz7VEqR2WvVX+a/3v656rUk6jfALJLaE9Z8g2Q=; b=R9YRhY/wdZbQKtsGtEDSyLBGuNy5UAq/R9yu/oQCRyySut3Lrv9q4P9jetw3hTxNBn NiI2GExE8AUcSnJQVjhoD+AdvUHXmfm0ylaQlTwEETHOJ520HIBMVHBOaFfGJRRGiVeP gPSNgH+9UW35OXtqIW2DBy/HwWRq/8Y3F3gvS8yWhtkuj6I6+8dJYRc22addW7BSciw5 8DDqc7V2/cty8rZKngiadoERYA+SAK+3cEoTOP/PVRnn2AVjfRN9uWnHwLPHx6PqF4SZ BfYJNB6fublgy7L/nLSDFfCtQbglWDZM5vRg4+o0+9uoOaNy8SKnStjLQ77d1h7X+WSU We3Q== X-Forwarded-Encrypted: i=1; AJvYcCUFbG0BtPc5H/UEIt1GqzDSced7CiaN5PXx18fPuMjWw6QPahSoIJX6HtTF9FMeMHahvyS8tOOcQ0lu@vger.kernel.org, AJvYcCVV7mDdOZdYOa6iTgq/1lbiBeYfU+kpUIxokQ5/f2do8NjzdhYpBTfZCRhj8Vm2C+dcD8NLKKI4PvLPcWCvrlc=@vger.kernel.org, AJvYcCVeYvWUhyOZrzid7JtzlKWbM+OtyYtHiFec3kaKeRf3RMLzgbbUDAYk3S5HXSrrYyjYlu0nvmH6gGIOiVnK5QPp@vger.kernel.org, AJvYcCXTD5iM5b+Wjb3wuLuOnT0RfiU2t+Dt85dznMELboHAwC5e2LdYIVQK/WDWkRBJVraTz3PEfafQsRfiYNE=@vger.kernel.org, AJvYcCXcB6psznbuyLsMfa9W285Gbh/u7hYHqWvFrSUwxCWzA2f5jt+pKeY3hDVRDlVJVjpoa1zYESVIVx/c@vger.kernel.org, AJvYcCXxzDfOyqKevlKdzUFRcrOojJhaTbLJ4r6Cq3ppmD50y88XjSeAP4FVSgzCqRwIyl5SIa+CBR32wKG2Q5ep@vger.kernel.org X-Gm-Message-State: AOJu0Yzd0oJtlXF0qdcyg0Q5uVGxexv7kwa3uZE0w3O/Trgnc9Pp76og XInqBwPTdZtcq9IvqFuO4WnY4Zd+K6Cv+KyfknWNXy8Mc4xeTH0o X-Gm-Gg: ASbGnctUxL1NPZIJEzuVAWXq9RIKRcgs8Fd34XInqCb5HcacLiXodZLTBW4gPEWPNkb +T7eD912lDuKp3z25AK3+8tuvUxr8Rryzob+B05+V8M3BTaZAIyBHt+RHKbcev7pQVi7ZvLqNED MhSvXpr4BQ3S0RVzjP5LteGZ15mEdvgP3KsAukjc17a2+B0QVA0Wb4xDxyZz9mVsC8kWPzVjkMc iSR2pZ5LtVWqOuaLcSBZj/dLz/X/k4D3O9mUnmf/YHLKHAkqmuw7Wrds0vTfeSX9KECodKpS8Tr AH1czhhpNleKVlSPJWWqMZw6tmX0y4V+Xv0ADnpBprcm0UNCmyMXK+7yF0rw0rLSIDI= X-Google-Smtp-Source: AGHT+IESqVUQFR+cQRbu+bscWrxEcSiPg+y+zXbo0sToWAnpe+xZUI43s4fil9r2PHX7RLN1yiDR6g== X-Received: by 2002:a05:6214:2428:b0:6e8:97d2:99a2 with SMTP id 6a1803df08f44-6e900681c78mr153498936d6.39.1741536064328; Sun, 09 Mar 2025 09:01:04 -0700 (PDT) Received: from [192.168.1.159] ([2600:4041:5be7:7c00:f0dd:49a0:8ab6:b3b6]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c3e534d38dsm512531485a.44.2025.03.09.09.01.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Mar 2025 09:01:03 -0700 (PDT) From: Tamir Duberstein Date: Sun, 09 Mar 2025 12:00:40 -0400 Subject: [PATCH v2 1/5] rust: retain pointer mut-ness in `container_of!` Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250309-ptr-as-ptr-v2-1-25d60ad922b7@gmail.com> References: <20250309-ptr-as-ptr-v2-0-25d60ad922b7@gmail.com> In-Reply-To: <20250309-ptr-as-ptr-v2-0-25d60ad922b7@gmail.com> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , 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 , Greg Kroah-Hartman , "Rafael J. Wysocki" , Brendan Higgins , David Gow , Rae Moar , Bjorn Helgaas , Luis Chamberlain , Russ Weight , Rob Herring , Saravana Kannan Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-pci@vger.kernel.org, linux-block@vger.kernel.org, devicetree@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev Avoid casting the input pointer to `*const _`, allowing the output pointer to be `*mut` if the input is `*mut`. This allows a number of `*const` to `*mut` conversions to be removed at the cost of slightly worse ergonomics when the macro is used with a reference rather than a pointer; the only example of this was in the macro's own doctest. Signed-off-by: Tamir Duberstein --- rust/kernel/lib.rs | 5 ++--- rust/kernel/pci.rs | 2 +- rust/kernel/platform.rs | 2 +- rust/kernel/rbtree.rs | 23 ++++++++++------------- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 7697c60b2d1a..9cd6b6864739 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -187,7 +187,7 @@ fn panic(info: &core::panic::PanicInfo<'_>) -> ! { /// } /// /// let test = Test { a: 10, b: 20 }; -/// let b_ptr = &test.b; +/// let b_ptr: *const _ = &test.b; /// // SAFETY: The pointer points at the `b` field of a `Test`, so the resulting pointer will be /// // in-bounds of the same allocation as `b_ptr`. /// let test_alias = unsafe { container_of!(b_ptr, Test, b) }; @@ -196,9 +196,8 @@ fn panic(info: &core::panic::PanicInfo<'_>) -> ! { #[macro_export] macro_rules! container_of { ($ptr:expr, $type:ty, $($f:tt)*) => {{ - let ptr = $ptr as *const _ as *const u8; let offset: usize = ::core::mem::offset_of!($type, $($f)*); - ptr.sub(offset) as *const $type + $ptr.byte_sub(offset).cast::<$type>() }} } diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 4c98b5b9aa1e..c37476576f02 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -364,7 +364,7 @@ pub unsafe fn from_dev(dev: ARef) -> Self { fn as_raw(&self) -> *mut bindings::pci_dev { // SAFETY: By the type invariant `self.0.as_raw` is a pointer to the `struct device` // embedded in `struct pci_dev`. - unsafe { container_of!(self.0.as_raw(), bindings::pci_dev, dev) as _ } + unsafe { container_of!(self.0.as_raw(), bindings::pci_dev, dev) } } /// Returns the PCI vendor ID. diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index 50e6b0421813..c51617569c01 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -189,7 +189,7 @@ unsafe fn from_dev(dev: ARef) -> Self { fn as_raw(&self) -> *mut bindings::platform_device { // SAFETY: By the type invariant `self.0.as_raw` is a pointer to the `struct device` // embedded in `struct platform_device`. - unsafe { container_of!(self.0.as_raw(), bindings::platform_device, dev) }.cast_mut() + unsafe { container_of!(self.0.as_raw(), bindings::platform_device, dev) } } } diff --git a/rust/kernel/rbtree.rs b/rust/kernel/rbtree.rs index 0d1e75810664..1fdea2806cfa 100644 --- a/rust/kernel/rbtree.rs +++ b/rust/kernel/rbtree.rs @@ -424,7 +424,7 @@ pub fn cursor_lower_bound(&mut self, key: &K) -> Option> while !node.is_null() { // 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!(node, Node, links) }.cast_mut(); + let this = unsafe { container_of!(node, Node, links) }; // SAFETY: `this` is a non-null node so it is valid by the type invariants. let this_key = unsafe { &(*this).key }; // SAFETY: `node` is a non-null node so it is valid by the type invariants. @@ -496,7 +496,7 @@ fn drop(&mut self) { // but it is not observable. The loop invariant is still maintained. // SAFETY: `this` is valid per the loop invariant. - unsafe { drop(KBox::from_raw(this.cast_mut())) }; + unsafe { drop(KBox::from_raw(this)) }; } } } @@ -761,7 +761,7 @@ pub fn remove_current(self) -> (Option, RBTreeNode) { let next = self.get_neighbor_raw(Direction::Next); // 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!(self.current.as_ptr(), Node, links) }.cast_mut(); + let this = unsafe { container_of!(self.current.as_ptr(), Node, links) }; // SAFETY: `this` is valid by the type invariants as described above. let node = unsafe { KBox::from_raw(this) }; let node = RBTreeNode { node }; @@ -806,7 +806,7 @@ fn remove_neighbor(&mut self, direction: Direction) -> Option> unsafe { bindings::rb_erase(neighbor, addr_of_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(); + let this = unsafe { container_of!(neighbor, Node, links) }; // SAFETY: `this` is valid by the type invariants as described above. let node = unsafe { KBox::from_raw(this) }; return Some(RBTreeNode { node }); @@ -912,7 +912,7 @@ unsafe fn to_key_value_mut<'b>(node: NonNull) -> (&'b K, &'b unsafe fn to_key_value_raw<'b>(node: NonNull) -> (&'b K, *mut V) { // 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!(node.as_ptr(), Node, links) }.cast_mut(); + let this = unsafe { container_of!(node.as_ptr(), Node, links) }; // SAFETY: The passed `node` is the current node or a non-null neighbor, // thus `this` is valid by the type invariants. let k = unsafe { &(*this).key }; @@ -1021,7 +1021,7 @@ fn next(&mut self) -> Option { // SAFETY: By the type invariant of `IterRaw`, `self.next` is a valid node in an `RBTree`, // and by the type invariant of `RBTree`, all nodes point to the links field of `Node` objects. - let cur = unsafe { container_of!(self.next, Node, links) }.cast_mut(); + let cur = unsafe { container_of!(self.next, Node, links) }; // SAFETY: `self.next` is a valid tree node by the type invariants. self.next = unsafe { bindings::rb_next(self.next) }; @@ -1216,7 +1216,7 @@ pub fn get_mut(&mut self) -> &mut V { // SAFETY: // - `self.node_links` is a valid pointer to a node in the tree. // - We have exclusive access to the underlying tree, and can thus give out a mutable reference. - unsafe { &mut (*(container_of!(self.node_links, Node, links).cast_mut())).value } + unsafe { &mut (*(container_of!(self.node_links, Node, links))).value } } /// Converts the entry into a mutable reference to its value. @@ -1226,7 +1226,7 @@ pub fn into_mut(self) -> &'a mut V { // SAFETY: // - `self.node_links` is a valid pointer to a node in the tree. // - This consumes the `&'a mut RBTree`, therefore it can give out a mutable reference that lives for `'a`. - unsafe { &mut (*(container_of!(self.node_links, Node, links).cast_mut())).value } + unsafe { &mut (*(container_of!(self.node_links, Node, links))).value } } /// Remove this entry from the [`RBTree`]. @@ -1239,9 +1239,7 @@ pub fn remove_node(self) -> RBTreeNode { RBTreeNode { // SAFETY: The node was a node in the tree, but we removed it, so we can convert it // back into a box. - node: unsafe { - KBox::from_raw(container_of!(self.node_links, Node, links).cast_mut()) - }, + node: unsafe { KBox::from_raw(container_of!(self.node_links, Node, links)) }, } } @@ -1272,8 +1270,7 @@ fn replace(self, node: RBTreeNode) -> RBTreeNode { // SAFETY: // - `self.node_ptr` produces a valid pointer to a node in the tree. // - Now that we removed this entry from the tree, we can convert the node to a box. - let old_node = - unsafe { KBox::from_raw(container_of!(self.node_links, Node, links).cast_mut()) }; + let old_node = unsafe { KBox::from_raw(container_of!(self.node_links, Node, links)) }; RBTreeNode { node: old_node } } From patchwork Sun Mar 9 16:00:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamir Duberstein X-Patchwork-Id: 14008634 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E6E01E8358; Sun, 9 Mar 2025 16:01:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741536071; cv=none; b=kQVUiRoFx073Gi+LIlnuxqNgV9mCA4EuzwGC4ibaF5SK8Cky2QMPkGoYbvVcYFumIPOJzAM4OT6d8w8LioTZs3/6pikt3lMSXpv9ytXJRRIxpbLZ/mCCFFWZLDqofskaWura+7q4dQAfMAeQj98gUsr3wrA9cdvxIKgFk4MEi8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741536071; c=relaxed/simple; bh=7EcD94Q4WYWZR7ZthCrbgntSRdI+N+imKFQkk4+NRuc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DP4vKCUBMHj+YTWrn8O4Tv53pqJYZeLr9ljQFxsB8Hn89i0emqhg6ltUbrKOGJLrbonJ2YD5EmE06+FB9EROCMCH8IZ/9ksi37DiOH2LhGk7chHrXx5FtIlWoBF3ZwTONAU8jAydaXyyoczI1cDMbEXiRNvM02n9mz2PEnqb63w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BA3tEyxa; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BA3tEyxa" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7be8f281714so362393785a.1; Sun, 09 Mar 2025 09:01:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741536068; x=1742140868; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=aZ88zBFCTRQHOQ0Wg8U7mUnIF3pMghf8VYGy5QjQeVs=; b=BA3tEyxady/7M8XgHWzIQAiNKJ5hrjC3BI7Io6hL49m22RYMkY7C5NR45qfnbb8EMO um81u9FG5jERIw+DiqHQbgpzMH2B0BDx6UdE/R7GoYnw/EgE/RNVk07FwCtLYabXj2yP xYw8zVg5joPW6HZfISKn2Eki2Pxeuv7cjfist8G2K1xasF7toVAbrUZmsV1VBSLPL5UM bwBS2rXlQpJ4n4pbwe2utkZs7M03bjSTBoHxiuhG+gnkXgx4bsG0Ssq0ynUKAERBLQZr 4Kp11ZcLFVNLl44F6fR2u7dOvfuTCGx0UrPNZ7i76EW23G5pO6gpFNS5Uzr2vVNoIs1h +zWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741536068; x=1742140868; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aZ88zBFCTRQHOQ0Wg8U7mUnIF3pMghf8VYGy5QjQeVs=; b=lT1h4yftUhqmi/C6IVIrqzSCRWvpHjCsu4MyiFmPk4l6tXwF2jGnFVxpoEh0v7loxZ UwwtdXo82OYqcEOX9QCIiTFEf34Uao6JJ98g/El3MZbuRexjr5kwDzK5OSyaLKiqFNb0 9BPD1u1/5lZkxTK7sjs3V3aI8szvtMCRuIovqA2UueJ2a8Fi7rMH13gfuanwDAtaBoqA FehZSZ4G4KqcoQW6CHtr2BJGTk4N0iDaOXJhGFRfwzobS7r2W7bAQrnXIqkDjqycUuVM 54IeA4Lut0MOY9Xq5aC2fgBmaYEIhP3blXP82vruMJyAO2vSjT3F5C6hjRKnt7Vuq1Md /TkQ== X-Forwarded-Encrypted: i=1; AJvYcCUDXyZtIhD4AYkBvUdSIjM5BbM14FN4P0UBdGYpUYvyfhgBSSZqokihsGedMbQ/Kgh/7hX2QJ7i8iLoYjd++Ik=@vger.kernel.org, AJvYcCUiOALuqednObN2a6Oqc/EdUPxx3cShW5gvwLSX/AxaQLf1WXD5PJGUImr7abrzWiyqggPShIJgABRAIJur@vger.kernel.org, AJvYcCVSSgrMXiITqbMJiC2H+VSxsP2mseU7O/BBpHWpaVxQZSUkYl+DFd0eSM1pd8hJQjk8V2EuCOlAIPzb@vger.kernel.org, AJvYcCVgCtQkiNPBg7EF4E5KHl5Nb4fZ8wH4HfnRZ/zyZhQmgkBv0pRlWqGl52k6gSIkmN8VPT688IpkuEyI@vger.kernel.org, AJvYcCVqHw36/ZWenCHPuOSSv+CPHKsj+aE6LgVJsO8Wk2Ya9TkHvA4++n6jglGrlVWuij7ybUqA2aWxzJ+WRjo=@vger.kernel.org, AJvYcCXRDtU20BNKur2kHzngEAJa2/DY4UVX6fiphfBPIdgtPKs4pIGbtn9sKSmcPtLUpazey9sL3vPEDAgdhPRo8KNJ@vger.kernel.org X-Gm-Message-State: AOJu0YwYzfCNaSKmflfTh9QPohY4x623JyyATkyXQTyDruAj78YmufIV 2WyNCu44hOeQ2PSnGreA6wSEXQX3JS3+FVcZ159dhJ0VNo5uGCTP X-Gm-Gg: ASbGnctWlpW2xZpzAfLYfp0d/j93l8AtOlv5iuPu1czNsh35LWiA1wM5kN89R9igiyE OOnLTRnxFUxYsQBu0zrdOj/q5IeFTEhbpLuQtkJnwS5M7PJ0qXRdM2mH/BhZF90P4HoDv10htwe RNENLaWvEwTD6Uo9Uj4HQev0sCjBvD7K4MXX0DYwUqGYsFTWSjNMaU7rmYplG0oJaNCPAV2Yc8b FVPHuvwzbK1SsIK8YE3FTu0eNNO6Y+hRsFQt0mL2h1xnJRUAdlIpOoRFEYkvPvziSNxLyB3oALp Xli92GLkByJh7naNSidFLRpvqnGH4i5s9JHFJrFx6YF6NVAVP919iNudImtNc7UvhbA= X-Google-Smtp-Source: AGHT+IFLYWIe1YCYz9TtcFkgYRFHXG06GTA+p1as4phyBoWZ2QLHVJAUuO95b9SpyVed9gOhZ2HdCg== X-Received: by 2002:a05:620a:2b43:b0:7c5:4750:9304 with SMTP id af79cd13be357-7c547509392mr512711385a.24.1741536067675; Sun, 09 Mar 2025 09:01:07 -0700 (PDT) Received: from [192.168.1.159] ([2600:4041:5be7:7c00:f0dd:49a0:8ab6:b3b6]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c3e534d38dsm512531485a.44.2025.03.09.09.01.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Mar 2025 09:01:06 -0700 (PDT) From: Tamir Duberstein Date: Sun, 09 Mar 2025 12:00:41 -0400 Subject: [PATCH v2 2/5] rust: enable `clippy::ptr_as_ptr` lint Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250309-ptr-as-ptr-v2-2-25d60ad922b7@gmail.com> References: <20250309-ptr-as-ptr-v2-0-25d60ad922b7@gmail.com> In-Reply-To: <20250309-ptr-as-ptr-v2-0-25d60ad922b7@gmail.com> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , 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 , Greg Kroah-Hartman , "Rafael J. Wysocki" , Brendan Higgins , David Gow , Rae Moar , Bjorn Helgaas , Luis Chamberlain , Russ Weight , Rob Herring , Saravana Kannan Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-pci@vger.kernel.org, linux-block@vger.kernel.org, devicetree@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev In Rust 1.51.0, Clippy introduced the `ptr_as_ptr` lint [1]: > Though `as` casts between raw pointers are not terrible, > `pointer::cast` is safer because it cannot accidentally change the > pointer's mutability, nor cast the pointer to other types like `usize`. There are a few classes of changes required: - Modules generated by bindgen are marked `#[allow(clippy::ptr_as_ptr)]`. - Inferred casts (` as _`) are replaced with `.cast()`. - Ascribed casts (` as *... T`) are replaced with `.cast::()`. - Multistep casts from references (` as *const _ as *const T`) are replaced with `let x: *const _ = &x;` and `.cast()` or `.cast::()` according to the previous rules. The intermediate `let` binding is required because `(x as *const _).cast::()` results in inference failure. - Native literal C strings are replaced with `c_str!().as_char_ptr()`. Apply these changes and enable the lint -- no functional change intended. Link: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr [1] Signed-off-by: Tamir Duberstein --- Makefile | 1 + rust/bindings/lib.rs | 1 + rust/kernel/alloc/allocator_test.rs | 2 +- rust/kernel/alloc/kvec.rs | 4 ++-- rust/kernel/device.rs | 5 +++-- rust/kernel/devres.rs | 2 +- rust/kernel/error.rs | 2 +- rust/kernel/fs/file.rs | 2 +- rust/kernel/kunit.rs | 15 +++++++-------- rust/kernel/list/impl_list_item_mod.rs | 2 +- rust/kernel/pci.rs | 2 +- rust/kernel/platform.rs | 4 +++- rust/kernel/print.rs | 11 +++++------ rust/kernel/seq_file.rs | 3 ++- rust/kernel/str.rs | 2 +- rust/kernel/sync/poll.rs | 2 +- rust/kernel/workqueue.rs | 10 +++++----- rust/uapi/lib.rs | 1 + 18 files changed, 38 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 70bdbf2218fc..ec8efc8e23ba 100644 --- a/Makefile +++ b/Makefile @@ -483,6 +483,7 @@ export rust_common_flags := --edition=2021 \ -Wclippy::needless_continue \ -Aclippy::needless_lifetimes \ -Wclippy::no_mangle_with_rust_abi \ + -Wclippy::ptr_as_ptr \ -Wclippy::undocumented_unsafe_blocks \ -Wclippy::unnecessary_safety_comment \ -Wclippy::unnecessary_safety_doc \ diff --git a/rust/bindings/lib.rs b/rust/bindings/lib.rs index 014af0d1fc70..0486a32ed314 100644 --- a/rust/bindings/lib.rs +++ b/rust/bindings/lib.rs @@ -25,6 +25,7 @@ )] #[allow(dead_code)] +#[allow(clippy::ptr_as_ptr)] #[allow(clippy::undocumented_unsafe_blocks)] mod bindings_raw { // Manual definition for blocklisted types. diff --git a/rust/kernel/alloc/allocator_test.rs b/rust/kernel/alloc/allocator_test.rs index c37d4c0c64e9..8017aa9d5213 100644 --- a/rust/kernel/alloc/allocator_test.rs +++ b/rust/kernel/alloc/allocator_test.rs @@ -82,7 +82,7 @@ unsafe fn realloc( // SAFETY: Returns either NULL or a pointer to a memory allocation that satisfies or // exceeds the given size and alignment requirements. - let dst = unsafe { libc_aligned_alloc(layout.align(), layout.size()) } as *mut u8; + let dst = unsafe { libc_aligned_alloc(layout.align(), layout.size()) }.cast::(); let dst = NonNull::new(dst).ok_or(AllocError)?; if flags.contains(__GFP_ZERO) { diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs index ae9d072741ce..c12844764671 100644 --- a/rust/kernel/alloc/kvec.rs +++ b/rust/kernel/alloc/kvec.rs @@ -262,7 +262,7 @@ pub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit] { // - `self.len` is smaller than `self.capacity` and hence, the resulting pointer is // guaranteed to be part of the same allocated object. // - `self.len` can not overflow `isize`. - let ptr = unsafe { self.as_mut_ptr().add(self.len) } as *mut MaybeUninit; + let ptr = unsafe { self.as_mut_ptr().add(self.len) }.cast::>(); // SAFETY: The memory between `self.len` and `self.capacity` is guaranteed to be allocated // and valid, but uninitialized. @@ -554,7 +554,7 @@ fn drop(&mut self) { // - `ptr` points to memory with at least a size of `size_of::() * len`, // - all elements within `b` are initialized values of `T`, // - `len` does not exceed `isize::MAX`. - unsafe { Vec::from_raw_parts(ptr as _, len, len) } + unsafe { Vec::from_raw_parts(ptr.cast(), len, len) } } } diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs index db2d9658ba47..9e500498835d 100644 --- a/rust/kernel/device.rs +++ b/rust/kernel/device.rs @@ -168,16 +168,17 @@ pub fn pr_dbg(&self, args: fmt::Arguments<'_>) { /// `KERN_*`constants, for example, `KERN_CRIT`, `KERN_ALERT`, etc. #[cfg_attr(not(CONFIG_PRINTK), allow(unused_variables))] unsafe fn printk(&self, klevel: &[u8], msg: fmt::Arguments<'_>) { + let msg: *const _ = &msg; // SAFETY: `klevel` is null-terminated and one of the kernel constants. `self.as_raw` // is valid because `self` is valid. The "%pA" format string expects a pointer to // `fmt::Arguments`, which is what we're passing as the last argument. #[cfg(CONFIG_PRINTK)] unsafe { bindings::_dev_printk( - klevel as *const _ as *const crate::ffi::c_char, + klevel.as_ptr().cast::(), self.as_raw(), c_str!("%pA").as_char_ptr(), - &msg as *const _ as *const crate::ffi::c_void, + msg.cast::(), ) }; } diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs index 942376f6f3af..3a9d998ec371 100644 --- a/rust/kernel/devres.rs +++ b/rust/kernel/devres.rs @@ -157,7 +157,7 @@ fn remove_action(this: &Arc) { #[allow(clippy::missing_safety_doc)] unsafe extern "C" fn devres_callback(ptr: *mut kernel::ffi::c_void) { - let ptr = ptr as *mut DevresInner; + let ptr = ptr.cast::>(); // Devres owned this memory; now that we received the callback, drop the `Arc` and hence the // reference. // SAFETY: Safe, since we leaked an `Arc` reference to devm_add_action() in diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs index f6ecf09cb65f..8654d52b0bb9 100644 --- a/rust/kernel/error.rs +++ b/rust/kernel/error.rs @@ -152,7 +152,7 @@ pub(crate) fn to_blk_status(self) -> bindings::blk_status_t { /// Returns the error encoded as a pointer. pub fn to_ptr(self) -> *mut T { // SAFETY: `self.0` is a valid error due to its invariant. - unsafe { bindings::ERR_PTR(self.0.get() as _) as *mut _ } + unsafe { bindings::ERR_PTR(self.0.get() as _).cast() } } /// Returns a string representing the error, if one exists. diff --git a/rust/kernel/fs/file.rs b/rust/kernel/fs/file.rs index e03dbe14d62a..8936afc234a4 100644 --- a/rust/kernel/fs/file.rs +++ b/rust/kernel/fs/file.rs @@ -364,7 +364,7 @@ fn deref(&self) -> &LocalFile { // // By the type invariants, there are no `fdget_pos` calls that did not take the // `f_pos_lock` mutex. - unsafe { LocalFile::from_raw_file(self as *const File as *const bindings::file) } + unsafe { LocalFile::from_raw_file((self as *const Self).cast()) } } } diff --git a/rust/kernel/kunit.rs b/rust/kernel/kunit.rs index 824da0e9738a..7ed2063c1af0 100644 --- a/rust/kernel/kunit.rs +++ b/rust/kernel/kunit.rs @@ -8,19 +8,20 @@ use core::{ffi::c_void, fmt}; +#[cfg(CONFIG_PRINTK)] +use crate::c_str; + /// Prints a KUnit error-level message. /// /// Public but hidden since it should only be used from KUnit generated code. #[doc(hidden)] pub fn err(args: fmt::Arguments<'_>) { + let args: *const _ = &args; // SAFETY: The format string is null-terminated and the `%pA` specifier matches the argument we // are passing. #[cfg(CONFIG_PRINTK)] unsafe { - bindings::_printk( - c"\x013%pA".as_ptr() as _, - &args as *const _ as *const c_void, - ); + bindings::_printk(c_str!("\x013%pA").as_char_ptr(), args.cast::()); } } @@ -29,14 +30,12 @@ pub fn err(args: fmt::Arguments<'_>) { /// Public but hidden since it should only be used from KUnit generated code. #[doc(hidden)] pub fn info(args: fmt::Arguments<'_>) { + let args: *const _ = &args; // SAFETY: The format string is null-terminated and the `%pA` specifier matches the argument we // are passing. #[cfg(CONFIG_PRINTK)] unsafe { - bindings::_printk( - c"\x016%pA".as_ptr() as _, - &args as *const _ as *const c_void, - ); + bindings::_printk(c_str!("\x016%pA").as_char_ptr(), args.cast::()); } } diff --git a/rust/kernel/list/impl_list_item_mod.rs b/rust/kernel/list/impl_list_item_mod.rs index a0438537cee1..1f9498c1458f 100644 --- a/rust/kernel/list/impl_list_item_mod.rs +++ b/rust/kernel/list/impl_list_item_mod.rs @@ -34,7 +34,7 @@ pub unsafe trait HasListLinks { unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut ListLinks { // SAFETY: The caller promises that the pointer is valid. The implementer promises that the // `OFFSET` constant is correct. - unsafe { (ptr as *mut u8).add(Self::OFFSET) as *mut ListLinks } + unsafe { ptr.cast::().add(Self::OFFSET).cast() } } } diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index c37476576f02..63218abb7a25 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -75,7 +75,7 @@ extern "C" fn probe_callback( // Let the `struct pci_dev` own a reference of the driver's private data. // SAFETY: By the type invariant `pdev.as_raw` returns a valid pointer to a // `struct pci_dev`. - unsafe { bindings::pci_set_drvdata(pdev.as_raw(), data.into_foreign() as _) }; + unsafe { bindings::pci_set_drvdata(pdev.as_raw(), data.into_foreign().cast()) }; } Err(err) => return Error::to_errno(err), } diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index c51617569c01..d609119e8ce8 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -66,7 +66,9 @@ extern "C" fn probe_callback(pdev: *mut bindings::platform_device) -> kernel::ff // Let the `struct platform_device` own a reference of the driver's private data. // SAFETY: By the type invariant `pdev.as_raw` returns a valid pointer to a // `struct platform_device`. - unsafe { bindings::platform_set_drvdata(pdev.as_raw(), data.into_foreign() as _) }; + unsafe { + bindings::platform_set_drvdata(pdev.as_raw(), data.into_foreign().cast()) + }; } Err(err) => return Error::to_errno(err), } diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs index b19ee490be58..0245c145ea32 100644 --- a/rust/kernel/print.rs +++ b/rust/kernel/print.rs @@ -25,7 +25,7 @@ // SAFETY: The C contract guarantees that `buf` is valid if it's less than `end`. let mut w = unsafe { RawFormatter::from_ptrs(buf.cast(), end.cast()) }; // SAFETY: TODO. - let _ = w.write_fmt(unsafe { *(ptr as *const fmt::Arguments<'_>) }); + let _ = w.write_fmt(unsafe { *ptr.cast::>() }); w.pos().cast() } @@ -102,6 +102,7 @@ pub unsafe fn call_printk( module_name: &[u8], args: fmt::Arguments<'_>, ) { + let args: *const _ = &args; // `_printk` does not seem to fail in any path. #[cfg(CONFIG_PRINTK)] // SAFETY: TODO. @@ -109,7 +110,7 @@ pub unsafe fn call_printk( bindings::_printk( format_string.as_ptr(), module_name.as_ptr(), - &args as *const _ as *const c_void, + args.cast::(), ); } } @@ -122,15 +123,13 @@ pub unsafe fn call_printk( #[doc(hidden)] #[cfg_attr(not(CONFIG_PRINTK), allow(unused_variables))] pub fn call_printk_cont(args: fmt::Arguments<'_>) { + let args: *const _ = &args; // `_printk` does not seem to fail in any path. // // SAFETY: The format string is fixed. #[cfg(CONFIG_PRINTK)] unsafe { - bindings::_printk( - format_strings::CONT.as_ptr(), - &args as *const _ as *const c_void, - ); + bindings::_printk(format_strings::CONT.as_ptr(), args.cast::()); } } diff --git a/rust/kernel/seq_file.rs b/rust/kernel/seq_file.rs index 04947c672979..90545d28e6b7 100644 --- a/rust/kernel/seq_file.rs +++ b/rust/kernel/seq_file.rs @@ -31,12 +31,13 @@ pub unsafe fn from_raw<'a>(ptr: *mut bindings::seq_file) -> &'a SeqFile { /// Used by the [`seq_print`] macro. pub fn call_printf(&self, args: core::fmt::Arguments<'_>) { + let args: *const _ = &args; // SAFETY: Passing a void pointer to `Arguments` is valid for `%pA`. unsafe { bindings::seq_printf( self.inner.get(), c_str!("%pA").as_char_ptr(), - &args as *const _ as *const crate::ffi::c_void, + args.cast::(), ); } } diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index 28e2201604d6..6a1a982b946d 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -191,7 +191,7 @@ pub unsafe fn from_char_ptr<'a>(ptr: *const crate::ffi::c_char) -> &'a Self { // to a `NUL`-terminated C string. let len = unsafe { bindings::strlen(ptr) } + 1; // SAFETY: Lifetime guaranteed by the safety precondition. - let bytes = unsafe { core::slice::from_raw_parts(ptr as _, len) }; + let bytes = unsafe { core::slice::from_raw_parts(ptr.cast(), len) }; // SAFETY: As `len` is returned by `strlen`, `bytes` does not contain interior `NUL`. // As we have added 1 to `len`, the last byte is known to be `NUL`. unsafe { Self::from_bytes_with_nul_unchecked(bytes) } diff --git a/rust/kernel/sync/poll.rs b/rust/kernel/sync/poll.rs index d5f17153b424..a151f54cde91 100644 --- a/rust/kernel/sync/poll.rs +++ b/rust/kernel/sync/poll.rs @@ -73,7 +73,7 @@ pub fn register_wait(&mut self, file: &File, cv: &PollCondVar) { // be destroyed, the destructor must run. That destructor first removes all waiters, // and then waits for an rcu grace period. Therefore, `cv.wait_queue_head` is valid for // long enough. - unsafe { qproc(file.as_ptr() as _, cv.wait_queue_head.get(), self.0.get()) }; + unsafe { qproc(file.as_ptr().cast(), cv.wait_queue_head.get(), self.0.get()) }; } } } diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs index 0cd100d2aefb..8ff54105be3f 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -170,7 +170,7 @@ impl Queue { pub unsafe fn from_raw<'a>(ptr: *const bindings::workqueue_struct) -> &'a Queue { // SAFETY: The `Queue` type is `#[repr(transparent)]`, so the pointer cast is valid. The // caller promises that the pointer is not dangling. - unsafe { &*(ptr as *const Queue) } + unsafe { &*ptr.cast::() } } /// Enqueues a work item. @@ -457,7 +457,7 @@ fn get_work_offset(&self) -> usize { #[inline] unsafe fn raw_get_work(ptr: *mut Self) -> *mut Work { // SAFETY: The caller promises that the pointer is valid. - unsafe { (ptr as *mut u8).add(Self::OFFSET) as *mut Work } + unsafe { ptr.cast::().add(Self::OFFSET).cast::>() } } /// Returns a pointer to the struct containing the [`Work`] field. @@ -472,7 +472,7 @@ unsafe fn work_container_of(ptr: *mut Work) -> *mut Self { // SAFETY: The caller promises that the pointer points at a field of the right type in the // right kind of struct. - unsafe { (ptr as *mut u8).sub(Self::OFFSET) as *mut Self } + unsafe { ptr.cast::().sub(Self::OFFSET).cast::() } } } @@ -538,7 +538,7 @@ unsafe impl WorkItemPointer for Arc { unsafe extern "C" fn run(ptr: *mut bindings::work_struct) { // The `__enqueue` method always uses a `work_struct` stored in a `Work`. - let ptr = ptr as *mut Work; + let ptr = ptr.cast::>(); // SAFETY: This computes the pointer that `__enqueue` got from `Arc::into_raw`. let ptr = unsafe { T::work_container_of(ptr) }; // SAFETY: This pointer comes from `Arc::into_raw` and we've been given back ownership. @@ -591,7 +591,7 @@ unsafe impl WorkItemPointer for Pin> { unsafe extern "C" fn run(ptr: *mut bindings::work_struct) { // The `__enqueue` method always uses a `work_struct` stored in a `Work`. - let ptr = ptr as *mut Work; + let ptr = ptr.cast::>(); // SAFETY: This computes the pointer that `__enqueue` got from `Arc::into_raw`. let ptr = unsafe { T::work_container_of(ptr) }; // SAFETY: This pointer comes from `Arc::into_raw` and we've been given back ownership. diff --git a/rust/uapi/lib.rs b/rust/uapi/lib.rs index 13495910271f..fe9bf7b5a306 100644 --- a/rust/uapi/lib.rs +++ b/rust/uapi/lib.rs @@ -15,6 +15,7 @@ #![allow( clippy::all, clippy::undocumented_unsafe_blocks, + clippy::ptr_as_ptr, dead_code, missing_docs, non_camel_case_types, From patchwork Sun Mar 9 16:00:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamir Duberstein X-Patchwork-Id: 14008635 Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (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 559671EF371; Sun, 9 Mar 2025 16:01:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741536074; cv=none; b=Id43l72i40HtBgWKdJFjfhQNkm9ka8QH8KHtAObSBhqnGW89BJy8lIaMpegYeNxhnJKsvvwfBpgm9cUcxU45U+yxDy3bz+S0MKnL1LJcoJl4T325wFMgkG2qw8k4DNfU96aWFIxDrjOTRgelSB7SnAGOVSLU6Lw1czhH0fk7BWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741536074; c=relaxed/simple; bh=HxbhEPgqCuwrpYNtTePvfa/ubYGF3lGsbO7lrTt8oKA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WtiVeVNRWUbtYfVCSKq0xbEVLtIHwYm5CA8m+GipUpuKa1IsKWCatoDyg9ffE57c30UmdGlFsu30Uk41YRYwDaVMfaeIyJCy64E+Jmr8V7XgQa1WMrqC+UODfydU9HVO33yoL4D2pb1UT2Wcm5P3FD3FVYy2VPpcPiFflp3a9gI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mF4cgE2u; arc=none smtp.client-ip=209.85.219.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mF4cgE2u" Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-6e904f53151so14692416d6.3; Sun, 09 Mar 2025 09:01:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741536071; x=1742140871; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=o7KaSTZS5R2yUcePjN3hlGQ4K9sAZcgJ+NDJtZEjrbo=; b=mF4cgE2ubfBIBDr7DurtNPZxtjBf8UJSHjwOvSaUJf8trIr/FX+O5jrYbJqo/4Ag/N rE2WUIAN8DSPzuf8SN55L7bCmqFuE/BOMvmUZcUfK4JbHpOg9wt2oPxS96peNJPx0Zrf kY0bZbqz5EV2ZJ3Yow8cANWfoA9wS5BEBOYNTBY3dnsA0Ez4WXYr6dbv/h6+Za6dtWfI 5/X1JPAbxSsl5lVHqO0aWEJwDu0D1wrEwGN4xi7xcNrOqR6QkNekVjH2pDE1sRk0U3VW +Lkxo+xY11Clv4Tdj9sZlbE70M8bL7AchzxXfHdojRADM+GtTH443G18sNh2mmWJawM+ K9kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741536071; x=1742140871; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o7KaSTZS5R2yUcePjN3hlGQ4K9sAZcgJ+NDJtZEjrbo=; b=c25hO3E9EBpU5g6dapC20DLB8dMTUI+qExmKLx1MhvnNg116jYm6EU+o+imSjRT/Dk 9L/+lMBsIk2a5e9J0L+NsljaBRcleAUWk7VOy/zUD9wY9bks4BiR0uaUK8CoD6+wcwZG i4MjftyLAJlwl/pBW5MuXMmlGQ5CYYeBNMFXWrN0bcUDC03w2+eGiaYkOSoNf0ZdWts4 daetoYaqoXLVbeDF9iegI+1WIvE+xWdES/s1cnlmBzox0qsWfnxNMP6ueb7wKDtNDaZI hnRPo+iFrzRRb4ZvSRUfteeiI4YACw2tbCB0DtOjJerj5Csog3GOgmmQ0ZvJgY5Iz9ZL zHGQ== X-Forwarded-Encrypted: i=1; AJvYcCUPUI8KdfXRsOu++5BH+DLSdxIcCzze+R52vGShTl47434gTgjcXHtswcmDxDfY6USKHaxf6N7pXLKhHzw=@vger.kernel.org, AJvYcCVXgZ1VIzzCJgtBLsyj+vb3NMO1t6SrVBsTgheJCZakSrXeIofONyxGOrPI2d9xO0W2f9KQcdMT4uAwBBFDij7X@vger.kernel.org, AJvYcCVpWAPGg6Ilhm96vnPiocGqYSDV+qMoG6FY8EwOd66wY4z0r58AhzCPqURPRy63eT4i0dgtktgGVvGU@vger.kernel.org, AJvYcCWO8fXf9sPvfHjSyaYHQEPETOXusS/o9ZAabB7vNDqxOJDT0MctIWNkIbkGwNio3I5QrDBkW4Bgdfnksx/W@vger.kernel.org, AJvYcCXhkfml/2aNkrpGk7yCDknNFrPXP4tauezmzjsoTBwyjwv/2UfLfRbUwEVEan95/AEraIioa/i7HFRAeaUvTMg=@vger.kernel.org, AJvYcCXxL5RQpR7VyZzL6JPaxTSrkjCgaTXh6k26+eVD6NBRcEdekupg9OKpLjhrCrkzSN5K83jSEpg3E+L2@vger.kernel.org X-Gm-Message-State: AOJu0YzruKmkkyUnINe3vGf3jG1LgiTflX1LwCvI+9j/YURi+8mM2LWq 0/ySn3jUpNkPsKPv2c0Zh4zh/zSSCxs0EPEkah5sZHb4GEovbQVJ X-Gm-Gg: ASbGncsynP3+qqkSBLuW+i8otoecJ3GtuUgR8HDA7mYkJ4XTqZUYIMd8RvGLrjDuMqF 7KIV+qReuQw5tdy+y1gENUdbe8G3GXA6AQFun8LsKc7YGYVN8WTTtnzYz2bQ0QhZWUWHWlaAsab X5CUtOWjY0TSPjFB4yPIyGNvjC1VyJz5ZBn3qfXEvM6BUY4+lY6OQJQOEhLjErguP098hF9ywBf BYoB9qIDpQ04Tt/tyOWr1df+GtvB4yOoPH+1htpVepyL8CpaQsezXqDP+iHwnxrxDDktYQjszBI 9OCVyzYm1LEVJQBwanQ07ttcgQ1ZXPh6FdqLqOKjUY6bMZELJvGIbShrvJ2XlgtRd+8= X-Google-Smtp-Source: AGHT+IFJtY7lXlh5gqBGTBs5oIzomrTfGTpZbDYZs0cgMoc/Gx8TBR/rXmP7+drYJX9np1C/LXlUUA== X-Received: by 2002:a05:6214:da9:b0:6e6:68e3:8d84 with SMTP id 6a1803df08f44-6e9006041damr162266376d6.18.1741536071123; Sun, 09 Mar 2025 09:01:11 -0700 (PDT) Received: from [192.168.1.159] ([2600:4041:5be7:7c00:f0dd:49a0:8ab6:b3b6]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c3e534d38dsm512531485a.44.2025.03.09.09.01.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Mar 2025 09:01:09 -0700 (PDT) From: Tamir Duberstein Date: Sun, 09 Mar 2025 12:00:42 -0400 Subject: [PATCH v2 3/5] rust: enable `clippy::ptr_cast_constness` lint Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250309-ptr-as-ptr-v2-3-25d60ad922b7@gmail.com> References: <20250309-ptr-as-ptr-v2-0-25d60ad922b7@gmail.com> In-Reply-To: <20250309-ptr-as-ptr-v2-0-25d60ad922b7@gmail.com> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , 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 , Greg Kroah-Hartman , "Rafael J. Wysocki" , Brendan Higgins , David Gow , Rae Moar , Bjorn Helgaas , Luis Chamberlain , Russ Weight , Rob Herring , Saravana Kannan Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-pci@vger.kernel.org, linux-block@vger.kernel.org, devicetree@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev In Rust 1.72.0, Clippy introduced the `ptr_cast_constness` lint [1]: > Though `as` casts between raw pointers are not terrible, > `pointer::cast_mut` and `pointer::cast_const` are safer because they > cannot accidentally cast the pointer to another type. There are only 2 affected sites: - `*mut T as *const U as *mut U` becomes `(*mut T).cast()` - `&self as *const Self as *mut Self` becomes a reference-to-pointer coercion + `(*const Self).cast()`. Apply these changes and enable the lint -- no functional change intended. Link: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_cast_constness [1] Signed-off-by: Tamir Duberstein --- Makefile | 1 + rust/kernel/block/mq/request.rs | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ec8efc8e23ba..c62bae2b107b 100644 --- a/Makefile +++ b/Makefile @@ -484,6 +484,7 @@ export rust_common_flags := --edition=2021 \ -Aclippy::needless_lifetimes \ -Wclippy::no_mangle_with_rust_abi \ -Wclippy::ptr_as_ptr \ + -Wclippy::ptr_cast_constness \ -Wclippy::undocumented_unsafe_blocks \ -Wclippy::unnecessary_safety_comment \ -Wclippy::unnecessary_safety_doc \ diff --git a/rust/kernel/block/mq/request.rs b/rust/kernel/block/mq/request.rs index 7943f43b9575..10c6d69be7f3 100644 --- a/rust/kernel/block/mq/request.rs +++ b/rust/kernel/block/mq/request.rs @@ -69,7 +69,7 @@ pub(crate) unsafe fn aref_from_raw(ptr: *mut bindings::request) -> ARef { // INVARIANT: By the safety requirements of this function, invariants are upheld. // SAFETY: By the safety requirement of this function, we own a // reference count that we can pass to `ARef`. - unsafe { ARef::from_raw(NonNull::new_unchecked(ptr as *const Self as *mut Self)) } + unsafe { ARef::from_raw(NonNull::new_unchecked(ptr.cast())) } } /// Notify the block layer that a request is going to be processed now. @@ -151,11 +151,12 @@ pub(crate) unsafe fn wrapper_ptr(this: *mut Self) -> NonNull /// Return a reference to the [`RequestDataWrapper`] stored in the private /// area of the request structure. pub(crate) fn wrapper_ref(&self) -> &RequestDataWrapper { + let this: *const _ = self; // SAFETY: By type invariant, `self.0` is a valid allocation. Further, // the private data associated with this request is initialized and // valid. The existence of `&self` guarantees that the private data is // valid as a shared reference. - unsafe { Self::wrapper_ptr(self as *const Self as *mut Self).as_ref() } + unsafe { Self::wrapper_ptr(this.cast_mut()).as_ref() } } } From patchwork Sun Mar 9 16:00:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tamir Duberstein X-Patchwork-Id: 14008636 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.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 D0DF41DF259; Sun, 9 Mar 2025 16:01:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741536079; cv=none; b=fWc8ZfULjNJmS52QPwchyxFUDaDMtbv3+CSTMapvBbbwp+H9vCO9jvdAxRDJSKPKwje68pey4n6a8a8+l7734CIUBORi/jO5FZujhwYFU3lB7qQTKXmzWa8xvQMKQa+lFsRsU5CXjqChHTrF/rCpmGEHi3CYG2LBFCd2Ju3yPTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741536079; c=relaxed/simple; bh=oNRbNb4r/1V2VqyfgzcuLuSel9lESwEeMabx/50bX9A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OnwzLqD1tpSZqXsQUTYSH1zprhWUe7swXvOxj97IPMg6glz1zQby4NbrJDLM5h5vn2Qy3A+fR7wsZYLgwKg8I4YbWSiBQ4wrJpm3jdNAhDzP+PL2dg7rHvMoa3GoHpX7wb3M0NUW890WEh8vCLBQixg1hbuTB1SMy/qMwW/bTds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QlNPHDuU; arc=none smtp.client-ip=209.85.222.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QlNPHDuU" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-7be8f28172dso222790585a.3; Sun, 09 Mar 2025 09:01:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741536074; x=1742140874; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=hAWd0B4we2Lx/jsJEWSFzRia6Y42P0AOIVa7mxyDLPQ=; b=QlNPHDuUPEE6QOWWb2goxnvYrarp+oxT201cXwLrxY2cGTBSJ2H5ZOtYs3SzzHhEvC r2C9ATkxtweXfujm+wrUefLGLtF8g7nyXgwJMRPW9Aajub+PxCK/QBQYYO0u2/uYonmu 2NiZg+EvL9aDT4ZxUVjBlyJy/rZe+60LhiqEPSolZ5f5w/a0Fm2/zPXqW9K14YdCupoQ w2pjcjFNmooCQBS46ittxb/PbZctuSJUq+2gxSjSsu3MUN2wFsf5bzj04H4R/rAo3JD4 dqt8mBJtfMYe3oq2zdsVMFd2qCp/kEYmBlUWgsM2iuMmpAsCzU7op+HAZ/qvW82aaW73 c6sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741536074; x=1742140874; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hAWd0B4we2Lx/jsJEWSFzRia6Y42P0AOIVa7mxyDLPQ=; b=f5V2/biVsbclaxZY/CNRIU09wyCdDxCBkWwuL/4SRxB4GAJmI9yCJOohSQd1pEquGA xSgWNxaD+X3GtFK3Rk1wG+tkxIZAVB7gl66jQk2T1EM7ahR10uzTPU33IjLcUZjNXgZM YaSbKdLZcqJTClkhRyfFvYKK5nt3W+MXhvl5HUwX9yhlUD01UTDGe6wKn4R12sqxzwW+ walEqmPAvocItFpBjfVVGLpQ+3l5z4Lih6RlJQtEyDmcWqqPWMJhFEo0ONXjPO2nFDD+ vMEeKDV2lMrwXhPnhHSRRHNRaQfsbprIE7L9rmdbtKlDwSsGJKqb0LupVxBFRRkQGb8e TZ5w== X-Forwarded-Encrypted: i=1; AJvYcCUv5fDwza6lyKB+v9T02kmWizaC4RguP5Htg1BIIeJKjyFiqPmT+rvGYT8O3pY5T7IFNB/yk/56hGaDC7M=@vger.kernel.org, AJvYcCV42xnTMTn/YZP9lG19YDoVVBwXVvfZwTNThyScx1iTmHJBKwigdH0Gb6dxxf6RYVLp9E4DZlxfUPXs@vger.kernel.org, AJvYcCWE6PFmU6g41f3lybPYjYrh7CNYtOMW+IzGlK+6bsEFEEm2fCzwI2cD996mUpOb73MGqJLfWNlOzKxPsxRxeSdv@vger.kernel.org, AJvYcCWfuigSycblgw7q0Yt06aMwBrAsorjpStZkf/UC5/eC3NYymGZPEOZIl1vEttfz64UizASZmqgCO30G17hQa0Q=@vger.kernel.org, AJvYcCXm21I5i1NyaZPIAZvdR7AW2yT2su0RMuUJYgBLjRoBec9W78x4KkBai32lV5yVgJZzHVyEau2h0puJS0Y7@vger.kernel.org, AJvYcCXyXLrgNEwmuTzB+AdYgtLqPcWJtYK2akMOa7Af4nHtuMObkNkk8PNZNAceK4jzVuozXHcvjIvZ8E6N@vger.kernel.org X-Gm-Message-State: AOJu0YzZS1B73ErMVY+4UKEsjJlGoHwycr36H9dWtvC9cTF8RWv+N2lQ zU6uKgKPv6vrysx4Yl844uM4dg7zel23IJqxBY7eGLCes2Hergb3 X-Gm-Gg: ASbGncsndRLAOAoFIoBAJ+2JbClKeU2yWkWf+nqAnj2RrQPrZevGHowW8KSzjSYH1G0 VzIo8NRJwQZvTHBWS3aNG0dljGqJYjgwX7s9qeshEl06maAN27A9/yYL51+uFd2Euc2LeLmXn1W xs1K2ZVX43X+Wj7dIf8k8zl3TmRCVKHZGb0V9cBZVfrbZWbFw/aUeSqB7txnURMJmDBmN6Gm+AZ xbrcOHuW7ygR/jyZYj/GG4CFwioX3k+u1/+j2jI/lvthUZ9DozbTxI3+lyiPL1r3+0pK13t60XQ yPBjaaJLZxjLLLbXaMpAn4dffSY+xQmuJ6uC391zK3p5ieKd/maIO0MjCWOX5amucSo= X-Google-Smtp-Source: AGHT+IGi9XWEOmbXwJHyecHe6thZh1KgqXu7hMzrKof4MiursoZ/E4M5j6+CcIFUc+LvzdjhS0N5YA== X-Received: by 2002:a05:620a:640d:b0:7c5:4be5:b0b1 with SMTP id af79cd13be357-7c54be5b2a0mr325321685a.35.1741536074608; Sun, 09 Mar 2025 09:01:14 -0700 (PDT) Received: from [192.168.1.159] ([2600:4041:5be7:7c00:f0dd:49a0:8ab6:b3b6]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c3e534d38dsm512531485a.44.2025.03.09.09.01.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Mar 2025 09:01:13 -0700 (PDT) From: Tamir Duberstein Date: Sun, 09 Mar 2025 12:00:43 -0400 Subject: [PATCH v2 4/5] rust: enable `clippy::as_ptr_cast_mut` lint Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250309-ptr-as-ptr-v2-4-25d60ad922b7@gmail.com> References: <20250309-ptr-as-ptr-v2-0-25d60ad922b7@gmail.com> In-Reply-To: <20250309-ptr-as-ptr-v2-0-25d60ad922b7@gmail.com> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , 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 , Greg Kroah-Hartman , "Rafael J. Wysocki" , Brendan Higgins , David Gow , Rae Moar , Bjorn Helgaas , Luis Chamberlain , Russ Weight , Rob Herring , Saravana Kannan Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-pci@vger.kernel.org, linux-block@vger.kernel.org, devicetree@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev In Rust 1.66.0, Clippy introduced the `as_ptr_cast_mut` lint [1]: > Since `as_ptr` takes a `&self`, the pointer won’t have write > permissions unless interior mutability is used, making it unlikely > that having it as a mutable pointer is correct. There is only one affected callsite, and the change amounts to replacing `as _` with `.cast_mut().cast()`. This doesn't change the semantics, but is more descriptive of what's going on. Apply this change and enable the lint -- no functional change intended. Link: https://rust-lang.github.io/rust-clippy/master/index.html#as_ptr_cast_mut [1] Signed-off-by: Tamir Duberstein Reviewed-by: Benno Lossin --- Makefile | 1 + rust/kernel/devres.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c62bae2b107b..bb15b86182a3 100644 --- a/Makefile +++ b/Makefile @@ -477,6 +477,7 @@ export rust_common_flags := --edition=2021 \ -Wrust_2018_idioms \ -Wunreachable_pub \ -Wclippy::all \ + -Wclippy::as_ptr_cast_mut \ -Wclippy::ignored_unit_patterns \ -Wclippy::mut_mut \ -Wclippy::needless_bitwise_bool \ diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs index 3a9d998ec371..598001157293 100644 --- a/rust/kernel/devres.rs +++ b/rust/kernel/devres.rs @@ -143,7 +143,7 @@ fn remove_action(this: &Arc) { bindings::devm_remove_action_nowarn( this.dev.as_raw(), Some(this.callback), - this.as_ptr() as _, + this.as_ptr().cast_mut().cast(), ) }; From patchwork Sun Mar 9 16:00:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamir Duberstein X-Patchwork-Id: 14008637 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.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 8EDCB1F09AE; Sun, 9 Mar 2025 16:01:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741536081; cv=none; b=NLVs0xjmQ7IBtXLvoouv1b+RP//CimAsYjZIWgvfYntaf1UbP7oB/kG5RzPeNCypARMPGkMoew2eLCvi2dTJvueDL55WtWurmyfDNmZCVj8cIkkU83YjK+HNyp6p7ab3zWjmcPeS21OOXP3ruIBjROYRjhZrw4bj8WUXTWhawv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741536081; c=relaxed/simple; bh=fCDqTpg8R8LtqsDEh5p3KO6EZ7s18zb0MUJ5VQ0JpSU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BnVzTS/R0U1+HQD0Z5/GhvEogSTPo6AX+meRAX4H3TBZQotKW4OVnJa2BDjayJ/IkDTlDaxDOPBHQzyLUJ3Xm0vRP3brnffjxT9TavRRZAGptvvmJV5ZKNrF7+E+oRdCyl0evdTgYduKw7tS8CxVSj7QisGHBS8dsRkflMDxHJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=k7z4I8F0; arc=none smtp.client-ip=209.85.222.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k7z4I8F0" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-7c0a159ded2so383888385a.0; Sun, 09 Mar 2025 09:01:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741536078; x=1742140878; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=OoHyfUob14DvKOfpuKH2+3sQlvl6ATsOpI2+e8gy5Ok=; b=k7z4I8F0qBQ2SXhIN3887Ju/YUoP3RPMHqqhH6J5kQ/pacH9yFFDvS6Pk1glKAKv5v d0V9kQkL07ymaUp7qhiX/TzsDjNMaIdiDQVD5pcOCusUIxEw+W5OboeEKzVQLJfg4XHR kUaOvMoINxIsg1SmdfdnxuVpT/XYFxz/G4ShSHZhVQEyOXJdK//LdHCUld0vOzjri1+U Ax51QEYueHmMTBC97itMnrBXQuBCxrZ6tEmy5AMRr8Z9ovbVYWeG1Hlxd08pesmVEESD TSpesZuRjjVFUnbnaTyaizkWi7EY00yunIfvcW/VOCAdvg28PyBZHjpMojmVgQnFoIW8 eplA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741536078; x=1742140878; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OoHyfUob14DvKOfpuKH2+3sQlvl6ATsOpI2+e8gy5Ok=; b=mjC8fyyCxAorBIeXeLvzrTjZexXqGAhInI1BL1fSStO7caVTgmySKMmFrtUhcZOaKi x35qiK0TvistWJRnXOq2984O3jEX1oeYhTEWTREW7bER6GjpxSOh2hH0xc4i1Mu0dml5 XmYcRMsqTe8iXedRT3sPVFapIuQ4I1S9Nxp8U11jBsq2RCREnaABoXnE234Y5gq7Mc5Q hcSOdh6HL6spZiHNVY4NLGb9dMtoLHx6XE1CPmdN3HlZ0LSZSv4dGyhYMDP+7sVZUzUu 2VUOUI5LxJT6Ot2Y1v/q5p0OV7+xuMi/rphindAjC8WxM+TF8du4yBEaJgUJ2hgTRll5 yvyw== X-Forwarded-Encrypted: i=1; AJvYcCUKt9Y0+K3zXRvg0okrOzjXrNXAFltd4Y6N4G7bPgpUfoih9QPNo9aELslQqhtHMC3ABWgS8rzUsJQW@vger.kernel.org, AJvYcCVeA2R07XbGTjrHEGqYoY9lR8FQvNk7m/0BE1Muw8+GJZQcB4ZhlFqXSo0f+j6u41WSMNQIkxcWM7UaTp0=@vger.kernel.org, AJvYcCW85QS50W447ETSs7KMGtgZlbbxOQSj82Obgfy4rV9EVqsMUQRD0dGVBKbQYh2ffXfkHtTNnrBu3vl7031o+ec7@vger.kernel.org, AJvYcCW8ULSXhQDmV18cR9c2MJppBJpWOt5KD3JNJ8aiXD7/xOwCQMXyll98lKXvDAf0HzwxcgJtkocbhVIO4xRlhMM=@vger.kernel.org, AJvYcCWtzzvXI8C2YBu3ygGXFl7XTqpyM0wOKeoA4g3+GKc1eH3XKu5Pp2uOU02JhO0M+K8Q4aGJl3WpT/BB@vger.kernel.org, AJvYcCXl6JNhjfGdAtymt1u3XxpnqO5+ADcypQ8DlKTj9Azv+hvhV5L5Cxai2fSERXxexl1d5mVSdX1g/jOoAzvi@vger.kernel.org X-Gm-Message-State: AOJu0YwzvF3P+yMsxDnEgGPFrwTcIujBannl1IKhNYUONVmKYzUsJorQ r9oWCt5KjG+6c5/ZRwUjZFWXukCkxIVnzK8yV0ci+ZtukLXBxZ8g X-Gm-Gg: ASbGncty1dnLqt8woqC9qhaLBIz0AV/G8P5a9Em7aXYZRcIj8YwgTKm3jpp2NtWS8iE 6hx9lhONSmkC5AErhUuGVk+l/m3/mA258MHTPEYGGe0u/MIjfS9wewV8Lfy4cF0scT4TXnAVhYm lCg9IoY7/e0DZrMr3WCnadGlb8GNl8zFdVTKFYQ4SgGKTBafQ/0IIqAMKBfn6HWtjewIbktwqyR pYcPR3AhVbV5dOWHy6xb9UpXfZERnJj5W916NMz0pCIx5LJ5nYwgAlvNaJ+exlis7m8c7Nhz8wT FM7LSQCxCjmaGmDObhEh41oGigIAu6q6UEbmCJ9wBlBAWFOMnlvPXgWjDyD5IeI15eZa10sVOef Kwg== X-Google-Smtp-Source: AGHT+IEGIms/3vQ/gA6TWTl1LA1mEziWYzrUFTTavtJ4+yKo7aU9mNn3PmyPTfifXVtGJo5A5tDUKQ== X-Received: by 2002:a05:620a:6190:b0:7c3:c1e0:4df8 with SMTP id af79cd13be357-7c4e619e37amr1556037185a.50.1741536078147; Sun, 09 Mar 2025 09:01:18 -0700 (PDT) Received: from [192.168.1.159] ([2600:4041:5be7:7c00:f0dd:49a0:8ab6:b3b6]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c3e534d38dsm512531485a.44.2025.03.09.09.01.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Mar 2025 09:01:16 -0700 (PDT) From: Tamir Duberstein Date: Sun, 09 Mar 2025 12:00:44 -0400 Subject: [PATCH v2 5/5] rust: enable `clippy::as_underscore` lint Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250309-ptr-as-ptr-v2-5-25d60ad922b7@gmail.com> References: <20250309-ptr-as-ptr-v2-0-25d60ad922b7@gmail.com> In-Reply-To: <20250309-ptr-as-ptr-v2-0-25d60ad922b7@gmail.com> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , 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 , Greg Kroah-Hartman , "Rafael J. Wysocki" , Brendan Higgins , David Gow , Rae Moar , Bjorn Helgaas , Luis Chamberlain , Russ Weight , Rob Herring , Saravana Kannan Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-pci@vger.kernel.org, linux-block@vger.kernel.org, devicetree@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev In Rust 1.63.0, Clippy introduced the `as_underscore` lint [1]: > The conversion might include lossy conversion or a dangerous cast that > might go undetected due to the type being inferred. > > The lint is allowed by default as using `_` is less wordy than always > specifying the type. Always specifying the type is especially helpful in function call contexts where the inferred type may change at a distance. Specifying the type also allows Clippy to spot more cases of `useless_conversion`. The primary downside is the need to specify the type in trivial getters. There are 4 such functions: 3 have become slightly less ergonomic, 1 was revealed to be a `useless_conversion`. While this doesn't eliminate unchecked `as` conversions, it makes such conversions easier to scrutinize. It also has the slight benefit of removing a degree of freedom on which to bikeshed. Thus apply the changes and enable the lint -- no functional change intended. Link: https://rust-lang.github.io/rust-clippy/master/index.html#as_underscore [1] Signed-off-by: Tamir Duberstein --- Makefile | 1 + rust/kernel/block/mq/operations.rs | 2 +- rust/kernel/block/mq/request.rs | 2 +- rust/kernel/device_id.rs | 2 +- rust/kernel/devres.rs | 15 ++++++++------- rust/kernel/error.rs | 2 +- rust/kernel/firmware.rs | 2 +- rust/kernel/io.rs | 18 +++++++++--------- rust/kernel/miscdevice.rs | 2 +- rust/kernel/of.rs | 6 +++--- rust/kernel/pci.rs | 9 ++++++--- rust/kernel/str.rs | 8 ++++---- rust/kernel/workqueue.rs | 2 +- 13 files changed, 38 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index bb15b86182a3..2af40bfed9ce 100644 --- a/Makefile +++ b/Makefile @@ -478,6 +478,7 @@ export rust_common_flags := --edition=2021 \ -Wunreachable_pub \ -Wclippy::all \ -Wclippy::as_ptr_cast_mut \ + -Wclippy::as_underscore \ -Wclippy::ignored_unit_patterns \ -Wclippy::mut_mut \ -Wclippy::needless_bitwise_bool \ diff --git a/rust/kernel/block/mq/operations.rs b/rust/kernel/block/mq/operations.rs index 864ff379dc91..d18ef55490da 100644 --- a/rust/kernel/block/mq/operations.rs +++ b/rust/kernel/block/mq/operations.rs @@ -101,7 +101,7 @@ impl OperationsVTable { if let Err(e) = ret { e.to_blk_status() } else { - bindings::BLK_STS_OK as _ + bindings::BLK_STS_OK as u8 } } diff --git a/rust/kernel/block/mq/request.rs b/rust/kernel/block/mq/request.rs index 10c6d69be7f3..bcf2b73d9189 100644 --- a/rust/kernel/block/mq/request.rs +++ b/rust/kernel/block/mq/request.rs @@ -125,7 +125,7 @@ pub fn end_ok(this: ARef) -> Result<(), ARef> { // success of the call to `try_set_end` guarantees that there are no // `ARef`s pointing to this request. Therefore it is safe to hand it // back to the block layer. - unsafe { bindings::blk_mq_end_request(request_ptr, bindings::BLK_STS_OK as _) }; + unsafe { bindings::blk_mq_end_request(request_ptr, bindings::BLK_STS_OK as u8) }; Ok(()) } diff --git a/rust/kernel/device_id.rs b/rust/kernel/device_id.rs index e5859217a579..4063f09d76d9 100644 --- a/rust/kernel/device_id.rs +++ b/rust/kernel/device_id.rs @@ -82,7 +82,7 @@ impl IdArray { unsafe { raw_ids[i] .as_mut_ptr() - .byte_offset(T::DRIVER_DATA_OFFSET as _) + .byte_add(T::DRIVER_DATA_OFFSET) .cast::() .write(i); } diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs index 598001157293..20159b7c9293 100644 --- a/rust/kernel/devres.rs +++ b/rust/kernel/devres.rs @@ -45,7 +45,7 @@ struct DevresInner { /// # Example /// /// ```no_run -/// # use kernel::{bindings, c_str, device::Device, devres::Devres, io::{Io, IoRaw}}; +/// # use kernel::{bindings, c_str, device::Device, devres::Devres, ffi::c_void, io::{Io, IoRaw}}; /// # use core::ops::Deref; /// /// // See also [`pci::Bar`] for a real example. @@ -59,19 +59,19 @@ struct DevresInner { /// unsafe fn new(paddr: usize) -> Result{ /// // SAFETY: By the safety requirements of this function [`paddr`, `paddr` + `SIZE`) is /// // valid for `ioremap`. -/// let addr = unsafe { bindings::ioremap(paddr as _, SIZE as _) }; +/// let addr = unsafe { bindings::ioremap(paddr as u64, SIZE) }; /// if addr.is_null() { /// return Err(ENOMEM); /// } /// -/// Ok(IoMem(IoRaw::new(addr as _, SIZE)?)) +/// Ok(IoMem(IoRaw::new(addr as usize, SIZE)?)) /// } /// } /// /// impl Drop for IoMem { /// fn drop(&mut self) { /// // SAFETY: `self.0.addr()` is guaranteed to be properly mapped by `Self::new`. -/// unsafe { bindings::iounmap(self.0.addr() as _); }; +/// unsafe { bindings::iounmap(self.0.addr() as *mut c_void); }; /// } /// } /// @@ -115,8 +115,9 @@ fn new(dev: &Device, data: T, flags: Flags) -> Result>> { // SAFETY: `devm_add_action` guarantees to call `Self::devres_callback` once `dev` is // detached. - let ret = - unsafe { bindings::devm_add_action(dev.as_raw(), Some(inner.callback), data as _) }; + let ret = unsafe { + bindings::devm_add_action(dev.as_raw(), Some(inner.callback), data.cast_mut().cast()) + }; if ret != 0 { // SAFETY: We just created another reference to `inner` in order to pass it to @@ -130,7 +131,7 @@ fn new(dev: &Device, data: T, flags: Flags) -> Result>> { } fn as_ptr(&self) -> *const Self { - self as _ + self } fn remove_action(this: &Arc) { diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs index 8654d52b0bb9..eb8fa52f08ba 100644 --- a/rust/kernel/error.rs +++ b/rust/kernel/error.rs @@ -152,7 +152,7 @@ pub(crate) fn to_blk_status(self) -> bindings::blk_status_t { /// Returns the error encoded as a pointer. pub fn to_ptr(self) -> *mut T { // SAFETY: `self.0` is a valid error due to its invariant. - unsafe { bindings::ERR_PTR(self.0.get() as _).cast() } + unsafe { bindings::ERR_PTR(self.0.get() as isize).cast() } } /// Returns a string representing the error, if one exists. diff --git a/rust/kernel/firmware.rs b/rust/kernel/firmware.rs index c5162fdc95ff..9a279330261c 100644 --- a/rust/kernel/firmware.rs +++ b/rust/kernel/firmware.rs @@ -61,7 +61,7 @@ fn request_internal(name: &CStr, dev: &Device, func: FwFunc) -> Result { // SAFETY: `pfw` is a valid pointer to a NULL initialized `bindings::firmware` pointer. // `name` and `dev` are valid as by their type invariants. - let ret = unsafe { func.0(pfw as _, name.as_char_ptr(), dev.as_raw()) }; + let ret = unsafe { func.0(pfw, name.as_char_ptr(), dev.as_raw()) }; if ret != 0 { return Err(Error::from_errno(ret)); } diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs index d4a73e52e3ee..d375eed73dc8 100644 --- a/rust/kernel/io.rs +++ b/rust/kernel/io.rs @@ -5,7 +5,7 @@ //! C header: [`include/asm-generic/io.h`](srctree/include/asm-generic/io.h) use crate::error::{code::EINVAL, Result}; -use crate::{bindings, build_assert}; +use crate::{bindings, build_assert, ffi::c_void}; /// Raw representation of an MMIO region. /// @@ -56,7 +56,7 @@ pub fn maxsize(&self) -> usize { /// # Examples /// /// ```no_run -/// # use kernel::{bindings, io::{Io, IoRaw}}; +/// # use kernel::{bindings, ffi::c_void, io::{Io, IoRaw}}; /// # use core::ops::Deref; /// /// // See also [`pci::Bar`] for a real example. @@ -70,19 +70,19 @@ pub fn maxsize(&self) -> usize { /// unsafe fn new(paddr: usize) -> Result{ /// // SAFETY: By the safety requirements of this function [`paddr`, `paddr` + `SIZE`) is /// // valid for `ioremap`. -/// let addr = unsafe { bindings::ioremap(paddr as _, SIZE as _) }; +/// let addr = unsafe { bindings::ioremap(paddr as u64, SIZE) }; /// if addr.is_null() { /// return Err(ENOMEM); /// } /// -/// Ok(IoMem(IoRaw::new(addr as _, SIZE)?)) +/// Ok(IoMem(IoRaw::new(addr as usize, SIZE)?)) /// } /// } /// /// impl Drop for IoMem { /// fn drop(&mut self) { /// // SAFETY: `self.0.addr()` is guaranteed to be properly mapped by `Self::new`. -/// unsafe { bindings::iounmap(self.0.addr() as _); }; +/// unsafe { bindings::iounmap(self.0.addr() as *mut c_void); }; /// } /// } /// @@ -119,7 +119,7 @@ pub fn $name(&self, offset: usize) -> $type_name { let addr = self.io_addr_assert::<$type_name>(offset); // SAFETY: By the type invariant `addr` is a valid address for MMIO operations. - unsafe { bindings::$name(addr as _) } + unsafe { bindings::$name(addr as *const c_void) } } /// Read IO data from a given offset. @@ -131,7 +131,7 @@ pub fn $try_name(&self, offset: usize) -> Result<$type_name> { let addr = self.io_addr::<$type_name>(offset)?; // SAFETY: By the type invariant `addr` is a valid address for MMIO operations. - Ok(unsafe { bindings::$name(addr as _) }) + Ok(unsafe { bindings::$name(addr as *const c_void) }) } }; } @@ -148,7 +148,7 @@ pub fn $name(&self, value: $type_name, offset: usize) { let addr = self.io_addr_assert::<$type_name>(offset); // SAFETY: By the type invariant `addr` is a valid address for MMIO operations. - unsafe { bindings::$name(value, addr as _, ) } + unsafe { bindings::$name(value, addr as *mut c_void) } } /// Write IO data from a given offset. @@ -160,7 +160,7 @@ pub fn $try_name(&self, value: $type_name, offset: usize) -> Result { let addr = self.io_addr::<$type_name>(offset)?; // SAFETY: By the type invariant `addr` is a valid address for MMIO operations. - unsafe { bindings::$name(value, addr as _) } + unsafe { bindings::$name(value, addr as *mut c_void) } Ok(()) } }; diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs index e14433b2ab9d..2c66e926bffb 100644 --- a/rust/kernel/miscdevice.rs +++ b/rust/kernel/miscdevice.rs @@ -33,7 +33,7 @@ impl MiscDeviceOptions { pub const fn into_raw(self) -> bindings::miscdevice { // SAFETY: All zeros is valid for this C type. let mut result: bindings::miscdevice = unsafe { MaybeUninit::zeroed().assume_init() }; - result.minor = bindings::MISC_DYNAMIC_MINOR as _; + result.minor = bindings::MISC_DYNAMIC_MINOR as i32; result.name = self.name.as_char_ptr(); result.fops = create_vtable::(); result diff --git a/rust/kernel/of.rs b/rust/kernel/of.rs index 04f2d8ef29cb..40d1bd13682c 100644 --- a/rust/kernel/of.rs +++ b/rust/kernel/of.rs @@ -22,7 +22,7 @@ unsafe impl RawDeviceId for DeviceId { const DRIVER_DATA_OFFSET: usize = core::mem::offset_of!(bindings::of_device_id, data); fn index(&self) -> usize { - self.0.data as _ + self.0.data as usize } } @@ -34,10 +34,10 @@ pub const fn new(compatible: &'static CStr) -> Self { // SAFETY: FFI type is valid to be zero-initialized. let mut of: bindings::of_device_id = unsafe { core::mem::zeroed() }; - // TODO: Use `clone_from_slice` once the corresponding types do match. + // TODO: Use `copy_from_slice` once stabilized for `const`. let mut i = 0; while i < src.len() { - of.compatible[i] = src[i] as _; + of.compatible[i] = src[i]; i += 1; } diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 63218abb7a25..a925732f6c7a 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -166,7 +166,7 @@ unsafe impl RawDeviceId for DeviceId { const DRIVER_DATA_OFFSET: usize = core::mem::offset_of!(bindings::pci_device_id, driver_data); fn index(&self) -> usize { - self.0.driver_data as _ + self.0.driver_data } } @@ -201,7 +201,10 @@ macro_rules! pci_device_table { /// MODULE_PCI_TABLE, /// ::IdInfo, /// [ -/// (pci::DeviceId::from_id(bindings::PCI_VENDOR_ID_REDHAT, bindings::PCI_ANY_ID as _), ()) +/// ( +/// pci::DeviceId::from_id(bindings::PCI_VENDOR_ID_REDHAT, bindings::PCI_ANY_ID as u32), +/// (), +/// ) /// ] /// ); /// @@ -317,7 +320,7 @@ unsafe fn do_release(pdev: &Device, ioptr: usize, num: i32) { // `ioptr` is valid by the safety requirements. // `num` is valid by the safety requirements. unsafe { - bindings::pci_iounmap(pdev.as_raw(), ioptr as _); + bindings::pci_iounmap(pdev.as_raw(), ioptr as *mut kernel::ffi::c_void); bindings::pci_release_region(pdev.as_raw(), num); } } diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index 6a1a982b946d..0b80a119d5f0 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -692,9 +692,9 @@ fn new() -> Self { pub(crate) unsafe fn from_ptrs(pos: *mut u8, end: *mut u8) -> Self { // INVARIANT: The safety requirements guarantee the type invariants. Self { - beg: pos as _, - pos: pos as _, - end: end as _, + beg: pos as usize, + pos: pos as usize, + end: end as usize, } } @@ -719,7 +719,7 @@ pub(crate) unsafe fn from_buffer(buf: *mut u8, len: usize) -> Self { /// /// N.B. It may point to invalid memory. pub(crate) fn pos(&self) -> *mut u8 { - self.pos as _ + self.pos as *mut u8 } /// Returns the number of bytes written to the formatter. diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs index 8ff54105be3f..d03f3440cb5a 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -198,7 +198,7 @@ pub fn enqueue(&self, w: W) -> W::EnqueueOutput unsafe { w.__enqueue(move |work_ptr| { bindings::queue_work_on( - bindings::wq_misc_consts_WORK_CPU_UNBOUND as _, + bindings::wq_misc_consts_WORK_CPU_UNBOUND as i32, queue_ptr, work_ptr, )