diff options
author | Aleksandr Miloserdov <a.miloserdov@yadro.com> | 2022-10-26 12:31:33 +0400 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2022-11-09 14:28:27 +0100 |
commit | becc4cac309dc867571f0080fde4426a6c2222e0 (patch) | |
tree | 5d3cf283531e5fa848358e7ae66279d364004f23 /drivers/nvme/target | |
parent | nvme: quiet user passthrough command errors (diff) | |
download | linux-dev-becc4cac309dc867571f0080fde4426a6c2222e0.tar.xz linux-dev-becc4cac309dc867571f0080fde4426a6c2222e0.zip |
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: Konstantin Shelekhin <k.shelekhin@yadro.com>
Reviewed-by: Dmitriy Bogdanov <d.bogdanov@yadro.com>
Signed-off-by: Aleksandr Miloserdov <a.miloserdov@yadro.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to '')
-rw-r--r-- | drivers/nvme/target/configfs.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c index 9443ee1d4ae3..d0b9eea15ff8 100644 --- a/drivers/nvme/target/configfs.c +++ b/drivers/nvme/target/configfs.c @@ -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; } |