提交 6b7e631b 编写于 作者: M Minwoo Im 提交者: Christoph Hellwig

nvmet: return a specified error it subsys_alloc fails

nvmet_subsys_alloc() returns its pointer or NULL if it fails.  We can
see three different steps in this function:
  1. memory allocation
  2. argument check
  3. memory allocation for string

But now the callers of this function do not seem to handle case 2 by
returning -ENOMEM only even if it fails with an invalid parameter.

This patch specifies error codes so that caller can pass it to its own
caller.
Signed-off-by: NMinwoo Im <minwoo.im.dev@gmail.com>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>.
Signed-off-by: NChristoph Hellwig <hch@lst.de>
上级 fc6c9730
...@@ -898,8 +898,8 @@ static struct config_group *nvmet_subsys_make(struct config_group *group, ...@@ -898,8 +898,8 @@ static struct config_group *nvmet_subsys_make(struct config_group *group,
} }
subsys = nvmet_subsys_alloc(name, NVME_NQN_NVME); subsys = nvmet_subsys_alloc(name, NVME_NQN_NVME);
if (!subsys) if (IS_ERR(subsys))
return ERR_PTR(-ENOMEM); return ERR_CAST(subsys);
config_group_init_type_name(&subsys->group, name, &nvmet_subsys_type); config_group_init_type_name(&subsys->group, name, &nvmet_subsys_type);
......
...@@ -1367,7 +1367,7 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn, ...@@ -1367,7 +1367,7 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,
subsys = kzalloc(sizeof(*subsys), GFP_KERNEL); subsys = kzalloc(sizeof(*subsys), GFP_KERNEL);
if (!subsys) if (!subsys)
return NULL; return ERR_PTR(-ENOMEM);
subsys->ver = NVME_VS(1, 3, 0); /* NVMe 1.3.0 */ subsys->ver = NVME_VS(1, 3, 0); /* NVMe 1.3.0 */
/* generate a random serial number as our controllers are ephemeral: */ /* generate a random serial number as our controllers are ephemeral: */
...@@ -1383,14 +1383,14 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn, ...@@ -1383,14 +1383,14 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,
default: default:
pr_err("%s: Unknown Subsystem type - %d\n", __func__, type); pr_err("%s: Unknown Subsystem type - %d\n", __func__, type);
kfree(subsys); kfree(subsys);
return NULL; return ERR_PTR(-EINVAL);
} }
subsys->type = type; subsys->type = type;
subsys->subsysnqn = kstrndup(subsysnqn, NVMF_NQN_SIZE, subsys->subsysnqn = kstrndup(subsysnqn, NVMF_NQN_SIZE,
GFP_KERNEL); GFP_KERNEL);
if (!subsys->subsysnqn) { if (!subsys->subsysnqn) {
kfree(subsys); kfree(subsys);
return NULL; return ERR_PTR(-ENOMEM);
} }
kref_init(&subsys->ref); kref_init(&subsys->ref);
......
...@@ -372,8 +372,8 @@ int __init nvmet_init_discovery(void) ...@@ -372,8 +372,8 @@ int __init nvmet_init_discovery(void)
{ {
nvmet_disc_subsys = nvmet_disc_subsys =
nvmet_subsys_alloc(NVME_DISC_SUBSYS_NAME, NVME_NQN_DISC); nvmet_subsys_alloc(NVME_DISC_SUBSYS_NAME, NVME_NQN_DISC);
if (!nvmet_disc_subsys) if (IS_ERR(nvmet_disc_subsys))
return -ENOMEM; return PTR_ERR(nvmet_disc_subsys);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册