Commit becc4cac authored by Aleksandr Miloserdov's avatar Aleksandr Miloserdov Committed by Christoph Hellwig

nvmet: fix memory leak in nvmet_subsys_attr_model_store_locked

Since model_number is allocated before it needs to be freed before
kmemdump_nul.
Reviewed-by: default avatarKonstantin Shelekhin <k.shelekhin@yadro.com>
Reviewed-by: default avatarDmitriy Bogdanov <d.bogdanov@yadro.com>
Signed-off-by: default avatarAleksandr Miloserdov <a.miloserdov@yadro.com>
Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent d7ac8dca
......@@ -1215,6 +1215,7 @@ static ssize_t nvmet_subsys_attr_model_store_locked(struct nvmet_subsys *subsys,
const char *page, size_t count)
{
int pos = 0, len;
char *val;
if (subsys->subsys_discovered) {
pr_err("Can't set model number. %s is already assigned\n",
......@@ -1237,9 +1238,11 @@ static ssize_t nvmet_subsys_attr_model_store_locked(struct nvmet_subsys *subsys,
return -EINVAL;
}
subsys->model_number = kmemdup_nul(page, len, GFP_KERNEL);
if (!subsys->model_number)
val = kmemdup_nul(page, len, GFP_KERNEL);
if (!val)
return -ENOMEM;
kfree(subsys->model_number);
subsys->model_number = val;
return count;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment