From patchwork Mon Nov 18 13:12:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manas via B4 Relay X-Patchwork-Id: 13878546 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 443DE19AA5F; Mon, 18 Nov 2024 13:12:19 +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=1731935539; cv=none; b=k8MENPdS31xH9HCxACe/5ew9UbHZZoVPD9IhNclJSzURgg9Y1Ji0bkfj9ttQBwpEF59ON+3nK/QzxSXWzLOmUod4iXOOQMD9aTGnRojMVsUukTzn6FM052tElF4AMqH5896kfrOKBJorxcJ8Cf69smSfM8RRDS3xVAuKMN3QagY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731935539; c=relaxed/simple; bh=HMy7z0vmYlrGgIkxgA33QHVGMm+yBmfqpLCVJj6m1Uw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lUMC6wXvtti8tfByj9BofAhB9QSW8jSeTToER5CJ5KmjlvU7Y8VaVeCC7/OTWxFv5iYfGxRMMsnmFBk807Xo2wE0fS+0JPia01q0hq0KzA/DrRHTt9JIUhrDdihv9Nhl+0xPFr50Q2VwXdOfFBkqBkaS7CQKehs4Gq8PbHhdLM0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Eza5mQId; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Eza5mQId" Received: by smtp.kernel.org (Postfix) with ESMTPS id DC6B2C4CED0; Mon, 18 Nov 2024 13:12:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731935538; bh=HMy7z0vmYlrGgIkxgA33QHVGMm+yBmfqpLCVJj6m1Uw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Eza5mQIdgWdqiSgZgnmQAkn7mU9Ay++wtU+RNmBq+RHDmtFGlykDRzucakXCeD5zk T7iWUbQkE/gHWKXJGkZ9TGIiDrgngRbC1cQE2MaXXjriTxBT99McC+yegJlnAHuuf8 Ed/QPY3hzN7R6u/VwSUOZo3/UDme4yfV2jsyoF7ycBYuDckoYkca7K9JvI4hVNcEdG Jj1cN1j3WGL22J3L2PEtz6zf/+iPOlJc4sM+mQOADYEDT93fqqIz57bo0A1Jz91iis EBD/L6k9puozdYlcC5jwv/g4bVHqjUIr3SbyQCMiSyFeYVrs+EF8lsSa7kUrWavFZE KMOAkgo/sV1oA== 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 C873CD4921C; Mon, 18 Nov 2024 13:12:18 +0000 (UTC) From: Manas via B4 Relay Date: Mon, 18 Nov 2024 18:42:17 +0530 Subject: [PATCH v2 1/3] rust: block: simplify Result<()> in validate_block_size return Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241118-simplify-result-v2-1-9d280ada516d@iiitd.ac.in> References: <20241118-simplify-result-v2-0-9d280ada516d@iiitd.ac.in> In-Reply-To: <20241118-simplify-result-v2-0-9d280ada516d@iiitd.ac.in> To: FUJITA Tomonori , Trevor Gross , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andreas Hindborg , Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl Cc: Shuah Khan , Anup Sharma , netdev@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Manas X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1731935537; l=1089; i=manas18244@iiitd.ac.in; s=20240813; h=from:subject:message-id; bh=mynh6sk8RoVgNyY4+tCv1gPC6C3Qaqxtwv1pM7qKGxI=; b=NIq7enWghtGJmPtwMxRPMx2hjBp6cdJYkvGzFhObjXO9HQlM1ll9+VlepGEXfM1RjQ3XekVqW 34Qzlh1WHo3BzgxH9PeFxze6MJoRyqNIp0cdjdFJPyaTrBCmcuUX5e4 X-Developer-Key: i=manas18244@iiitd.ac.in; a=ed25519; pk=pXNEDKd3qTkQe9vsJtBGT9hrfOR7Dph1rfX5ig2AAoM= X-Endpoint-Received: by B4 Relay for manas18244@iiitd.ac.in/20240813 with auth_id=196 X-Original-From: Manas Reply-To: manas18244@iiitd.ac.in From: Manas `Result` is used in place of `Result<()>` because the default type parameters are unit `()` and `Error` types, which are automatically inferred. This patch keeps the usage consistent throughout codebase. Signed-off-by: Manas Reviewed-by: Miguel Ojeda --- rust/kernel/block/mq/gen_disk.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_disk.rs index 708125dce96a934f32caab44d5e6cff14c4321a9..798c4ae0bdedd58221b5851a630c0e1052e0face 100644 --- a/rust/kernel/block/mq/gen_disk.rs +++ b/rust/kernel/block/mq/gen_disk.rs @@ -45,7 +45,7 @@ pub fn rotational(mut self, rotational: bool) -> Self { /// Validate block size by verifying that it is between 512 and `PAGE_SIZE`, /// and that it is a power of two. - fn validate_block_size(size: u32) -> Result<()> { + fn validate_block_size(size: u32) -> Result { if !(512..=bindings::PAGE_SIZE as u32).contains(&size) || !size.is_power_of_two() { Err(error::code::EINVAL) } else { From patchwork Mon Nov 18 13:12:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manas via B4 Relay X-Patchwork-Id: 13878547 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 4448819AD7E; Mon, 18 Nov 2024 13:12:19 +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=1731935539; cv=none; b=TIqo3OKMK9NBAxdNHsBi5LG5faBE6xrHmR3I4HcXm33SS4xp2kVIBVS57vTxT6CfAsY/TzrFvTPhSOV6NKDSLx1rxlALuFtpV8sV/5RydiRvz0bA4CHCPFhjlh0DUT+DkDAlMnRLc8y9Jv3ehqfMXB+4ik1chPhaNGY9iu5TmJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731935539; c=relaxed/simple; bh=fbxklw6aYSFwowHXbk2xxPrEWuhXoyAWAQ3wJtxtslU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DIGu3/MbWfG1YwVjOreSkGmsPxdZpQieMw1dDjN0ri7HBD4d4nEwA81hzVErpoa1qpYwPGY6QcShaCxSiA6FXBft0gQHmsCB8lwV/665bdw6kyypzWb0QrjvFeSAwUoYoGI5l5pNtv/pKyjjjceFFGJ/FjDY9B+IRyQ7sAUBEyY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=azbguS5P; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="azbguS5P" Received: by smtp.kernel.org (Postfix) with ESMTPS id ECF98C4CED9; Mon, 18 Nov 2024 13:12:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731935539; bh=fbxklw6aYSFwowHXbk2xxPrEWuhXoyAWAQ3wJtxtslU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=azbguS5PkfJqvqqyN2fPQ9+XWrAk3kex7MpVv+e2XZl7qpAyHgx0Ag2A4L4eAVQnr ncDtSxArVdO7swAyLEda9B8d+B0m3+P7Ua6T7E3rlOcDi3Gd/7gjPBxTIyE3wguOzH OTioO3Niqa+UJj3cTvss7a2HCCkbRXjXyOKKHtywxUd3CSM2r5vCX29C+UGpEBwJys 7+l9nsgCrK4q5xu+Xangyux4XdIymkUKu+kNVXtb468j93sFz0z5D27YO0cZcYfZ/9 RLJFwdc1HY/BJ4cbQAk7/oGIJCLd4YY49N6CDoag8JK91/l2A0QHeT0hZgNYWQIL3m mYft9JFfbuS+w== 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 DBAE2D49220; Mon, 18 Nov 2024 13:12:18 +0000 (UTC) From: Manas via B4 Relay Date: Mon, 18 Nov 2024 18:42:18 +0530 Subject: [PATCH v2 2/3] rust: uaccess: simplify Result<()> in bytes_add_one return Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241118-simplify-result-v2-2-9d280ada516d@iiitd.ac.in> References: <20241118-simplify-result-v2-0-9d280ada516d@iiitd.ac.in> In-Reply-To: <20241118-simplify-result-v2-0-9d280ada516d@iiitd.ac.in> To: FUJITA Tomonori , Trevor Gross , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andreas Hindborg , Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl Cc: Shuah Khan , Anup Sharma , netdev@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Manas X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1731935537; l=955; i=manas18244@iiitd.ac.in; s=20240813; h=from:subject:message-id; bh=9Gxv/qHfLswgJdVyXaRQDKJONyKmoZBo4nn1UwfQens=; b=A5WVxANHl42qVjTQgMaEs5OYWJIBBaH9cgMmLGXCsJ9ige2U8lYYSyX2IbGox9gSvQHKMyX5R 3+t4PGCl1GUDaXF8F3kCvDSG8Hu424BhRq1xeeRS0eiwMOLqJvUpqJK X-Developer-Key: i=manas18244@iiitd.ac.in; a=ed25519; pk=pXNEDKd3qTkQe9vsJtBGT9hrfOR7Dph1rfX5ig2AAoM= X-Endpoint-Received: by B4 Relay for manas18244@iiitd.ac.in/20240813 with auth_id=196 X-Original-From: Manas Reply-To: manas18244@iiitd.ac.in From: Manas bytes_add_one returns `Result<()>`, a result over unit type. This can be simplified to `Result` as default type parameters are unit `()` and `Error` types. This also keeps the usage of `Result` consistent throughout codebase. Signed-off-by: Manas --- rust/kernel/uaccess.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs index 05b0b8d13b10da731af62be03e1c2c13ced3f706..7c21304344ccd943816e38119a5be2ccf8d8e154 100644 --- a/rust/kernel/uaccess.rs +++ b/rust/kernel/uaccess.rs @@ -49,7 +49,7 @@ /// use kernel::error::Result; /// use kernel::uaccess::{UserPtr, UserSlice}; /// -/// fn bytes_add_one(uptr: UserPtr, len: usize) -> Result<()> { +/// fn bytes_add_one(uptr: UserPtr, len: usize) -> Result { /// let (read, mut write) = UserSlice::new(uptr, len).reader_writer(); /// /// let mut buf = KVec::new(); From patchwork Mon Nov 18 13:12:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manas via B4 Relay X-Patchwork-Id: 13878548 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 6ADBC19C560; Mon, 18 Nov 2024 13:12:19 +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=1731935539; cv=none; b=BD3QxXr7/3egC1S0PVcNGCIHinLhQ1Vp9yHwyp50tOU14V3xxyHLyfkg115kJvLw5DIkNkqy2aYGtEYwwR3xiBp4rKHLotKU4X4hodxRxkrPwKUr8L1LxEPJjTQgH8YxM5Dy4+Zut4cBpLkM2mdOoVE2/9IEvz+kJuFwBePM3oU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731935539; c=relaxed/simple; bh=FMYxsf9lW6S6RnGgoIzzxMAtqiexE0hgvQ7nmRbtYa0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=c4w1fLol0A3LPeI4v4YMCh6fXiY0auwBASiO2QN2yagNcInN61oNV3FEoGdZyxoAQf1Ije3S4YjRoieOzO4gohBErtJUiCUQoFw2aJ4dpnvcqR2s2/xKSoElbe9YDTbtRGtV8tLVOrp5bcR0JX3lZLgbzMWku6Pz5Yo6ra2EiKo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E2NdPL96; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="E2NdPL96" Received: by smtp.kernel.org (Postfix) with ESMTPS id 0B1A9C4CEDB; Mon, 18 Nov 2024 13:12:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731935539; bh=FMYxsf9lW6S6RnGgoIzzxMAtqiexE0hgvQ7nmRbtYa0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=E2NdPL96N7hBepjMCkhxM0AL2B4PLOEqN/aNFY/y8RRmbP/A+5FH0S/rLekuJuxdh liTgkR9/iTZGaRg0Jatm5CFJ8+N/JwJYQfRlGFtocgsSAo4lPo4u7QBoZdIOYnwGVv 1LAQB/142i42wbzxWnyzFsPyFc4u2U9spnTkgrJ1rV/9N7mvrb50WoFQGhzClcNR65 J27bSJNi4rltnpHHBbfZgZ0SO9ZdQyK3HNFjUXkobiAi/xpVNTjpK6O5XDZq7fGdVQ BSM81mzWzJ9ed5c5xMPUldmZsjK3FPLPOCco1pWoEtdpTCEVlR1eU1rHL7FIPEF2Pb UPT2JUxHCCgzA== 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 F0886D49221; Mon, 18 Nov 2024 13:12:18 +0000 (UTC) From: Manas via B4 Relay Date: Mon, 18 Nov 2024 18:42:19 +0530 Subject: [PATCH v2 3/3] rust: macros: simplify Result<()> in function returns Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241118-simplify-result-v2-3-9d280ada516d@iiitd.ac.in> References: <20241118-simplify-result-v2-0-9d280ada516d@iiitd.ac.in> In-Reply-To: <20241118-simplify-result-v2-0-9d280ada516d@iiitd.ac.in> To: FUJITA Tomonori , Trevor Gross , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andreas Hindborg , Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl Cc: Shuah Khan , Anup Sharma , netdev@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Manas X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1731935537; l=1346; i=manas18244@iiitd.ac.in; s=20240813; h=from:subject:message-id; bh=kLuPLhtQy03UFJsMApFTqciq/nC1ofEukNt3vnOoNoI=; b=KjPfrmtej3yw3CTY13ra2gZyIs0M3OVKKGBxb/WuQ26KVNSQ8jxdoeTy/4O1E/z7OwgmMlaKm YHkOTrdtbjeBkAQtbugCM/fRAPIUhlZA5WBglQU13RUz1Og+7nVTHNK X-Developer-Key: i=manas18244@iiitd.ac.in; a=ed25519; pk=pXNEDKd3qTkQe9vsJtBGT9hrfOR7Dph1rfX5ig2AAoM= X-Endpoint-Received: by B4 Relay for manas18244@iiitd.ac.in/20240813 with auth_id=196 X-Original-From: Manas Reply-To: manas18244@iiitd.ac.in From: Manas Functions foo and bar in doctests return `Result<()>` type. This type can be simply written as `Result` as default type parameters are unit `()` and `Error` types. This also keeps the usage of `Result` consistent. Signed-off-by: Manas --- rust/macros/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs index 4ab94e44adfe3206faad159e81417ea41a35815b..463920353ca9c408f5d69e2626c13a173bae98d7 100644 --- a/rust/macros/lib.rs +++ b/rust/macros/lib.rs @@ -144,11 +144,11 @@ pub fn module(ts: TokenStream) -> TokenStream { /// // Declares a `#[vtable]` trait /// #[vtable] /// pub trait Operations: Send + Sync + Sized { -/// fn foo(&self) -> Result<()> { +/// fn foo(&self) -> Result { /// kernel::build_error(VTABLE_DEFAULT_ERROR) /// } /// -/// fn bar(&self) -> Result<()> { +/// fn bar(&self) -> Result { /// kernel::build_error(VTABLE_DEFAULT_ERROR) /// } /// } @@ -158,7 +158,7 @@ pub fn module(ts: TokenStream) -> TokenStream { /// // Implements the `#[vtable]` trait /// #[vtable] /// impl Operations for Foo { -/// fn foo(&self) -> Result<()> { +/// fn foo(&self) -> Result { /// # Err(EINVAL) /// // ... /// }