Re: [PATCH v5 2/4] rust: add bindings for bitops.h

From: Yury Norov
Date: Fri Mar 21 2025 - 12:05:32 EST


On Fri, Mar 21, 2025 at 11:15:30AM +0000, Burak Emir wrote:
> 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>
> Signed-off-by: Burak Emir <bqe@xxxxxxxxxx>
> ---
> 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 52fc47a28b4c..7cd15c25a43c 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -4128,6 +4128,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..2eaab292db4f
> --- /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 int nr, unsigned long *addr)
> +{
> + __set_bit(nr, addr);
> +}
> +
> +void rust_helper___clear_bit(unsigned int nr, unsigned long *addr)
> +{
> + __clear_bit(nr, addr);
> +}
> +
> +void rust_helper_set_bit(unsigned int nr, unsigned long *addr)

volatile

> +{
> + set_bit(nr, addr);
> +}
> +
> +void rust_helper_clear_bit(unsigned int nr, unsigned long *addr)
> +{
> + clear_bit(nr, addr);
> +}
> diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
> index d4a60f1d6cc4..0c25cc86a52a 100644
> --- a/rust/helpers/helpers.c
> +++ b/rust/helpers/helpers.c
> @@ -8,6 +8,7 @@
> */
>
> #include "bitmap.c"
> +#include "bitops.c"
> #include "blk.c"
> #include "bug.c"
> #include "build_assert.c"
> --
> 2.49.0.395.g12beb8f557-goog