Message ID | 20240116160141.165951-3-kernel@valentinobst.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-27554-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp353766dye; Tue, 16 Jan 2024 08:03:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IE75U3AOjld51vh2DM2fUgzkbIvT0+FiN+auLl3Gj4aoGupnwnClg8SDhB9NZv/4qmPp0zH X-Received: by 2002:a05:6871:d30c:b0:204:c0:5db3 with SMTP id pn12-20020a056871d30c00b0020400c05db3mr9786172oac.13.1705421012885; Tue, 16 Jan 2024 08:03:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705421012; cv=none; d=google.com; s=arc-20160816; b=GW0niaF3UXD0LUQ1wOObcJFr6+6eg6wJ/72f7jPxeeDB5RdltEtBYhvl/+MYfxfokc MWqXsTnuoV93fwuOIuv2ehSUbtxLYTBGFpkBQR7xOiQseXA+LbCZsZ3F/rHKbm7xuTyo AfLfgKwcwto6/+TqOwVZ423Q4f8fE1qMbYPqCdvdkV5En5/rCUiqkTZlowtbQ/HXk9x5 g5q4haF8NVfwhMlgknNO6ZUFGhszq9CxYf3CUJB3cC17PRs5DQbQQJGNFV1+cVgbXkPH +QrTLvOFWbs5ARIb46o6etx2wxMvIjxSKJdHlDn4n+LI7/IL0sWXDoc4K/qH/OYwZJ21 m+mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from; bh=Bb349fvwXSjnN4V0GLzjJRdZzoRZLmEwtKL7jY3CLSU=; fh=mB5qiQ7ps5IWvjuQS9+zcxjK3ZInVolb8UwIN1mvAmg=; b=nbi02NyCZ3hOTjnVXFEep9RdpphxrkhLfVyltfdMkRolmf2pxuca6pU9QxTUwYjjzQ dmCvM0fQ6OGZQCTXNixgsuTWOlAJY988hLkiLDtqhwWVRhMfoKvY/iUu52c6y3ysIMT6 /fYCEKtSw7gU6gkRzeFjt17G4IFCbpycQjkdkYGm/dzuZhBh6dVBqXMMgTTFYJISAkCF xwys80cCnDEmvo9rXceCgoutiDmEqILucJ7HzqjF4GmeVKsircDIUJRGT9K40m/H8ZDt pzu1IdWRBHQOt28th/mK/xbThoUt2obE+69NkF5GpuighVs6Y58XKIFFfmWT1H4Fv0fs E/iw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-27554-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27554-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id js12-20020a056870bacc00b001fb4c57432csi3993365oab.185.2024.01.16.08.03.32 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 08:03:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27554-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-27554-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27554-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 9EA432836D1 for <ouuuleilei@gmail.com>; Tue, 16 Jan 2024 16:03:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 631F61CAA5; Tue, 16 Jan 2024 16:02:56 +0000 (UTC) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F025C1C686; Tue, 16 Jan 2024 16:02:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=valentinobst.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=valentinobst.de Received: from localhost.localdomain ([217.245.156.100]) by mrelayeu.kundenserver.de (mreue011 [213.165.67.97]) with ESMTPSA (Nemesis) id 1MeToK-1qpL9E40VY-00aWQh; Tue, 16 Jan 2024 17:02:37 +0100 From: Valentin Obst <kernel@valentinobst.de> To: Miguel Ojeda <ojeda@kernel.org>, Alex Gaynor <alex.gaynor@gmail.com>, Wedson Almeida Filho <wedsonaf@gmail.com> Cc: Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>, =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= <bjorn3_gh@protonmail.com>, Benno Lossin <benno.lossin@proton.me>, Andreas Hindborg <a.hindborg@samsung.com>, Alice Ryhl <aliceryhl@google.com>, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Valentin Obst <kernel@valentinobst.de> Subject: [PATCH 02/13] rust: error: move unsafe block into function call Date: Tue, 16 Jan 2024 17:01:27 +0100 Message-ID: <20240116160141.165951-3-kernel@valentinobst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240116160141.165951-1-kernel@valentinobst.de> References: <20240116160141.165951-1-kernel@valentinobst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version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jG/PeBxM3CAKHgOwJC9VWvsvujFS6bcPBZ2e19K3AfwqJBDd14XptY7Oiqinl OcOZS0NE1nLQe3YtVIbn/KkuaGkc7EqApKXYGscg9nzHTFd/FYGLNCo05DCBs5kw64+BGScW3 h6skzvWUQCoZaRPif6kgfLjDRyCZuQU5Jgd0= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788263543792379931 X-GMAIL-MSGID: 1788263543792379931 |
Series |
rust: kernel: documentation improvements
|
|
Commit Message
Valentin Obst
Jan. 16, 2024, 4:01 p.m. UTC
The `from_err_ptr` function is safe. There is no need for the call to it
to be inside the unsafe block.
Signed-off-by: Valentin Obst <kernel@valentinobst.de>
---
rust/kernel/error.rs | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
Comments
On Tue, Jan 16, 2024 at 11:05 AM Valentin Obst <kernel@valentinobstde> wrote: > > The `from_err_ptr` function is safe. There is no need for the call to it > to be inside the unsafe block. > > Signed-off-by: Valentin Obst <kernel@valentinobst.de> > --- > rust/kernel/error.rs | 7 +------ > 1 file changed, 1 insertion(+), 6 deletions(-) > > diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs > index 4f0c1edd63b7..6f6676bc0eb9 100644 > --- a/rust/kernel/error.rs > +++ b/rust/kernel/error.rs > @@ -265,12 +265,7 @@ pub fn to_result(err: core::ffi::c_int) -> Result { > /// index: u32, > /// ) -> Result<*mut core::ffi::c_void> { > /// // SAFETY: FFI call. > -/// unsafe { > -/// from_err_ptr(bindings::devm_platform_ioremap_resource( > -/// pdev.to_ptr(), > -/// index, > -/// )) > -/// } > +/// from_err_ptr(unsafe { bindings::devm_platform_ioremap_resource(pdev.to_ptr(), index) }) > /// } > /// ``` > // TODO: Remove `dead_code` marker once an in-kernel client is available. > -- > 2.43.0 > > If you're up for it, that safety comment could also be improved. Something like // SAFETY: `pdev` points to a valid platform device But that is noncritical. Reviewed-by: Trevor Gross <tmgross@umich.edu>
> If you're up for it, that safety comment could also be improved. > Something like > > // SAFETY: `pdev` points to a valid platform device Thanks, will include something like that in a v2. Just to make sure I got it correctly: Index is bounds checked [1] and thus there is no need to include it in the comment. Please object if that is wrong. [1]: https://elixir.bootlin.com/linux/v6.7/source/drivers/base/platform.c#L63
diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs index 4f0c1edd63b7..6f6676bc0eb9 100644 --- a/rust/kernel/error.rs +++ b/rust/kernel/error.rs @@ -265,12 +265,7 @@ pub fn to_result(err: core::ffi::c_int) -> Result { /// index: u32, /// ) -> Result<*mut core::ffi::c_void> { /// // SAFETY: FFI call. -/// unsafe { -/// from_err_ptr(bindings::devm_platform_ioremap_resource( -/// pdev.to_ptr(), -/// index, -/// )) -/// } +/// from_err_ptr(unsafe { bindings::devm_platform_ioremap_resource(pdev.to_ptr(), index) }) /// } /// ``` // TODO: Remove `dead_code` marker once an in-kernel client is available.