Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 BF8DC47669D for ; Fri, 24 Jul 2026 23:38:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784936325; cv=none; b=PGAcqdzbwoftOJCbMssCus2wWXLhDa9Alyri7y5bpUottgEXlSnN95uOC+eACYTrnI55DI+AWUws48/ILAJVZoDg9ZjrKrAtYsXTkfiHgA4Y30TASI3DWc1qc6QYQmH5nyKry/VIjcSLFcD2G82N44qtkHDM4WKpvL0OxmNVhIw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784936325; c=relaxed/simple; bh=kKKmq7jufGIPyfk8VrnaKD8ZMuWoYzZl5hWNdLhisvg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rTNQLSHfby+TOWUlNerhhgC4NSoUW34TC7YhNGnsvTdHgywz0O99dtNIjMYb+lDU6t4SjtruAT7xPsrEYCsyd47wccva/TRTl9hVGmjiAlfjb/bQqkJkzBh+F91j1wBFssz+d14cBmwXGpdxzmzRmvTtfq161WllRac1A7aLjho= 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=f0le2ZHr; arc=none smtp.client-ip=209.85.128.41 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="f0le2ZHr" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4956869750eso7176845e9.2 for ; Fri, 24 Jul 2026 16:38:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784936321; x=1785541121; 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:content-type; bh=QUkrcS3bT47EateKo7yg7zIM6h/BJq/nEtdQpmc8z04=; b=f0le2ZHr5pmz2++EvZm4f8hvpnqdGYriWvb9cox0exePPzKfDPZ5xhM2wFtuj0DZ+W OFVoQkKEIxRIgEjpj5voPhsN3jA8bEaieHxRExsI1KMzfprX+tQZ5KIxU/S+Zwns8K1U X4QJok12Hf3zEBrEEY3fXAyxje0Em7w6TdKkpOhb18VgM9+FhV7cI553byzNWt9xcaxN XmJm3ywk4PygEwbhfhtseyCCsoHZT/Tkt4S/YH0FFQCLMNF69EEHzc2p/UBuil3yBWWB jgmRXSUgP0xzdbYOwl/2+S4gh8vvj/jmIGFnUdf/VaCMb8vroyaQycP8OywjhUzt6HuU qNcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784936321; x=1785541121; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=QUkrcS3bT47EateKo7yg7zIM6h/BJq/nEtdQpmc8z04=; b=j+rn1Vwxmg5w+ZCIARzQTs0P29EsDUkrWgHIY1qY/DW/i41cvz2ybSeO6xabx6GD0e ffA1Kb+SHHeht6OWBErb70hCzJzIUIR/ozQE5r63SSyn47lUaBG/MvZnv95NlgtRMopJ pwPyupxvab2+2JPG5Y8RLone2ccCTEFgy+9/8cYw7RXJmFALx+Z1jixbpPx5nCgCt8qb c+M4+k+ug+KvS+Z9gdyby0dmlZ7AefuixwTRR9FV5xJjVpZvCFSRRV5dvqaPy4xjaH+t ExGQWAqpML5Q36tfDn32LoU8urqKUOuZpOSbnef4m2q+0H0VezFOCsDyIcmTYQaKtrQm XQSw== X-Forwarded-Encrypted: i=1; AHgh+RqhkSu6alqtTeKkcAeWDnq49lsGO/s7fVzLa95DfjaSgKK7yWmsoLm8YiBi1R4f5C2bDJ6+H6dRsjluHfQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyPn3VVBPU+MvYfdLeFaM9QVXkme3dlFmDdXkI7AfgPkQGWNcrt 5/0i/ZzjCUjM/uHTIdFiT+s/wYbJPj68kh8UYewmghhGKtDhO2jmoXNP X-Gm-Gg: AR+sD11EGLtDbh6R3yrsiMR0L5XJHjI9Vc6ziecsQFYpED14m5UyKH+j06QjyD2f8Kb MMRWCvD7S/nxF6UsRgCw9iaY1Hptrz19O6vBC79+ucz+X8khCMpf4Bt/ZaQRUoMed4sf0w5ra6/ +AWUvC6T42M2VrcQsFzVXGZ/PQ4gU3vTKqMAV7xUQpDsoxBFzOhRJztloqZyex30/Cqn+K5ko6Y nTpAObxRJol3ifi5Fuyotg5fTuiQaYfLDxb+id3WpMVjY7PyBEtKBt0dMDDhoMgIAimlkw62Uu0 AFJ2RxAUskGRhds+icK1Js/U3INFhvkJlWsX59352qLd1QeK0VuXaYPW1X5R4zc1g9f25ywfszT /efIPLCcUnwFdYbB/ffx8Osr9rQXmarmedrIaXHq+13SgugfJTmdBIbtjVMdyXx/j2Jx37wg1tR hz3i06niNEaBhE2+FV8epnFPWoToI31sPcN3kf90VzB8fYTtUUKr3MiUI/ X-Received: by 2002:a05:600c:4ec8:b0:495:3f68:699b with SMTP id 5b1f17b1804b1-496b56f3705mr3664245e9.9.1784936321038; Fri, 24 Jul 2026 16:38:41 -0700 (PDT) Received: from Cian.taile2c8f4.ts.net ([2a02:8084:d03:fa00:819d:8e1d:c966:142d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4957b5f35a1sm72226775e9.0.2026.07.24.16.38.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2026 16:38:40 -0700 (PDT) From: Cian McGuire To: Miguel Ojeda Cc: Boqun Feng , Gary Guo , Alice Ryhl , Lyude Paul , Daniel Almeida , =?UTF-8?q?Onur=20=C3=96zkan?= , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Tamir Duberstein , Alexandre Courbot , FUJITA Tomonori , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Cian McGuire Subject: [PATCH v2 3/4] rust: list: document safety of List::remove Date: Sat, 25 Jul 2026 00:38:24 +0100 Message-ID: <20260724233825.1321247-3-cianmcguire167@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260724233825.1321247-1-cianmcguire167@gmail.com> References: <20260724233825.1321247-1-cianmcguire167@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The call to `ListLinks::fields(T::view_links(item))` in `List::remove` had its SAFETY comment left as "TODO.". This call chains two separate safety requirements that need to be discharged together. `view_links` requires its pointer argument to point at a valid value. `item` is a `&T`, and Rust's reference guarantees mean it is always a valid, non-dangling pointer to a live value of type `T`, so this is satisfied without needing anything beyond ordinary reference validity (`view_links`'s own doc comment notes it "need not be in an `Arc`", to head off the assumption that anything more is required here). `fields` requires its pointer argument to be dereferenceable. The pointer returned by `view_links` is guaranteed dereferenceable by its own documented guarantees: it is either the pointer from a preceding `prepare_to_insert` call, which itself must point at a valid value, or it points at a read-only `ListLinks` with null fields. Either way, `fields`'s requirement is satisfied. Suggested-by: Miguel Ojeda Link: https://github.com/Rust-for-Linux/linux/issues/351 Signed-off-by: Cian McGuire --- rust/kernel/list.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rust/kernel/list.rs b/rust/kernel/list.rs index 406e3a028c55..22b497eb10c0 100644 --- a/rust/kernel/list.rs +++ b/rust/kernel/list.rs @@ -599,7 +599,12 @@ pub fn pop_front(&mut self) -> Option> { /// /// `item` must not be in a different linked list (with the same id). pub unsafe fn remove(&mut self, item: &T) -> Option> { - // SAFETY: TODO. + // SAFETY: `item` is a `&T`, and Rust's reference guarantees mean it is always a valid, + // non-dangling pointer to a live value of type `T`, satisfying `view_links`'s safety + // requirement. The pointer `view_links` returns is guaranteed dereferenceable by its own + // documented guarantees: it's either the pointer from a preceding `prepare_to_insert` + // call, which itself must point at a valid value, or it points at a read-only + // `ListLinks` with null fields. Either way, `fields`'s safety requirement is satisfied. let mut item = unsafe { ListLinks::fields(T::view_links(item)) }; // SAFETY: The user provided a reference, and reference are never dangling. // -- 2.55.0