From nobody Sun Feb 8 09:32:36 2026 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.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 B6E962E7179 for ; Thu, 5 Feb 2026 04:23:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770265416; cv=none; b=Xj/MxhoteVFs6PgHDJCNttliORzRImB+QmCbg0YhfFzK3qhqiWadx1YUuQZTwcgGo1QptpVt0INdXuZM///Dl3Gq1umomIGs4DqQ5ZqD4jELzjZ3bGNza6i86NE1vIhjRibT2j0odcgVLdmmztm7FVmRywj8hi0jdiaVJwLmY6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770265416; c=relaxed/simple; bh=jebVDHQiMzpD9h1nlRU1tfea/zh5UxIJ4reuJJpTc/8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=krAT1PNwveidQ9DCefS8JTEfHmRlcBuVc60fj0qyZPG1yDwDGZPDEXIObENx5D0G9ZlttzfBnKZylwDyuiePQRw3luVgkakVG4SXKk2iUZCjZKu/mCnrm8tClMf7LsEGeT1QK8MM3R7wY7HwCqOhVTJyHYieoDNAb+MiW0TntFU= 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=ker/U3JZ; arc=none smtp.client-ip=209.85.214.173 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="ker/U3JZ" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2a0c20ee83dso3716745ad.2 for ; Wed, 04 Feb 2026 20:23:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770265416; x=1770870216; 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; bh=EUj8Ofs9pFmUDpSvtcIVhk+ld3584XT2y4BejegH4Kg=; b=ker/U3JZZS+emZkJRaDsy0OaXqgYfHFkKaZJk52ejDIC0H/ZbiImdRF/hdaXVsZHF3 e+YXgBi32Tg8XO9LqOyJYWGg5rLmAhmCiXPNbtugq29RmJdaHaIL6dVRxjPymML3HdKg wH049lGXLYRiLbohBFZPrn3RpA15VFBqyIktL5rTBs+TjYRW2ac8P023y/P2wZwwg1pS 1iSHSZF6X80wBbGzsQcTN1bN4iLdtS908YApoauABNMEraKz8py+mzF4ShK9euwvVRGU L5Zsbr0uls1H0QFIo/LzDBlPQ978thOElYNKI/BFX3iZ9OiyhXj0AGfBn7gBlrn3aqZo yAyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770265416; x=1770870216; 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; bh=EUj8Ofs9pFmUDpSvtcIVhk+ld3584XT2y4BejegH4Kg=; b=W2fs2k/g3beSe0nnKBR1TDw3u+g4fEkOzz96QFrFjTNZ53SR3MV3lXNA2s76ZFn8eW vC4XonGClNqgvemoY/rqhHmBn/O2Zvgy3yX63VCA0uGwQJQizqlyUePDdhW+g+1MZVq0 qenpgeEHmF00EU1nD4HGruYkwWUR8ueCUfxrcV2ARDFBRkDchfIfh6EX2xO+J7HjtxFu KPoEUpKICNf6qo/MuMmokSOagffOA7aw4B3pre3D+vnlfsB2dJNcVuZb16Vkzh7Qvark uK6PvctV5xbYCBG2D5YA+ELVPEiPdm3dEzqGXm1LeybOZuh9oJk670UaKVvtSX8kr9ta a3WQ== X-Forwarded-Encrypted: i=1; AJvYcCUHRT+nR2ZSuyXwif6hajTcsmKo51H1fOx+qbEJglmqk9gBR08HXA0LV99G8ytcjc4I7xWdkH8VkhaBcjM=@vger.kernel.org X-Gm-Message-State: AOJu0YwLTVKHEYc7k45FLaiuMD6p4fOHFP5dvciaXMO3/uwrwQH6JxJT jD9zr4KgOd+vyxhfnNu0ioTiVS+IiOm9miKyAZ+qbYNEpE+IkEGBnz0k X-Gm-Gg: AZuq6aJHc8wqt4DCZ4rfCvbC5N2CjTX8KBpY37BpGEJmyGLR1yi/uDs1JOcdFbglbrX t/HQyhPEtt4x7G8uRd+Wx27rnoY0FWCtLdznZ8/HTHp6uALpTE9uG7PXahJrLFP3LP9WGHAtJY0 4CnBJOUo8xmN/tl0VTCUDzL058Z66D0tjHwm0kJzPyo4ZLUiCCdUXyQmFDBSrwNIEx7VwEWssVa QxlecpGdlKGLzVEFOl30mamp1XE1z+bgNE8cZaR2ccTyKVFSLGNzl5M+FQ26czE5wJk4mPg3hwq kTZujnKn9v4KzyHRs7jgXZaAOe0byvYHQXaKwItSptU5p4Bpic4fWzISY248B2iaElCmGustu79 ispKDdwXTblbV1OIELNHa6rzjuGjaR/PG2PtL6ZTTiKbZHqUSKXnuhpJLW/yZ5I+kdNgSmUO53a vcYFP5avFapnL2YlnJjcKuF1r+UhCes9mywLif8Pro5tIeOaJwfppNqg== X-Received: by 2002:a17:902:fc86:b0:2a9:46af:2317 with SMTP id d9443c01a7336-2a946af2a48mr2457845ad.46.1770265416039; Wed, 04 Feb 2026 20:23:36 -0800 (PST) Received: from localhost.localdomain ([103.143.106.244]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a9339664b1sm37658665ad.68.2026.02.04.20.23.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 04 Feb 2026 20:23:35 -0800 (PST) From: Muchamad Coirul Anwar To: ojeda@kernel.org Cc: boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, tamird@kernel.org, gregkh@linuxfoundation.org, fujita.tomonori@gmail.com, andrewjballance@gmail.com, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Muchamad Coirul Anwar Subject: [PATCH] rust: print: add safety comments for %pA formatting Date: Thu, 5 Feb 2026 11:21:32 +0700 Message-ID: <20260205042132.40772-1-muchamadcoirulanwar@gmail.com> X-Mailer: git-send-email 2.50.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The safety comments in `rust_fmt_argument` and `call_printk` were previously marked as TODO. This patch adds the missing safety documentation explaining why dereferencing the pointers and calling the C `_printk` function is safe in these contexts. It clarifies the contract between `lib/vsprintf.c` and the Rust implementation regarding the `%pA` format specifier. Signed-off-by: Muchamad Coirul Anwar --- rust/kernel/print.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs index 6fd84389a858..3e6ff8f42d95 100644 --- a/rust/kernel/print.rs +++ b/rust/kernel/print.rs @@ -29,7 +29,11 @@ use fmt::Write; // SAFETY: The C contract guarantees that `buf` is valid if it's less = than `end`. let mut w =3D unsafe { RawFormatter::from_ptrs(buf.cast(), end.cast())= }; - // SAFETY: TODO. + // SAFETY: The C implementation of `vsprintf` (in `lib/vsprintf.c`) sp= ecifically + // calls this function ONLY when processing the `%pA` format specifier. + // On the Rust side (`call_printk`), we guarantee that `%pA` is always= paired + // with a valid pointer to `fmt::Arguments`. + // Therefore, dereferencing `ptr` here is safe. let _ =3D w.write_fmt(unsafe { *ptr.cast::>() }); w.pos().cast() } @@ -109,7 +113,9 @@ pub unsafe fn call_printk( ) { // `_printk` does not seem to fail in any path. #[cfg(CONFIG_PRINTK)] - // SAFETY: TODO. + // SAFETY: The format string is constructed to use `%pA`, which corres= ponds to the + // pointer to `fmt::Arguments` passed as the third argument. + // Since `args` is a valid reference, casting it to a pointer is safe. unsafe { bindings::_printk( format_string.as_ptr(), --=20 2.50.0