Skip to contentSkip to conversation

bitops.h: Remove unused bitops function test_and_change_bit()

PATCH John Snow 3 participants 3 messages Apr 3, 2019 – Apr 4, 2019 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

John Snow

author Reviewed-by
#1 lore raw
Quoted 39 lines · Zhang Chen

From: Zhang Chen <[email protected]>

In current codes we use change_bit() to finish the job.

---
 include/qemu/bitmap.h |  1 -
 include/qemu/bitops.h | 15 ---------------
 2 files changed, 16 deletions(-)
include/qemu/bitmap.h +0 -1
index 5c313346b9..6b71ef631c 100644
@@ -52,7 +52,6 @@
  * test_bit(bit, addr)			Is bit set in *addr?
  * test_and_set_bit(bit, addr)		Set bit and return old value
  * test_and_clear_bit(bit, addr)	Clear bit and return old value
- * test_and_change_bit(bit, addr)	Change bit and return old value
  * find_first_zero_bit(addr, nbits)	Position first zero bit in *addr
  * find_first_bit(addr, nbits)		Position first set bit in *addr
  * find_next_zero_bit(addr, nbits, bit)	Position next zero bit in *addr >= bit
include/qemu/bitops.h +0 -8
index 3f0926cf40..1f98ffcdc0 100644
@@ -109,21 +109,6 @@ static inline int test_and_clear_bit(long nr, unsigned long *addr)
     return (old & mask) != 0;
 }
 
-/**
- * test_and_change_bit - Change a bit and return its old value
- * @nr: Bit to change
- * @addr: Address to count from
- */
-static inline int test_and_change_bit(long nr, unsigned long *addr)
-{
-    unsigned long mask = BIT_MASK(nr);

include/qemu/bitops.h static inline int test_and_clear_bit(long nr, unsigned long *addr) · line 114

Quoted 10 lines
include/qemu/bitops.h +0 -7
-    unsigned long *p = addr + BIT_WORD(nr);
-    unsigned long old = *p;
-
-    *p = old ^ mask;
-    return (old & mask) != 0;
-}
-
 /**
  * test_bit - Determine whether a bit is set
  * @nr: bit number to test

I personally don't see the harm in keeping this, but it is indeed unused, so:

As for merging other sibling functions, I guess the desire is a small decrease in SLOC; I'm not sure if you'll run into any uses where the changed signatures for a combined function causes issues. I am not sure it's worth the hassle.

#2 lore raw
In reply to a message not in the archive
Quoted 10 lines · Zhang Chen

From: Zhang Chen <[email protected]>

In current codes we use change_bit() to finish the job.

---
 include/qemu/bitmap.h |  1 -
 include/qemu/bitops.h | 15 ---------------
 2 files changed, 16 deletions(-)

Do we gain anything by removing this function? IIRC these functions are all borrowed from the Linux kernel, so keeping the same API as the kernel does would make sense to me, even if we happen not to use all of it right now.

thanks
-- PMM

#3 lore raw
Quoted 24 lines

-----Original Message-----
From: Peter Maydell [mailto:[email protected]]
Sent: Thursday, April 4, 2019 9:43 AM
To: Zhang, Chen <[email protected]>
Cc: Dr. David Alan Gilbert <[email protected]>; qemu-dev <qemu- [email protected]>; John Snow <[email protected]>; Fam Zheng <[email protected]>
Subject: Re: [Qemu-devel] [PATCH] bitops.h: Remove unused bitops function test_and_change_bit()

Quoted 10 lines · Zhang Chen

From: Zhang Chen <[email protected]>

In current codes we use change_bit() to finish the job.

---
 include/qemu/bitmap.h |  1 -
 include/qemu/bitops.h | 15 ---------------
 2 files changed, 16 deletions(-)
Quoted 4 lines

Do we gain anything by removing this function? IIRC these functions are all borrowed from the Linux kernel, so keeping the same API as the kernel does would make sense to me, even if we happen not to use all of it right now.

Hi Peter,

OK, I agree with you.
But another question are the bitmap.h and bitops.h lack of maintenance. Please look at this patch:
[PATCH] MAINTAINERS: Add unmaintained bitmap file to related field

Do you have any comments?

Thanks
Zhang Chen

Quoted 2 lines

thanks
-- PMM