[PATCH v14 2/5] rust: add bindings for bitops.h

From: Burak Emir
Date: Wed Aug 13 2025 - 11:38:07 EST


Makes atomic set_bit and clear_bit inline functions as well as the
non-atomic variants __set_bit and __clear_bit available to Rust.
Adds a new MAINTAINERS section BITOPS API BINDINGS [RUST].

Suggested-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Suggested-by: Yury Norov <yury.norov@xxxxxxxxx>
Signed-off-by: Burak Emir <bqe@xxxxxxxxxx>
Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Acked-by: Yury Norov [NVIDIA] <yury.norov@xxxxxxxxx>
---
MAINTAINERS | 5 +++++
rust/helpers/bitops.c | 23 +++++++++++++++++++++++
rust/helpers/helpers.c | 1 +
3 files changed, 29 insertions(+)
create mode 100644 rust/helpers/bitops.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 3950f605dedb..a9ebb2d49dea 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4315,6 +4315,11 @@ F: include/linux/bitops.h
F: lib/test_bitops.c
F: tools/*/bitops*

+BITOPS API BINDINGS [RUST]
+M: Yury Norov <yury.norov@xxxxxxxxx>
+S: Maintained
+F: rust/helpers/bitops.c
+
BLINKM RGB LED DRIVER
M: Jan-Simon Moeller <jansimon.moeller@xxxxxx>
S: Maintained
diff --git a/rust/helpers/bitops.c b/rust/helpers/bitops.c
new file mode 100644
index 000000000000..5d0861d29d3f
--- /dev/null
+++ b/rust/helpers/bitops.c
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/bitops.h>
+
+void rust_helper___set_bit(unsigned long nr, unsigned long *addr)
+{
+ __set_bit(nr, addr);
+}
+
+void rust_helper___clear_bit(unsigned long nr, unsigned long *addr)
+{
+ __clear_bit(nr, addr);
+}
+
+void rust_helper_set_bit(unsigned long nr, volatile unsigned long *addr)
+{
+ set_bit(nr, addr);
+}
+
+void rust_helper_clear_bit(unsigned long nr, volatile unsigned long *addr)
+{
+ clear_bit(nr, addr);
+}
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index 8437736fdf28..abff1ef14d81 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -9,6 +9,7 @@

#include "auxiliary.c"
#include "bitmap.c"
+#include "bitops.c"
#include "blk.c"
#include "bug.c"
#include "build_assert.c"
--
2.51.0.rc0.205.g4a044479a3-goog