diff options
| author | Andy Shevchenko <[email protected]> | 2019-12-05 00:53:26 +0000 |
|---|---|---|
| committer | Linus Torvalds <[email protected]> | 2019-12-05 03:44:14 +0000 |
| commit | 30544ed5de431fe25d3793e4dd5a058d877c4d77 (patch) | |
| tree | 4e61a782d8482dc987228ecddd854441f9bb6f68 /lib/bitmap.c | |
| parent | lib/test_bitmap: fix comment about this file (diff) | |
| download | kernel-30544ed5de431fe25d3793e4dd5a058d877c4d77.tar.gz kernel-30544ed5de431fe25d3793e4dd5a058d877c4d77.zip | |
lib/bitmap: introduce bitmap_replace() helper
In some drivers we want to have a single operation over bitmap which is
an equivalent to:
*dst = (*old & ~(*mask)) | (*new & *mask)
Introduce bitmap_replace() helper for this.
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Andy Shevchenko <[email protected]>
Acked-by: Linus Walleij <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: William Breathitt Gray <[email protected]>
Cc: Yury Norov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
Diffstat (limited to 'lib/bitmap.c')
| -rw-r--r-- | lib/bitmap.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/bitmap.c b/lib/bitmap.c index f9e834841e94..4250519d7d1c 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -222,6 +222,18 @@ int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1, } EXPORT_SYMBOL(__bitmap_andnot); +void __bitmap_replace(unsigned long *dst, + const unsigned long *old, const unsigned long *new, + const unsigned long *mask, unsigned int nbits) +{ + unsigned int k; + unsigned int nr = BITS_TO_LONGS(nbits); + + for (k = 0; k < nr; k++) + dst[k] = (old[k] & ~mask[k]) | (new[k] & mask[k]); +} +EXPORT_SYMBOL(__bitmap_replace); + int __bitmap_intersects(const unsigned long *bitmap1, const unsigned long *bitmap2, unsigned int bits) { |
