lightnvm: pblk: avoid ref warning on cache creation
The current kref implementation around pblk global caches triggers a
false positive on refcount_inc_checked() (when called) as the kref is
initialized to 0. Instead of usint kref_inc() on a 0 reference, which is
in principle correct, use kref_init() to avoid the check. This is also
more explicit about what actually happens on cache creation.
In the process, do a small refactoring to use kref helpers.
Fixes: 1864de94ec
"lightnvm: pblk: stop recreating global caches"
Signed-off-by: Javier González <javier@cnexlabs.com>
Reviewed-by: Hans Holmberg <hans.holmberg@cnexlabs.com>
Signed-off-by: Matias Bjørling <mb@lightnvm.io>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
85136c0102
commit
42bd0384d7
1 changed files with 5 additions and 9 deletions
|
@ -347,23 +347,19 @@ fail_destroy_ws:
|
||||||
|
|
||||||
static int pblk_get_global_caches(void)
|
static int pblk_get_global_caches(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = 0;
|
||||||
|
|
||||||
mutex_lock(&pblk_caches.mutex);
|
mutex_lock(&pblk_caches.mutex);
|
||||||
|
|
||||||
if (kref_read(&pblk_caches.kref) > 0) {
|
if (kref_get_unless_zero(&pblk_caches.kref))
|
||||||
kref_get(&pblk_caches.kref);
|
goto out;
|
||||||
mutex_unlock(&pblk_caches.mutex);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = pblk_create_global_caches();
|
ret = pblk_create_global_caches();
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
kref_get(&pblk_caches.kref);
|
kref_init(&pblk_caches.kref);
|
||||||
|
|
||||||
|
out:
|
||||||
mutex_unlock(&pblk_caches.mutex);
|
mutex_unlock(&pblk_caches.mutex);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue