nvme-pci: return -EINVAL when failing to parse quirk parameter
PATCH 1/1 nvme-pci: return -EINVAL when failing to parse quirk parameter
In quirks_param_set(), if nvme_parse_quirk_entry() fails to parse an entry from the user-provided quirks string, the function prints an error message with pr_err() and jumps to out_free_qlist to free resources.
However, the variable 'err' is not updated upon parse failure, retaining the value '0' from the preceding call to param_set_copystring(). As a result, quirks_param_set() frees the allocated memory but returns 0 (success) to the kernel parameter subsystem, silently masking the parsing failure and incorrectly reporting success to the caller.
Fix this by explicitly setting 'err = -EINVAL;' before jumping to out_free_qlist, ensuring that parse failures are correctly propagated to the caller.
--- drivers/nvme/host/pci.c | 1 + 1 file changed, 1 insertion(+)
drivers/nvme/host/pci.c +1 -0
@@ -213,6 +213,7 @@ static int quirks_param_set(const char *value, const struct kernel_param *kp)if (nvme_parse_quirk_entry (field, &qlist[i])) {pr_err ("nvme: failed to parse quirk string %s\n" , value); + err = -EINVAL ; goto out_free_qlist; }
Signature · 1 line
2.54.0
Looks good:
Keith Busch
maintainerQuoted 12 lines · Sreeraj S Kurup
In
quirks_param_set(), ifnvme_parse_quirk_entry()fails to parse an entry from the user-provided quirks string, the function prints an error message withpr_err()and jumps toout_free_qlistto free resources.However, the variable 'err' is not updated upon parse failure, retaining the value '0' from the preceding call to
param_set_copystring(). As a result,quirks_param_set()frees the allocated memory but returns 0 (success) to the kernel parameter subsystem, silently masking the parsing failure and incorrectly reporting success to the caller.
Quoted 3 lines
Fix this by explicitly setting 'err =
-EINVAL;' before jumping toout_free_qlist, ensuring that parse failures are correctly propagated to the caller.
This fix was submitted earlier: