summaryrefslogtreecommitdiffstats
path: root/rust/bindings
diff options
context:
space:
mode:
authorGary Guo <gary@garyguo.net>2023-11-04 15:56:56 +0100
committerMiguel Ojeda <ojeda@kernel.org>2023-12-14 20:14:01 +0100
commit743766565dc0bdeedf7db419500031c7bdc84033 (patch)
treebcc357f4dfab31ed67c4c53d62f4dd87d4180737 /rust/bindings
parentrust: Ignore preserve-most functions (diff)
downloadlinux-743766565dc0bdeedf7db419500031c7bdc84033.tar.xz
linux-743766565dc0bdeedf7db419500031c7bdc84033.zip
rust: bindings: rename const binding using sed
Currently, for `const`s that bindgen doesn't recognise, we define a helper constant with const <TYPE> BINDINGS_<NAME> = <NAME>; in `bindings_helper.h` and then we put pub const <NAME>: <TYPE> = BINDINGS_<NAME>; in `bindings/lib.rs`. This is fine since 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. This patch changes the way we define constant helpers to const <TYPE> RUST_CONST_HELPER_<NAME> = <NAME>; and then use `sed` to postprocess Rust code generated by bindgen to remove the distinct prefix, so users of the `bindings` crate can refer to the name directly. Reviewed-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Signed-off-by: Gary Guo <gary@garyguo.net> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20231104145700.2495176-1-gary@garyguo.net [ Reworded for typos. ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust/bindings')
-rw-r--r--rust/bindings/bindings_helper.h6
-rw-r--r--rust/bindings/lib.rs3
2 files changed, 3 insertions, 6 deletions
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index 85f013ed4ca4..b5714fb69fe3 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -15,6 +15,6 @@
#include <linux/workqueue.h>
/* `bindgen` gets confused at certain things. */
-const size_t BINDINGS_ARCH_SLAB_MINALIGN = ARCH_SLAB_MINALIGN;
-const gfp_t BINDINGS_GFP_KERNEL = GFP_KERNEL;
-const gfp_t BINDINGS___GFP_ZERO = __GFP_ZERO;
+const size_t RUST_CONST_HELPER_ARCH_SLAB_MINALIGN = ARCH_SLAB_MINALIGN;
+const gfp_t RUST_CONST_HELPER_GFP_KERNEL = GFP_KERNEL;
+const gfp_t RUST_CONST_HELPER___GFP_ZERO = __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 {
}
pub use bindings_raw::*;
-
-pub const GFP_KERNEL: gfp_t = BINDINGS_GFP_KERNEL;
-pub const __GFP_ZERO: gfp_t = BINDINGS___GFP_ZERO;