Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1234381rdb; Tue, 30 Jan 2024 11:55:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjMowqtrbKnFfMQ+0YE9rf375bn6F4RMFjz0PwK9JaTz27Fstb3gSD87O8+kIRcxYWezZJ X-Received: by 2002:a81:c704:0:b0:603:f076:a5ff with SMTP id m4-20020a81c704000000b00603f076a5ffmr2523971ywi.85.1706644500959; Tue, 30 Jan 2024 11:55:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706644500; cv=pass; d=google.com; s=arc-20160816; b=F/U9zFlH8/eoDBJ2RDIQu1KAjfoGRL85KQjPNTDMXUMpF5pbz7R72XY6BKMwOvrcWi /ZPUHTkZTBAHrNpR0RPOP94vJhzpz9hEVBrCsIwacCNnGAkPLwAG5ybjgAmxf95SjP2m V5RZQ6T9m859xlshCCTZFB5vs8MF1JHxCQzXSyHsmWIfAf/HPC/QeNP+MIIS1vM94MQX RiCclEiNRXiKz92X3MHZZFxdfaoFyLhVQ0UZ8BBO9n45tkyssdTCoiuYKiADyMnh/xx/ Z5i44LbMvZf45RXW4o8qtsn5vCeWbnzCa6xIilTbGNtyVW5gw/ybP637glUxHbWJBGvx PQBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from; bh=0ADVgV0W2qr4/2M8YAKPNuJ/PmdJI1oDioLd2H2CEhs=; fh=hUsCs6AAE1rR6UueQu8Ky7Vz1eqbksdHYaZcO+jXHjI=; b=F5LToZ9hU966tpcfvZcMjqXOZY5fgsRF3Ri9acAzDue8zb7cJIXGcj0qXUtqeQfGVF dBbjlRUcotZ0zKnkGvfor5YgT48N9mzUB2kMDMbsZQYyhC/9QIcxUzoEunG34c0MAQ0Z 5QYXuCDVpZBDuUpY7a2cRlDcJVBfH17FI4lS1BK2+B1Q6vpOEslMfgTq+oBCoK/lCCzv kQyd4njHPrR+PpDjdRxNo/ok09MNRrEMoykLE1pX45PgzyI+zfkfFSX2fQUTmWwTCZ7g 9RSAd3Hu7I7plGwo33vHN7s5/8wZSsNuHa+/gS7sSsHZ5fQ8JOJG3drptWvLscISTBM/ BQAw== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=christina-quast.de); spf=pass (google.com: domain of linux-kernel+bounces-45225-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45225-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id kl11-20020a056214518b00b0068c4af4a70dsi5689857qvb.410.2024.01.30.11.55.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 11:55:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45225-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=christina-quast.de); spf=pass (google.com: domain of linux-kernel+bounces-45225-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45225-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B14A31C23DBD for ; Tue, 30 Jan 2024 19:55:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5F75769DE8; Tue, 30 Jan 2024 19:54:50 +0000 (UTC) Received: from mail.someserver.de (mail.someserver.de [116.202.193.223]) (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 CAB4869D36; Tue, 30 Jan 2024 19:54:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=116.202.193.223 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706644489; cv=none; b=SZrcNhMEbtnW3wQkC+WCFuHDDo7PkyoC0e2eRu7q0AUyliwd49mTqz4JQy/3nlVTIUhWjbWPCH7nFpyCB+5Z7SGTUAmCTHUt9kuGcNvlN2PftyC3DPcbjS/rHAvIF67YtVBLLEYdpcF3z/eFzVWDde9D0OGIM7MToTYcMCYW8bk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706644489; c=relaxed/simple; bh=xgl3MC3s1y+/xuGn3VPAMSHRrzUBbY9DHF1bmTq1orY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=C94QUUE5DzNl4R2tzPv6/+R5lzdJelKEGFKFod5QIj4m1kABJ0hz0TBcG1vtcISMwcNPBzvNRJb+07/DOehgj1jFZOBU5GtDjVG9e0URGHHWVUhON95e8OBbBLZ2zGq7uLslOps/AAFV7wgWuF9mQ+s4o6zYzn2+FDlv7CsTIxw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=christina-quast.de; spf=pass smtp.mailfrom=christina-quast.de; arc=none smtp.client-ip=116.202.193.223 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=christina-quast.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=christina-quast.de Received: from localhost (unknown [195.162.191.218]) by mail.someserver.de (Postfix) with ESMTPSA id AC348A2194; Tue, 30 Jan 2024 20:48:00 +0100 (CET) From: Christina Quast Date: Tue, 30 Jan 2024 20:47:51 +0100 Subject: [PATCH] rust: prelude: add bit function 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: <20240130-rust-bit-v1-1-ed2ed6389a58@christina-quast.de> X-B4-Tracking: v=1; b=H4sIAGZSuWUC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxMDQ2MD3aLS4hLdpMwSXUvLlBSzFONEA1NjMyWg8oKi1LTMCrBR0bG1tQD yELu2WgAAAA== 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, Christina Quast X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706644076; l=1210; i=contact@christina-quast.de; s=20240130; h=from:subject:message-id; bh=xgl3MC3s1y+/xuGn3VPAMSHRrzUBbY9DHF1bmTq1orY=; b=IHKGeUwSlFiuDYNIGEj+pe7lXU8/JC4z+PlzeygWkPNGUN6EbHVPeknbOQfa0VAhLSpY85+Pq jeN5dZXFEzADtKZ73EE41EokaLOnYmLWM/7L6Fez0t3E5YP0i9LR9MK X-Developer-Key: i=contact@christina-quast.de; a=ed25519; pk=aoQfinjbnr265vCkIZdYteLDcmIqLBhY1m74WfFUU9E= In order to create masks easily, the define BIT() is used in C code. This commit adds the same functionality to the rust kernel. To use it, include the following into your rust file: use kernel::prelude::bit Signed-off-by: Christina Quast --- This patch is needed for further patches porting the rockchip phy driver to rust. --- rust/kernel/prelude.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/rust/kernel/prelude.rs b/rust/kernel/prelude.rs index ae21600970b3..16e483de2f27 100644 --- a/rust/kernel/prelude.rs +++ b/rust/kernel/prelude.rs @@ -38,3 +38,19 @@ pub use super::init::{InPlaceInit, Init, PinInit}; pub use super::current; + +/// Returns a `u32` number that has only the `n`th bit set. +/// +/// # Arguments +/// +/// * `n` - A `u32` that specifies the bit position (zero-based index) +/// +/// # Example +/// +/// ``` +/// let b = bit(2); +/// assert_eq!(b, 4); +#[inline] +pub const fn bit(n: u32) -> u32 { + 1 << n +} --- base-commit: 6613476e225e090cc9aad49be7fa504e290dd33d change-id: 20240130-rust-bit-99dd6d3a0536 Best regards, -- Christina Quast