[PATCH nvme-7.3 v2 3/4] nvme-fabrics: reuse string helper for subsystem NQN
From: raoxu
Date: Thu Aug 27 2026 - 09:34:03 EST
From: Xu Rao <raoxu@xxxxxxxxxxxxx>
The subsystem NQN starts with the same owned-string replacement sequence
as the direct string options handled by nvmf_parse_string_option():
duplicate the matched value, free the previously stored string, and
transfer ownership of the new allocation.
Reuse nvmf_parse_string_option() for that replacement only. Leave the
existing NQN length validation and discovery-NQN update unchanged. The
hostnqn and hostid parsing paths are also left untouched.
This removes another copy of the match_strdup(), free and
ownership-transfer sequence without introducing a dedicated helper or
changing option-specific logic.
No functional change is intended.
Suggested-by: Christoph Hellwig <hch@xxxxxx>
Signed-off-by: Xu Rao <raoxu@xxxxxxxxxxxxx>
---
drivers/nvme/host/fabrics.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index aab3fd279d0e..24385e777307 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -773,13 +773,9 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
goto out;
break;
case NVMF_OPT_NQN:
- p = match_strdup(args);
- if (!p) {
- ret = -ENOMEM;
+ ret = nvmf_parse_string_option(args, &opts->subsysnqn);
+ if (ret)
goto out;
- }
- kfree(opts->subsysnqn);
- opts->subsysnqn = p;
nqnlen = strlen(opts->subsysnqn);
if (nqnlen >= NVMF_NQN_SIZE) {
pr_err("%s needs to be < %d bytes\n",
--
2.50.1