From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 A58E4392803 for ; Fri, 24 Jul 2026 21:50:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784929832; cv=none; b=EafjDOVnP0pExV2Utb+LlMC/BKz7sTFFoSowUpCUosSW4CmWetzmFYXDjqbu5pQCsjk8WU6civQuxKIK8YXJ21CZFKhgogK8CtMIlp66wuNiv5C21hj4FvRKUPcod/WvKZ12EUvh0HoYl7ddWXHPlJ973U5zGDVKNphI2RG1TmE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784929832; c=relaxed/simple; bh=kKKmq7jufGIPyfk8VrnaKD8ZMuWoYzZl5hWNdLhisvg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CgNdlISqEWzcyVBwImv5rFeUEHLMgZHRsq6hUewhL3+NKJAm7AYRNvIdxOOAWWfowq2G9wxtaSzTOHG8A59SP9ZFw1IKYjgIEE7r9IOwZaJAqsLj88ZK+vTOkJKrPdTkYLb3TYszXYq/Q1fLHLQTDVTRd2du3NMXJwziVTV+8/g= 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=QcOG/IpG; arc=none smtp.client-ip=209.85.128.49 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="QcOG/IpG" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-49553515a8bso10389595e9.1 for ; Fri, 24 Jul 2026 14:50:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784929828; x=1785534628; 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=QcOG/IpGvAlQXqHLwClcJDIoD3eEIkONS8+eiAXnx4KENbHrFk/HZtV8+asADfpQWJ 2O+jmpoMZLvkBefibMLEr/l94tcuJ2gqAmE+FoxVBCIjZ1gcALzk1JgpGuBUgc/+lZYX b0MSdNSV/K2175mLrduolQ0KaSGJDlBpfK9HjP/pbmP6mNm7v1EaCp/KPJ4p4dpS6I64 nzRtD+HIzdXdQpDpGLQRBlzJCrOg6iwbqpL2ZuP7zJVrqo/MSPkXne+Y+khFnupEzth1 YVNOuliYzNHEJDj5FxWncCYcEY28ozl55yyJNw47TQfUa41MlVJgqc2xFV7bgPj/ALHi 1R4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784929828; x=1785534628; 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=gu/3XY0ToN9zwN7oLMLv/oLtdx1Z8F4tYeP9i9OcKPOwGVS+Zal0CNS2giQuUyQa22 B7F/R6bOrk3jvMUe6Tte5qg9hx1U4zswmR9BiRPRlKTJ1cUpAkgFROu4Gl44vtdW9A8T rF/pTq9qyCoHsJyQhS4wpOuHxhRe0IFyaPJzveljKrpL5GeMcLYvwpGIDhf3FQUAyPlL Hso0lTB0hXLKGL0WqnaM0LYa4QstVAD+hDCRZh9m8owF8GcjRNvffI2N/4QtlIak8Kmp zWyCqgczTfQgQ0AHueoCBhSOgo1fJMivEsVms3/Vaij+UsrkYeM1pYvOc2hcHKMVvNkR M4qg== X-Forwarded-Encrypted: i=1; AHgh+Ro/1kw1EXBKggGH/9tTmJgUzPojMDyCNCMLcOQ0tPDa+m0HwVdM2pVw5Zbay+7oc1vOIj7yu88i+kgOyqk=@vger.kernel.org X-Gm-Message-State: AOJu0Yy7gHLsrc1VUFwp39mfKO42j/3TEpY8o4wcZ9wkRY4AuedS/muv +AsZ036uhZJJrZVfW7FjsmQuTNBjuBceWDYZhCirSb35nUT2XaUWo350 X-Gm-Gg: AR+sD11+d1rZbdj9VgjWXzIgGsZDfpsj14DCLmjEK9m0NqofaSEZSVvP3GBc3LjDDlo bEFXicc80AgNWDclYGuYn6YSJHA6eT+r92R5MXyFnlvSh6qJ+pdW/8l87/TR9j8ex+uUEqNrG0B Butt/59aGwXQuI9ysciIlbCsWssGKvbABlxdSFPZXgMPX4LLlbgfPV5qAPrFNVNgAI0e8xIYTBn cfkjJ+9HAreCn5lViCaQ4pL9ZXmR+wYJXGfgg3nx3e05rLlJDwTeCYWaHZeYfF0WWFOUFUUw13T lcc2CSpcwtXRGbHAEIulFOYPOPGmThOXG7tq3E1gU2h4p1ZKh96fUSU8UB3dN4wNA7kuRyCaWgh u6X/szbEcQw4rXD2KvI2bIuNJYndJb3vyp0GQzq+uM0z7sVIrvbpT4Df/B8kw2DPsVHTiap6elh iZwe8rezSVIjJqOUnXS3uus0eUkF+ay1qUgVSNUnGr8nICFwk2+Jhpuftf X-Received: by 2002:a7b:c847:0:b0:495:4856:2659 with SMTP id 5b1f17b1804b1-496b56f14a9mr704945e9.9.1784929822663; Fri, 24 Jul 2026 14:50:22 -0700 (PDT) Received: from Cian.taile2c8f4.ts.net ([2a02:8084:d03:fa00:819d:8e1d:c966:142d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-496b4d8d6efsm17588265e9.0.2026.07.24.14.50.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2026 14:50:21 -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 3/4] rust: list: document safety of List::remove Date: Fri, 24 Jul 2026 22:49:39 +0100 Message-ID: <20260724214940.1070221-3-cianmcguire167@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260724214940.1070221-1-cianmcguire167@gmail.com> References: <20260724214940.1070221-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