From: Gokul K <gokul02k@gmail.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org
Cc: Shuah Khan <shuah@kernel.org>,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] KVM: selftests: Delete the unused sparsebit copy and count helpers
Date: Fri, 18 Sep 2026 17:06:29 +0530 [thread overview]
Message-ID: <20260918113631.634233-2-gokul02k@gmail.com> (raw)
In-Reply-To: <20260918113631.634233-1-gokul02k@gmail.com>
sparsebit_copy() and sparsebit_num_set() have no callers. Nor does the
FUZZ harness at the bottom of lib/sparsebit.c, which exercises most of
the rest of the API and still builds and links with both removed.
sparsebit_copy() was the only non-recursive caller of
node_copy_subtree(), which leaves that unreachable too. It is static,
so keeping it would trip -Wunused-function; delete it as well.
The comment on the num_set member gives sparsebit_num_set() as the
reason the count is maintained. The member stays - it is what lets
sparsebit_all_set() answer in O(1), and the dump path prints it - so
point the comment at what still uses it.
No functional change intended.
Signed-off-by: Gokul K <gokul02k@gmail.com>
---
.../testing/selftests/kvm/include/sparsebit.h | 2 -
tools/testing/selftests/kvm/lib/sparsebit.c | 63 +------------------
2 files changed, 1 insertion(+), 64 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/sparsebit.h b/tools/testing/selftests/kvm/include/sparsebit.h
index e027e5790946..8a2ab11dae6f 100644
--- a/tools/testing/selftests/kvm/include/sparsebit.h
+++ b/tools/testing/selftests/kvm/include/sparsebit.h
@@ -30,7 +30,6 @@ typedef u64 sparsebit_num_t;
struct sparsebit *sparsebit_alloc(void);
void sparsebit_free(struct sparsebit **sbitp);
-void sparsebit_copy(struct sparsebit *dstp, const struct sparsebit *src);
bool sparsebit_is_set(const struct sparsebit *sbit, sparsebit_idx_t idx);
bool sparsebit_is_set_num(const struct sparsebit *sbit,
@@ -38,7 +37,6 @@ bool sparsebit_is_set_num(const struct sparsebit *sbit,
bool sparsebit_is_clear(const struct sparsebit *sbit, sparsebit_idx_t idx);
bool sparsebit_is_clear_num(const struct sparsebit *sbit,
sparsebit_idx_t idx, sparsebit_num_t num);
-sparsebit_num_t sparsebit_num_set(const struct sparsebit *sbit);
bool sparsebit_any_set(const struct sparsebit *sbit);
bool sparsebit_any_clear(const struct sparsebit *sbit);
bool sparsebit_all_set(const struct sparsebit *sbit);
diff --git a/tools/testing/selftests/kvm/lib/sparsebit.c b/tools/testing/selftests/kvm/lib/sparsebit.c
index 4d845000de15..8ce230af4f14 100644
--- a/tools/testing/selftests/kvm/lib/sparsebit.c
+++ b/tools/testing/selftests/kvm/lib/sparsebit.c
@@ -184,8 +184,7 @@ struct sparsebit {
/*
* A redundant count of the total number of bits set. Used for
- * diagnostic purposes and to change the time complexity of
- * sparsebit_num_set() from O(n) to O(1).
+ * diagnostic purposes and to answer sparsebit_all_set() in O(1).
* Note: Due to overflow, a value of 0 means none or all set.
*/
sparsebit_num_t num_set;
@@ -269,39 +268,6 @@ static struct node *node_prev(const struct sparsebit *s, struct node *np)
}
-/* Allocates space to hold a copy of the node sub-tree pointed to by
- * subtree and duplicates the bit settings to the newly allocated nodes.
- * Returns the newly allocated copy of subtree.
- */
-static struct node *node_copy_subtree(const struct node *subtree)
-{
- struct node *root;
-
- /* Duplicate the node at the root of the subtree */
- root = calloc(1, sizeof(*root));
- if (!root) {
- perror("calloc");
- abort();
- }
-
- root->idx = subtree->idx;
- root->mask = subtree->mask;
- root->num_after = subtree->num_after;
-
- /* As needed, recursively duplicate the left and right subtrees */
- if (subtree->left) {
- root->left = node_copy_subtree(subtree->left);
- root->left->parent = root;
- }
-
- if (subtree->right) {
- root->right = node_copy_subtree(subtree->right);
- root->right->parent = root;
- }
-
- return root;
-}
-
/* Searches for and returns a pointer to the node that describes the setting
* of the bit given by idx. A node describes the setting of a bit if its
* index is within the bits described by the mask bits or the number of
@@ -964,22 +930,6 @@ void sparsebit_free(struct sparsebit **sbitp)
*sbitp = NULL;
}
-/* Makes a copy of the sparsebit array given by s, to the sparsebit
- * array given by d. Note, d must have already been allocated via
- * sparsebit_alloc(). It can though already have bits set, which
- * if different from src will be cleared.
- */
-void sparsebit_copy(struct sparsebit *d, const struct sparsebit *s)
-{
- /* First clear any bits already set in the destination */
- sparsebit_clear_all(d);
-
- if (s->root) {
- d->root = node_copy_subtree(s->root);
- d->num_set = s->num_set;
- }
-}
-
/* Returns whether num consecutive bits starting at idx are all set. */
bool sparsebit_is_set_num(const struct sparsebit *s,
sparsebit_idx_t idx, sparsebit_num_t num)
@@ -1035,17 +985,6 @@ bool sparsebit_is_clear_num(const struct sparsebit *s,
return next_set == 0 || next_set - idx >= num;
}
-/* Returns the total number of bits set. Note: 0 is also returned for
- * the case of all bits set. This is because with all bits set, there
- * is 1 additional bit set beyond what can be represented in the return
- * value. Use sparsebit_any_set(), instead of sparsebit_num_set() > 0,
- * to determine if the sparsebit array has any bits set.
- */
-sparsebit_num_t sparsebit_num_set(const struct sparsebit *s)
-{
- return s->num_set;
-}
-
/* Returns whether any bit is set in the sparsebit array. */
bool sparsebit_any_set(const struct sparsebit *s)
{
--
2.54.0
next prev parent reply other threads:[~2026-09-18 11:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 11:36 [PATCH 0/3] KVM: selftests: Delete three pieces of dead library code Gokul K
2026-09-18 11:36 ` Gokul K [this message]
2026-09-18 16:24 ` [PATCH 1/3] KVM: selftests: Delete the unused sparsebit copy and count helpers Sean Christopherson
2026-09-18 11:36 ` [PATCH 2/3] KVM: selftests: Delete the declaration of vcpu_set_cpuid_maxphyaddr() Gokul K
2026-09-18 11:36 ` [PATCH 3/3] KVM: selftests: Delete the unused guest_snprintf() Gokul K
2026-09-18 16:05 ` Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260918113631.634233-2-gokul02k@gmail.com \
--to=gokul02k@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®