aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
authorLinus Torvalds <torvalds@linux-foundation.org>2026-06-17 11:38:38 +0100
committerLinus Torvalds <torvalds@linux-foundation.org>2026-06-17 11:38:38 +0100
commit59a6c7ac0a47154774cb44c59a8735f6a16b75f7 (patch)
tree99e3375faeac2b20e06fc21dc144e8227c07a447 /lib
parent8479bb8c44fdabe3d123735347af95002828d112 (diff)
parent7b2c5b4e43aa2fdf6c63e24df26370c4a5c27f78 (diff)
downloadath-59a6c7ac0a47154774cb44c59a8735f6a16b75f7.tar.gz
Merge tag 'bitmap-for-7.2' of https://github.com/norov/linux
Pull bitmap updates from Yury Norov: "This includes the new FIELD_GET_SIGNED() helper, bitmap_print_to_pagebuf() removal, RISCV/bitrev support, and a couple cleanups. - new handy helper FIELD_GET_SIGNED() (Yury) - arch test_and_set_bit_lock() and clear_bit_unlock() cleanup (Randy) - __bf_shf() simplification (Yury) - bitmap_print_to_pagebuf() removal (Yury) - RISCV/bitrev conditional support (Jindie, Yury)" * tag 'bitmap-for-7.2' of https://github.com/norov/linux: MAINTAINERS: BITOPS: include bitrev.[ch] arch/riscv: Add bitrev.h file to support rev8 and brev8 bitops: Define generic___bitrev8/16/32 for reuse lib/bitrev: Introduce GENERIC_BITREVERSE arch: select HAVE_ARCH_BITREVERSE conditionally on BITREVERSE bitmap: fix find helper documentation bitmap: drop bitmap_print_to_pagebuf() cpumask: switch cpumap_print_to_pagebuf() to using scnprintf() bitfield: wire __bf_shf to __builtin_ctzll bitops: use common function parameter names ptp: switch to using FIELD_GET_SIGNED() rtc: rv3032: switch to using FIELD_GET_SIGNED() wifi: rtw89: switch to using FIELD_GET_SIGNED() iio: mcp9600: switch to using FIELD_GET_SIGNED() iio: pressure: bmp280: switch to using FIELD_GET_SIGNED() iio: magnetometer: yas530: switch to using FIELD_GET_SIGNED() iio: intel_dc_ti_adc: switch to using FIELD_GET_SIGNED() x86/extable: switch to using FIELD_GET_SIGNED() bitfield: add FIELD_GET_SIGNED()
Diffstat (limited to 'lib')
-rw-r--r--lib/Kconfig13
-rw-r--r--lib/Makefile2
-rw-r--r--lib/bitmap-str.c42
-rw-r--r--lib/bitrev.c3
4 files changed, 19 insertions, 41 deletions
diff --git a/lib/Kconfig b/lib/Kconfig
index 00a9509636c18..a33988adfaa3e 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -54,14 +54,27 @@ config PACKING_KUNIT_TEST
config BITREVERSE
tristate
+ select GENERIC_BITREVERSE if !HAVE_ARCH_BITREVERSE
config HAVE_ARCH_BITREVERSE
bool
default n
+ depends on BITREVERSE
help
This option enables the use of hardware bit-reversal instructions on
architectures which support such operations.
+config GENERIC_BITREVERSE
+ tristate
+ depends on BITREVERSE
+ help
+ Generic bit reversal implementation. Drivers should never enable
+ it explicitly. Instead, enable BITREVERSE.
+
+ Architectures may want to select it as a fall-back option for
+ HAVE_ARCH_BITREVERSE, when the hardware-accelerated bit reverse
+ instruction set is optional, like RISC-V ZBKB extension.
+
config ARCH_HAS_STRNCPY_FROM_USER
bool
diff --git a/lib/Makefile b/lib/Makefile
index f33a24bf1c19a..23e07d19d01c9 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -145,7 +145,7 @@ obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
obj-$(CONFIG_LIST_HARDENED) += list_debug.o
obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
-obj-$(CONFIG_BITREVERSE) += bitrev.o
+obj-$(CONFIG_GENERIC_BITREVERSE) += bitrev.o
obj-$(CONFIG_LINEAR_RANGES) += linear_ranges.o
obj-$(CONFIG_PACKING) += packing.o
obj-$(CONFIG_PACKING_KUNIT_TEST) += packing_test.o
diff --git a/lib/bitmap-str.c b/lib/bitmap-str.c
index be745209507a4..26d36c938c6af 100644
--- a/lib/bitmap-str.c
+++ b/lib/bitmap-str.c
@@ -40,32 +40,6 @@ int bitmap_parse_user(const char __user *ubuf,
EXPORT_SYMBOL(bitmap_parse_user);
/**
- * bitmap_print_to_pagebuf - convert bitmap to list or hex format ASCII string
- * @list: indicates whether the bitmap must be list
- * @buf: page aligned buffer into which string is placed
- * @maskp: pointer to bitmap to convert
- * @nmaskbits: size of bitmap, in bits
- *
- * Output format is a comma-separated list of decimal numbers and
- * ranges if list is specified or hex digits grouped into comma-separated
- * sets of 8 digits/set. Returns the number of characters written to buf.
- *
- * It is assumed that @buf is a pointer into a PAGE_SIZE, page-aligned
- * area and that sufficient storage remains at @buf to accommodate the
- * bitmap_print_to_pagebuf() output. Returns the number of characters
- * actually printed to @buf, excluding terminating '\0'.
- */
-int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp,
- int nmaskbits)
-{
- ptrdiff_t len = PAGE_SIZE - offset_in_page(buf);
-
- return list ? scnprintf(buf, len, "%*pbl\n", nmaskbits, maskp) :
- scnprintf(buf, len, "%*pb\n", nmaskbits, maskp);
-}
-EXPORT_SYMBOL(bitmap_print_to_pagebuf);
-
-/**
* bitmap_print_to_buf - convert bitmap to list or hex format ASCII string
* @list: indicates whether the bitmap must be list
* true: print in decimal list format
@@ -101,7 +75,7 @@ static int bitmap_print_to_buf(bool list, char *buf, const unsigned long *maskp,
* @off: in the string from which we are copying, We copy to @buf
* @count: the maximum number of bytes to print
*
- * The bitmap_print_to_pagebuf() is used indirectly via its cpumap wrapper
+ * The sprintf("%*pb[l]") is used indirectly via its cpumap wrapper
* cpumap_print_to_pagebuf() or directly by drivers to export hexadecimal
* bitmask and decimal list to userspace by sysfs ABI.
* Drivers might be using a normal attribute for this kind of ABIs. A
@@ -111,18 +85,11 @@ static int bitmap_print_to_buf(bool list, char *buf, const unsigned long *maskp,
* struct device_attribute *attr, char *buf)
* {
* ...
- * return bitmap_print_to_pagebuf(true, buf, &mask, nr_trig_max);
+ * return scnprintf(buf, PAGE_SIZE - offset_in_page(buf), nr_trig_max, &mask);
* }
*
* show entry of attribute has no offset and count parameters and this
* means the file is limited to one page only.
- * bitmap_print_to_pagebuf() API works terribly well for this kind of
- * normal attribute with buf parameter and without offset, count::
- *
- * bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp,
- * int nmaskbits)
- * {
- * }
*
* The problem is once we have a large bitmap, we have a chance to get a
* bitmask or list more than one page. Especially for list, it could be
@@ -149,7 +116,7 @@ static int bitmap_print_to_buf(bool list, char *buf, const unsigned long *maskp,
*
* The role of cpumap_print_bitmask_to_buf() and cpumap_print_list_to_buf()
* is similar with cpumap_print_to_pagebuf(), the difference is that
- * bitmap_print_to_pagebuf() mainly serves sysfs attribute with the assumption
+ * scnprintf("%*pb[l]") mainly serves sysfs attribute with the assumption
* the destination buffer is exactly one page and won't be more than one page.
* cpumap_print_bitmask_to_buf() and cpumap_print_list_to_buf(), on the other
* hand, mainly serves bin_attribute which doesn't work with exact one page,
@@ -158,7 +125,8 @@ static int bitmap_print_to_buf(bool list, char *buf, const unsigned long *maskp,
*
* WARNING!
*
- * This function is not a replacement for sprintf() or bitmap_print_to_pagebuf().
+ * This function is not a replacement for sprintf().
+ *
* It is intended to workaround sysfs limitations discussed above and should be
* used carefully in general case for the following reasons:
*
diff --git a/lib/bitrev.c b/lib/bitrev.c
index 81b56e0a7f325..05088231f31fd 100644
--- a/lib/bitrev.c
+++ b/lib/bitrev.c
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: GPL-2.0-only
-#ifndef CONFIG_HAVE_ARCH_BITREVERSE
#include <linux/types.h>
#include <linux/module.h>
#include <linux/bitrev.h>
@@ -43,5 +42,3 @@ const u8 byte_rev_table[256] = {
0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
};
EXPORT_SYMBOL_GPL(byte_rev_table);
-
-#endif /* CONFIG_HAVE_ARCH_BITREVERSE */