From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BAA1399CF5 for ; Sun, 12 Jul 2026 12:35:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783859725; cv=none; b=FrfxPfxIEsi5p2GmjWeB4x+U1JY792dYUjwAc661TzUjqEaF7w1Vzz5/SPNPC4wQUvXSKukANQwAOTLXv5jlchMrMUdM6LcPpzd7gM9/OBCiUb1mr6Wx/nLriZwLhS8h9/nBJA/GUvp0lkfRJkzDKzyVsdaa1Io0QBAN1rdAfD0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783859725; c=relaxed/simple; bh=Qd6fADU3tgLMNu+GFgH22sLsNUV0tmxxK98IifKu3oY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=BFBN9y0+qE6rchKn7twkV1egAchjMcARh2cbNgBOnEJ2deefGMrELPsfnSUZho9DqrkgfDPS42Pk3CSh/RkYRgNmfFGGFsnujMXcwha3c3Id15vl38L1QWiYLUPdYnUGjhXD+6KLc49pJ1c5F5jmVLz9AV8A1FrGfIZ8vXztY4w= 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=MFz/Z/7b; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MFz/Z/7b" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-c9ef3e1337fso1440812a12.2 for ; Sun, 12 Jul 2026 05:35:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783859724; x=1784464524; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=6WA/Yp2D4HqvQ5OTI3/NmFxLywTKNdInMVr/lxCPnUI=; b=MFz/Z/7bkLH05MWxnfvB8R6iGkRYqE1u/U3P1f5zn9kiUtr9EJ/vVt1AeCK5gaSgtK zqWBQzGAvPbm5AdcAHx/ltxsz2KU9fj2V1vk4Tfm1vhpANtmsUg7/E+YTaYc1SsolT6r eLHcdNOCv3TfD89H//9CM4jiZXjEd6+szRTiLRYPqs2vA7Sg+W1lKj3kZPh9dXknIYNr jKgYXcu4c7yWZETsvREo87AObIKYFsrmCb0bOQDhjY/uq0DdUZE2ZylLKl2sFj8ZXI64 zMrGlh8nupoWy+XjF16gpTgN3vgjf/kvXKOXR7l70tXotxoUhKgLwB0rtpAHll4FIONY u3Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783859724; x=1784464524; h=content-transfer-encoding:mime-version: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=6WA/Yp2D4HqvQ5OTI3/NmFxLywTKNdInMVr/lxCPnUI=; b=AuooV6t7JdGfyBQkEo0snjJBfXWLwRRej6CTSCa0mFOW6H0qw2n6dyq0j2/vkyYrSW utuUizbeu+oartKgKD4Ppn8Q0QDvOlCKGVkD0ycGGUXYOhhLVBoYSse1aZJ5WY3wQnxr zgpHM/OHdhmnPYpZT0X7UfMkHOANSdXFTKRtXfIJxHzr9GI3Q5olpod1GBm0faTJgBRq s/xfXdKTVhROL6XkYsvGd4gprrVPsAoSz7hdoMWjpOKPTc4tBniQb68cBghsRmHFxVGK AAYKzg9Hpp5iybZCIIgqvXhJXumPkh6We+uDq+mnHMCFYhzfSS8ai8aO2WR4gExcV502 YBAg== X-Forwarded-Encrypted: i=1; AHgh+Rq6cQKhbr+/7hbuIGrynjQhAUCD9iFZsGJ5obi9jm9H0N7hGwT9Gx7ohwR69TZ9i9q5WxOMphNJOU7oFZs=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+YglhDum2eY5GcyHxKQJlyI0+FnJ5Cs6pm9MBix/4ih8PxYcm 7BAEtc1yCtWAU8vZBmyINHuGTpxm5YR014D70+/7kpFtG9shRi5KVMJottN+49KD X-Gm-Gg: AfdE7cnj1KuPdvpRU8LnrLCcZpmX/Jb+XRT+6EyinPATg6vArcF2y0zETsXPEe5l3vy mmnHwN3+9YN3ntIhm9GRcE+8JvQe+zlia7bpMvDGb6Ua+RqdxsXmH44XubiQirzHFrAe4UH8o3B eotUbq7taGL/P4cFkurJJ1ykJt/nrXyHiiUzgn9JYOCRdWz8dsuM13lXI3tZyAyMxPyrhXxK1Vv HfYVo1f2A6tGJohEaMYYkcGNaxg5Xc5hTiJ39rDQS4TR6e2HKy8+PxcQowKu5I3p9j/L9ASigvw v3PBKM9vDgnVv0R8oKZ7yIwwId/rAc40ONy10cg8R9/NA5VYaJIB96J4zW1gX1XSrRDQVlpbArd M6bjYt/1QqC8bfWsvj8rh4+3M6s348lKl6xqd07ATYPYPupPGLMXnOSUeb1lEeYf2Ip/uK7BKd0 pKog68Ly4MZUibiGHE6HTAtpJD8ourDi6MDbUU0G5i X-Received: by 2002:a05:6a20:c998:b0:3c0:9c1a:893f with SMTP id adf61e73a8af0-3c110f7f555mr5553017637.71.1783859723782; Sun, 12 Jul 2026 05:35:23 -0700 (PDT) Received: from Excalibur.localdomain ([157.51.238.219]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-313c50c70c9sm16540072eec.29.2026.07.12.05.35.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jul 2026 05:35:23 -0700 (PDT) From: Christopher Joshy To: ojeda@kernel.org Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Christopher Joshy Subject: [[PATCH]] rust: kernel: add SAFETY comments in aref doc example Date: Sun, 12 Jul 2026 12:35:17 +0000 Message-ID: <20260712123517.392-1-christopherjoshy4@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Replace TODO safety comments with proper explanations in the `ARef::into_raw` doc example. For the `unsafe impl AlwaysRefCounted`, explain that the empty implementation is trivially sound since `Empty` has no data. For the `ARef::from_raw` call, explain that the pointer is valid because it is derived from a valid reference. Link: https://github.com/Rust-for-Linux/linux/issues/351 Signed-off-by: Christopher Joshy --- rust/kernel/sync/aref.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rust/kernel/sync/aref.rs b/rust/kernel/sync/aref.rs index b721b2e00..932343799 100644 --- a/rust/kernel/sync/aref.rs +++ b/rust/kernel/sync/aref.rs @@ -124,7 +124,8 @@ pub unsafe fn from_raw(ptr: NonNull) -> Self { /// /// struct Empty {} /// - /// # // SAFETY: TODO. + /// # // SAFETY: `Empty` has no data, so `inc_ref` and `dec_ref` being no-ops is trivially + /// # // sound. /// unsafe impl AlwaysRefCounted for Empty { /// fn inc_ref(&self) {} /// unsafe fn dec_ref(_obj: NonNull) {} @@ -132,7 +133,8 @@ pub unsafe fn from_raw(ptr: NonNull) -> Self { /// /// let mut data = Empty {}; /// let ptr = NonNull::::new(&mut data).unwrap(); - /// # // SAFETY: TODO. + /// # // SAFETY: `ptr` is derived from a valid reference and is therefore non-null, properly + /// # // aligned, and points to a valid `Empty` instance. /// let data_ref: ARef = unsafe { ARef::from_raw(ptr) }; /// let raw_ptr: NonNull = ARef::into_raw(data_ref); /// -- 2.43.0