Re: [PATCH] sbitmap: reset alloc_hint to NULL after freeing
From: Bart Van Assche
Date: Wed Dec 02 2026 - 10:02:49 EST
On 12/1/26 8:15 PM, Thanh Nguyen wrote:
diff --git a/include/linux/sbitmap.h b/include/linux/sbitmap.h
index cc7ad189c..620480e33 100644
--- a/include/linux/sbitmap.h
+++ b/include/linux/sbitmap.h
@@ -185,6 +185,7 @@ static inline unsigned int __map_depth(const struct sbitmap *sb, int index)
static inline void sbitmap_free(struct sbitmap *sb)
{
free_percpu(sb->alloc_hint);
+ sb->alloc_hint = NULL;
kvfree(sb->map);
sb->map = NULL;
}
diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index 4d188d05d..59879e27d 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -119,6 +119,7 @@ int sbitmap_init_node(struct sbitmap *sb, unsigned int depth, int shift,
if (depth == 0) {
sb->map = NULL;
+ sb->alloc_hint = NULL;
return 0;
}
@@ -132,6 +133,7 @@ int sbitmap_init_node(struct sbitmap *sb, unsigned int depth, int shift,
sb->map = kvzalloc_node(sb->map_nr * sizeof(*sb->map), flags, node);
if (!sb->map) {
free_percpu(sb->alloc_hint);
+ sb->alloc_hint = NULL;
return -ENOMEM;
}
This patch looks more complete to me:
https://lore.kernel.org/linux-block/d8da37180d44f60c0d4345683bfa2e3a2cfb8335.1795999192.git.bvanassche@xxxxxxx/
Thanks,
Bart.