From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 0123D156D9 for ; Tue, 17 Oct 2023 07:15:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="IQWp3b+D" Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 559FE8E; Tue, 17 Oct 2023 00:15:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1697526943; x=1697786143; bh=acUd1lSaIk6mqFLWpDrtsFDJMd6E9whjQUC+IiZu2Vs=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=IQWp3b+DXcNWxfbyrxfOxJC4DldaHNEsBjLcqtbHOlpMGxp/jZKEnQkG8zWouSp8T inCvh+IZS5Ewux0jJQBmR+Uvgaa4gmoyi7bG5i5HrzwQ2jKVIRq6PHEI2vJZGtivye QsfysrKVo6rhH5TdPCJ8F9YOBo+MP3GlwPbkDRohCk8JriYOgtVh2F3Q4GPx+MTtjR O1yj6se5a57k50iVh+3cii7qcI7Q4iSijRehyc08xKv/W5XZiLsN5QS1KeKnLC2oJB 98m3Wc4cFEVSw7WOKQYKi4Vrm9ohrXhKNeIeRYNHui4gyAH9H/DAF4A8YUT9szHy0s c8sOJ1q8zUPRw== Date: Tue, 17 Oct 2023 07:15:16 +0000 To: Gary Guo , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Martin Rodriguez Reboredo , Vincenzo Palazzo , Vlastimil Babka From: Benno Lossin Cc: Wedson Almeida Filho , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] rust: bindings: rename const binding using sed Message-ID: In-Reply-To: <20230930133704.13313-1-gary@garyguo.net> References: <20230930133704.13313-1-gary@garyguo.net> Feedback-ID: 71780778:user:proton Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net On 30.09.23 15:36, Gary Guo wrote: > Current for consts that bindgen don't recognise, we define a helper > constant with >=20 > const BINDINGS_ =3D ; >=20 > in `bindings_helper.h` and then we put >=20 > pub const : =3D BINDINGS_; >=20 > in `bindings/lib.rs`. This is fine that we currently only have 3 > constants that are defined this way, but is going to be more annoying > when more constants are added since every new constant needs to be > defined in two places. >=20 > This patch changes the way we define constant helpers to >=20 > const RUST_BINDING_ =3D ; >=20 > and then use `sed` to postprocess Rust code by generated by bindgen to > remove the distinct prefix, so user of the binding crate can refer to > the name directly. >=20 > Signed-off-by: Gary Guo > --- > rust/Makefile | 2 ++ > rust/bindings/bindings_helper.h | 6 +++--- > rust/bindings/lib.rs | 3 --- > rust/kernel/allocator.rs | 2 +- > 4 files changed, 6 insertions(+), 7 deletions(-) >=20 > diff --git a/rust/Makefile b/rust/Makefile > index 14d93cf60a95..20889302b172 100644 > --- a/rust/Makefile > +++ b/rust/Makefile > @@ -339,6 +339,8 @@ quiet_cmd_bindgen =3D BINDGEN $@ >=20 > $(obj)/bindings/bindings_generated.rs: private bindgen_target_flags =3D= \ > $(shell grep -v '^#\|^$$' $(srctree)/$(src)/bindgen_parameters) > +$(obj)/bindings/bindings_generated.rs: private bindgen_target_extra =3D = ; \ > + sed -Ei 's/pub const RUST_BINDING_([a-zA-Z0-9_]*)/pub const \1/g' $@ Would it make sense to use `^pub const...`? I also agree with Alice that we could use a less generic name as the prefix. With those things fixed: Reviewed-by: Benno Lossin --=20 Cheers, Benno > $(obj)/bindings/bindings_generated.rs: $(src)/bindings/bindings_helper.= h \ > $(src)/bindgen_parameters FORCE > =09$(call if_changed_dep,bindgen) > diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_hel= per.h > index 85f013ed4ca4..c41eaab4ddb2 100644 > --- a/rust/bindings/bindings_helper.h > +++ b/rust/bindings/bindings_helper.h > @@ -15,6 +15,6 @@ > #include >=20 > /* `bindgen` gets confused at certain things. */ > -const size_t BINDINGS_ARCH_SLAB_MINALIGN =3D ARCH_SLAB_MINALIGN; > -const gfp_t BINDINGS_GFP_KERNEL =3D GFP_KERNEL; > -const gfp_t BINDINGS___GFP_ZERO =3D __GFP_ZERO; > +const size_t RUST_BINDING_ARCH_SLAB_MINALIGN =3D ARCH_SLAB_MINALIGN; > +const gfp_t RUST_BINDING_GFP_KERNEL =3D GFP_KERNEL; > +const gfp_t RUST_BINDING___GFP_ZERO =3D __GFP_ZERO; > diff --git a/rust/bindings/lib.rs b/rust/bindings/lib.rs > index 9bcbea04dac3..40ddaee50d8b 100644 > --- a/rust/bindings/lib.rs > +++ b/rust/bindings/lib.rs > @@ -48,6 +48,3 @@ mod bindings_helper { > } >=20 > pub use bindings_raw::*; > - > -pub const GFP_KERNEL: gfp_t =3D BINDINGS_GFP_KERNEL; > -pub const __GFP_ZERO: gfp_t =3D BINDINGS___GFP_ZERO; > diff --git a/rust/kernel/allocator.rs b/rust/kernel/allocator.rs > index a8f3d5be1af1..4b057e837358 100644 > --- a/rust/kernel/allocator.rs > +++ b/rust/kernel/allocator.rs > @@ -21,7 +21,7 @@ unsafe fn krealloc_aligned(ptr: *mut u8, new_layout: La= yout, flags: bindings::gf >=20 > let mut size =3D layout.size(); >=20 > - if layout.align() > bindings::BINDINGS_ARCH_SLAB_MINALIGN { > + if layout.align() > bindings::ARCH_SLAB_MINALIGN { > // The alignment requirement exceeds the slab guarantee, thus t= ry to enlarge the size > // to use the "power-of-two" size/alignment guarantee (see comm= ents in `kmalloc()` for > // more information). > -- > 2.40.1 >=20