From patchwork Wed Jan 31 20:23:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Obst via B4 Relay X-Patchwork-Id: 194922 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp3477dyc; Wed, 31 Jan 2024 12:26:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IHy1ebFWTmfnIhl19vSoURLdUoxzUZ0iXWTlGTXBXyID22IGizKw0Kcqwt0fHjzFu5ATbvT X-Received: by 2002:a05:6902:e13:b0:dc2:3f75:1f79 with SMTP id df19-20020a0569020e1300b00dc23f751f79mr3388404ybb.23.1706732814398; Wed, 31 Jan 2024 12:26:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706732814; cv=pass; d=google.com; s=arc-20160816; b=FkwxYnmBu95C+XBj+1rgFCDdmf+/0uA++e5Z9jpWG3QzvUY9nK3XTe3eLgMLU2m5Ee jnHQ16EU690Pg9WEgLYNz0PzzoezYVkwkHcAvp/r2j6Ifk8CN8v6ugpdq4B52YhJ24XC ZFQOFkF7Wbq+g0IoxrVT7168gx/BjA+0JMDbr48PInmbihsveTfix3+mQ0Plu9o6dztk H1vPPlBIAbArnx6yHWgDHrQ0gQJ4Yy04AgPaIbhuyg/2jKo2ScxQd2onz4Y46apjUEsA RovCG7RINLCs4pfUalTZtB61fDCs9nfOyDfMnknloQPtS1EY3hqtUYfHGrmrzvZRqT1f qWug== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:subject:date:from:dkim-signature; bh=NR/AxSO+/VzERySueDZiQaX4+a+3W0mCm0GQSd4ktU0=; fh=hJKxds4AEPT2Gq1zRchx5zE2aaRrWRkm5A5VLQt/2UQ=; b=lbUo9YaUYvCtXAf5mvBqO21Fs7/8HnJL4D5g9Bx13hqGhMpnCEUx685mgs/mhPloDQ itcY5agFVZc5qcbv4FgYqIaPcm/0cAge14CUhqWwrIQWB/GJ0Dd/S2/NOLYLXlDo1gqZ qKrj7yVDyv9/3+bgAb+WrU7GcknpxR2D7Uj1ufP2Bek0RgNU9SbpYDePQCobVtQb3ddm R1R1KHuYafRWPh8Na4acZdPFuW0d+PYZG271bqxU4s6hfTQiUR0w/vd6sTtu28ajnmur c3f93COjZiNlxPLJKWAN+6/D7fhMictWbTWNL+wlkCI9mivVvELQzg25foRubu/ei5vu 8VcA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZSYEa0HD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-47065-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47065-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCX3mumfQMbzlo7X8HUqBQ3BP9XJ1A9+mITzTQooRxb0BOveMi+WqQqaFUlUGNfaksx9a/Hk6DS/7v9iolRwRQKKQ/w0ig== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b26-20020a05620a127a00b0078437ff3445si3818803qkl.36.2024.01.31.12.26.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 12:26:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47065-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZSYEa0HD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-47065-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47065-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id EA71B1C2164D for ; Wed, 31 Jan 2024 20:26:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3148813B7AF; Wed, 31 Jan 2024 20:24:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZSYEa0HD" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3A0A2405FD; Wed, 31 Jan 2024 20:24:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706732649; cv=none; b=P/pXmIc5LuyTgQOzb2sZwva4gIZQg7Cd0ksHCuAISQ0P3/3v6Nj0TlzVy9S/jiLONiuPExPk0c60fM+kBKs0A3B+omJy3/Qtsh2HHSYea/QF21N1XR6cRl5VKMfvPZwn1xAk6HJ1KSCofvAW2gKeNl2+YGkVN98rYYeckiv9yeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706732649; c=relaxed/simple; bh=7+HfyhzzCkGim8Q92q/WPjGDaBB/DO24UGQTf2LaIQ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fXAZc8bEKf65Cy/gOnmm2n7ccDl4mqs1t6pL0WVBpepPwM8sj/YtRI9utRB76gmJV/hOdyLE1g/rLGzO5PVF0zvGVPpZA7RtSDEQEv+YSg4SzjGERi901SN0Ej8bAg0vakj9j7AETE3ZbVvJ0naMtKQvOrVhWUoTF9vnthTXmi8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZSYEa0HD; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id D1C33C43394; Wed, 31 Jan 2024 20:24:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706732648; bh=7+HfyhzzCkGim8Q92q/WPjGDaBB/DO24UGQTf2LaIQ0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ZSYEa0HDHmlAX4RfR0TPN42+rM0RHSUisBaQruyPofDeVyY46LsD0wbAzS1oc05Hi 8srel8f/3fpc7p+c1S21+O0XLhH0kOyBK9tEdY3eUxAepvrkluZ7PVslwHHxp5xt7E o3Us+TH8H7cwIgNke7oi3Fx87Oe35g3Bt5/06EhmOCjDpQO5YOJ2YvrmfG4e+Au7Vm /ac33OaEtoBMOq1oInW4SeOUwAU494ZlbNS4K2T86pggZ9dTAk+fSfQ1PAQ/bTbF8q KIxQMu3ITLNddY8fmC99vBEtO5sEbVTKMWTOaYrd6iaU9gOMZkpMLaYOXlG2f7W/h6 yIF5U0evb/NfQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8159C47DB3; Wed, 31 Jan 2024 20:24:08 +0000 (UTC) From: Valentin Obst via B4 Relay Date: Wed, 31 Jan 2024 21:23:24 +0100 Subject: [PATCH v3 02/12] rust: error: improve unsafe code in example Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240131-doc-fixes-v3-v3-2-0c8af94ed7de@valentinobst.de> References: <20240131-doc-fixes-v3-v3-0-0c8af94ed7de@valentinobst.de> In-Reply-To: <20240131-doc-fixes-v3-v3-0-0c8af94ed7de@valentinobst.de> To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Valentin Obst , Martin Rodriguez Reboredo X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706732646; l=1327; i=kernel@valentinobst.de; s=20240131; h=from:subject:message-id; bh=6+MgMwYSzO387ZH/l2u1ebga1PIh0bS6tqLpjrjT2uo=; b=Z/KZuTuucZxrwSZ2hrvH8wBevQGTrKv8ViFSulOXQ1vFBR+NAq8VtP/cKqkH5mqutwRli950E awsD2FxX7uKDb2cDfX6wfRCyUn4Pjr4siGeIBadFu//Jic/rXph6dUM X-Developer-Key: i=kernel@valentinobst.de; a=ed25519; pk=3s7U8y0mqkaiurgHSQQTYWOo2tw5HgzCg5vnJVfw37Y= X-Endpoint-Received: by B4 Relay for kernel@valentinobst.de/20240131 with auth_id=124 X-Original-From: Valentin Obst Reply-To: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789639067555451428 X-GMAIL-MSGID: 1789639067555451428 From: Valentin Obst The `from_err_ptr` function is safe. There is no need for the call to it to be inside the unsafe block. Reword the SAFETY comment to provide a better justification of why the FFI call is safe. Signed-off-by: Valentin Obst Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Alice Ryhl Reviewed-by: Trevor Gross --- rust/kernel/error.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs index 4f0c1edd63b7..4786d3ee1e92 100644 --- a/rust/kernel/error.rs +++ b/rust/kernel/error.rs @@ -264,13 +264,9 @@ pub fn to_result(err: core::ffi::c_int) -> Result { /// pdev: &mut PlatformDevice, /// index: u32, /// ) -> Result<*mut core::ffi::c_void> { -/// // SAFETY: FFI call. -/// unsafe { -/// from_err_ptr(bindings::devm_platform_ioremap_resource( -/// pdev.to_ptr(), -/// index, -/// )) -/// } +/// // SAFETY: `pdev` points to a valid platform device. There are no safety requirements +/// // on `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.