aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/lightnvm/pblk-init.c
diff options
context:
space:
mode:
authorJavier González <javier@javigon.com>2018-12-11 14:16:21 -0500
committerJens Axboe <axboe@kernel.dk>2018-12-11 14:22:34 -0500
commit42bd0384d77ef7552954056928018f5cfa91a013 (patch)
treecf6d0cf36fb17c73e75606ef2f9247fad68ef25f /drivers/lightnvm/pblk-init.c
parent85136c0102852fe505c0fbd3f1bf9d17038bb94d (diff)
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: 1864de94ec9d6 "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>
Diffstat (limited to 'drivers/lightnvm/pblk-init.c')
-rw-r--r--drivers/lightnvm/pblk-init.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
index 0e37104de596..72ad3e70318c 100644
--- a/drivers/lightnvm/pblk-init.c
+++ b/drivers/lightnvm/pblk-init.c
@@ -347,23 +347,19 @@ fail_destroy_ws:
347 347
348static int pblk_get_global_caches(void) 348static int pblk_get_global_caches(void)
349{ 349{
350 int ret; 350 int ret = 0;
351 351
352 mutex_lock(&pblk_caches.mutex); 352 mutex_lock(&pblk_caches.mutex);
353 353
354 if (kref_read(&pblk_caches.kref) > 0) { 354 if (kref_get_unless_zero(&pblk_caches.kref))
355 kref_get(&pblk_caches.kref); 355 goto out;
356 mutex_unlock(&pblk_caches.mutex);
357 return 0;
358 }
359 356
360 ret = pblk_create_global_caches(); 357 ret = pblk_create_global_caches();
361
362 if (!ret) 358 if (!ret)
363 kref_get(&pblk_caches.kref); 359 kref_init(&pblk_caches.kref);
364 360
361out:
365 mutex_unlock(&pblk_caches.mutex); 362 mutex_unlock(&pblk_caches.mutex);
366
367 return ret; 363 return ret;
368} 364}
369 365