From nobody Wed Sep 17 17:36:25 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A2FAC4332F for ; Fri, 16 Dec 2022 17:49:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231725AbiLPRtw (ORCPT ); Fri, 16 Dec 2022 12:49:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231655AbiLPRtl (ORCPT ); Fri, 16 Dec 2022 12:49:41 -0500 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7E2370B9D; Fri, 16 Dec 2022 09:49:40 -0800 (PST) Received: by mail-wr1-f44.google.com with SMTP id i7so3240206wrv.8; Fri, 16 Dec 2022 09:49:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7yIyfrfOdv5xmkNvR1/BpAbRSIDwZLQJEypBYov0ihk=; b=mmC6HbKQ6BYA6GmOpVI3q/ntPkn73T7A4CpKCKOkKCi42iXNHGzwTu/gPNALyFXJ6R 6rekyI0X2eoRPIKC9o0uU2VN4IaIxZ/71O05rLbbAcAI0/IVSdaDOT6ND3nSCLy5cHxz AQAZqNAX16woTG4Ppb8vYlTRPIlh8x/io3JVvA0au3EP6iLxjB0lajktJ+yU1xyopWA3 io0Vyh6Of7vhLO+1xycqmF/WpTtN0FZO7psbuRbtRWmtCyTg5mPsPZRPfIKhMMcAM5ay AR+EPGc1v6SfdbvFNoZ28aIvKnH5D2SccjUb24pthYm/9pDmVIMfhmH1Q6KGGZmLDTR/ XPAw== X-Gm-Message-State: ANoB5pk1mkjhUfVmfuy1PTXSM8Ybgz7LNii0Lpv8RGTbLpND9MTeYWlS akxGKaOyDD0ZRd3H0cVzCZuBlWyfRqg= X-Google-Smtp-Source: AA0mqf5cH/FN4aDPJsYWBBDQyEca7uIiApJIE5g7qvsecnaR7LSuohXr8cvjjPr1+O2u7i0/jkTYJQ== X-Received: by 2002:a5d:6741:0:b0:242:567e:25a7 with SMTP id l1-20020a5d6741000000b00242567e25a7mr22013961wrw.42.1671212978691; Fri, 16 Dec 2022 09:49:38 -0800 (PST) Received: from liuwe-devbox-debian-v2.j3c5onc20sse1dnehy4noqpfcg.zx.internal.cloudapp.net ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id w1-20020adfec41000000b002422b462975sm2809384wrn.34.2022.12.16.09.49.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 09:49:38 -0800 (PST) From: Wei Liu To: rust-for-linux@vger.kernel.org, Linux Kernel List Cc: Wei Liu , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= Subject: [PATCH] rust: kernel: drop repetition in offset_of macro Date: Fri, 16 Dec 2022 17:49:27 +0000 Message-Id: <20221216174927.1008629-1-wei.liu@kernel.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It doesn't make sense to allow multiple fields to be specified in offset_of. No functional change. Signed-off-by: Wei Liu --- Cc: Miguel Ojeda Cc: Alex Gaynor Cc: Wedson Almeida Filho Cc: Boqun Feng Cc: Gary Guo Cc: Bj=C3=B6rn Roy Baron --- rust/kernel/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 6a322effa60c..2f3601e4e27e 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -208,7 +208,7 @@ impl<'a> Drop for KParamGuard<'a> { /// ``` #[macro_export] macro_rules! offset_of { - ($type:ty, $($f:tt)*) =3D> {{ + ($type:ty, $f:tt) =3D> {{ let tmp =3D core::mem::MaybeUninit::<$type>::uninit(); let outer =3D tmp.as_ptr(); // To avoid warnings when nesting `unsafe` blocks. @@ -216,12 +216,14 @@ macro_rules! offset_of { // SAFETY: The pointer is valid and aligned, just not initialised;= `addr_of` ensures that // we don't actually read from `outer` (which would be UB) nor cre= ate an intermediate // reference. - let inner =3D unsafe { core::ptr::addr_of!((*outer).$($f)*) } as *= const u8; + let inner =3D unsafe { core::ptr::addr_of!((*outer).$f) } as *cons= t u8; // To avoid warnings when nesting `unsafe` blocks. #[allow(unused_unsafe)] // SAFETY: The two pointers are within the same allocation block. - unsafe { inner.offset_from(outer as *const u8) } - }} + unsafe { + inner.offset_from(outer as *const u8) + } + }}; } =20 /// Produces a pointer to an object from a pointer to one of its fields. --=20 2.35.1