Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1895632rdb; Wed, 31 Jan 2024 12:25:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbOqpWxmIglLr9r9JReR45c1uuPqDkAW/w565ezo2DaadLoSKmtxc44wRmOjvrW1hwUvly X-Received: by 2002:aa7:d842:0:b0:55c:584:d6d with SMTP id f2-20020aa7d842000000b0055c05840d6dmr1736540eds.3.1706732707058; Wed, 31 Jan 2024 12:25:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706732707; cv=pass; d=google.com; s=arc-20160816; b=uICuMp+qQGNPopl4x+lP4PuSBTbpM67csEpC5UAYa+quvW6wYa8E/Y3po4QyOonGIW Ntkrsraw5TvcWX25vBPbgVGZglgwodmVaVPxIhHHJ6LOtHC41ZiVWZCUPFKCONcIr9tj tHIW2azCF1W2R0LmPI+1f9rlmc9++la+V6SMsWNxTi9cnHeuwoL0J91XFW+XlPUUc9nX 2VvTgxg0EMGxMwaTWTFfdQQZOyMVhRAHIDEmBBaaaYsVfPw57xVIKXi/tbsyLTREjmn/ WlxxBC0EnAQ7SuxBXvg1pUxRisrDXicsC0lu8aWXZrDJHCJd/oObcT+xPQoR3Q2l7iVJ wsZA== 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=LQN3sEPpKJ9rQR9RdK+WlWzUFKSjSy+Bxja4W/L/Y1c=; b=xQPLw2ebVFcqFwHm77QplILxB3VDm05gUI27yW/KVM9b/U4P3LUkdqRZDoMnjmeHR5 BIBb2afgbdqqAXJatvxCJcijeMu+WIgX2iL9UDqFmK/7hQyZwf4YwG2cfh2bgpxkCpnR KI+/sadhzBkDKqt5N24rS5uUNiY4BdYSoShSau2GLUn+3vT6IKWeVw+5qJyCME5UWb6T kguZJAKzM76xH48xnovMD7v3Oi2iVgbrwEsZjohVuGQ9mfss7kaKbVt6tX3rwMVcp4kG vOE9LgsnvNxphP/I9nELBxtIQZ7nI8A9mWbAB02oOSc97XXKfVmGlrUvfWOUPm6k6SA5 QcKA==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47065-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCXG2yBHNiX+hYJtX+rLSeJRkL+FuTdxa5z7X1Lt0gsQ/3UcgIBZY+hYjEm+ShA+cIduymt/Z51/A3xnRuJylGE3xWpUowcvCtWQ1bi46g== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l24-20020a056402125800b0055f84acac72si1003178edw.158.2024.01.31.12.25.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 12:25:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47065-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47065-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id C9AE51F27029 for ; Wed, 31 Jan 2024 20:25:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3379A12DDAB; Wed, 31 Jan 2024 20:24:10 +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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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: 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 --- 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. -- 2.43.0