diff options
author | Javier González <javier@cnexlabs.com> | 2018-01-05 14:16:04 +0100 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2018-01-05 08:50:12 -0700 |
commit | e29c80e6dd70d60de5db305eecf1aecf707b02e8 (patch) | |
tree | 010bcc9b75eff3af63b0d39dd49aa068003ea299 /drivers/lightnvm | |
parent | fae7fae4077c24dc2be720b9f21f53adea98d7dd (diff) | |
download | linux-stable-e29c80e6dd70d60de5db305eecf1aecf707b02e8.tar.gz linux-stable-e29c80e6dd70d60de5db305eecf1aecf707b02e8.tar.bz2 linux-stable-e29c80e6dd70d60de5db305eecf1aecf707b02e8.zip |
lightnvm: refactor target type lookup
Refactor target type lookup to use/not use locks explicitly instead of
using a hidden parameter to make the function locking.
Signed-off-by: Javier González <javier@cnexlabs.com>
Signed-off-by: Matias Bjørling <m@bjorling.me>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/lightnvm')
-rw-r--r-- | drivers/lightnvm/core.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 6d6d2c12ff5b..5c2d0f3a830b 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -220,21 +220,25 @@ static const struct block_device_operations nvm_fops = { .owner = THIS_MODULE, }; -static struct nvm_tgt_type *nvm_find_target_type(const char *name, int lock) +static struct nvm_tgt_type *__nvm_find_target_type(const char *name) { - struct nvm_tgt_type *tmp, *tt = NULL; + struct nvm_tgt_type *tt; - if (lock) - down_write(&nvm_tgtt_lock); + list_for_each_entry(tt, &nvm_tgt_types, list) + if (!strcmp(name, tt->name)) + return tt; - list_for_each_entry(tmp, &nvm_tgt_types, list) - if (!strcmp(name, tmp->name)) { - tt = tmp; - break; - } + return NULL; +} + +static struct nvm_tgt_type *nvm_find_target_type(const char *name) +{ + struct nvm_tgt_type *tt; + + down_write(&nvm_tgtt_lock); + tt = __nvm_find_target_type(name); + up_write(&nvm_tgtt_lock); - if (lock) - up_write(&nvm_tgtt_lock); return tt; } @@ -249,7 +253,7 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) void *targetdata; int ret; - tt = nvm_find_target_type(create->tgttype, 1); + tt = nvm_find_target_type(create->tgttype); if (!tt) { pr_err("nvm: target type %s not found\n", create->tgttype); return -EINVAL; @@ -523,7 +527,7 @@ int nvm_register_tgt_type(struct nvm_tgt_type *tt) int ret = 0; down_write(&nvm_tgtt_lock); - if (nvm_find_target_type(tt->name, 0)) + if (__nvm_find_target_type(tt->name)) ret = -EEXIST; else list_add(&tt->list, &nvm_tgt_types); |