Commit bbdaa8c1 authored by Maurizio Lombardi's avatar Maurizio Lombardi Committed by Keith Busch
Browse files

nvme: fix memory leak in quirks_param_set()



When loading the nvme module, if the 'quirks' parameter is specified
via both the kernel command line (e.g., nvme.quirks=...) and the
modprobe command line (e.g., modprobe nvme quirks=...), the
quirks_param_set() callback is invoked twice.

Currently, in the double-invocation scenario, the second call
overwrites the nvme_pci_quirk_list pointer, causing the memory
allocated in the first call to leak.

Fix this by freeing the existing list before assigning the new one.

Fixes: b4247c8317c5 ("nvme: add support for dynamic quirk configuration via module parameter")
Reviewed-by: default avatarDaniel Wagner <dwagner@suse.de>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarMaurizio Lombardi <mlombard@redhat.com>
Signed-off-by: default avatarKeith Busch <kbusch@kernel.org>
parent 3ddfbfbc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -219,6 +219,7 @@ static int quirks_param_set(const char *value, const struct kernel_param *kp)
		i++;
	}

	kfree(nvme_pci_quirk_list);
	nvme_pci_quirk_count = count;
	nvme_pci_quirk_list  = qlist;
	goto out_free_val;