]> www.infradead.org Git - nvme.git/commit
nvme: split device add from initialization
authorKeith Busch <kbusch@kernel.org>
Tue, 4 Jun 2024 18:59:08 +0000 (11:59 -0700)
committerKeith Busch <kbusch@kernel.org>
Mon, 24 Jun 2024 19:53:42 +0000 (12:53 -0700)
commit1a9e218195a55d0a31e8cbe263aa2f618580ef1d
tree7d2a55dc57ecfdb8e7d67edb303ce0be621fd52e
parent72cded7573c8c038f999e49c77d1097efcfd15aa
nvme: split device add from initialization

Combining both creates an ambiguous cleanup scenario for the caller if
an error is returned: does the device reference need to be dropped or
did the error occur before the device was initialized? If an error
occurs after the device is added, then the existing cleanup routines
will leak memory.

Furthermore, the nvme core is taking it upon itself to free the device's
kobj name under certain conditions rather than go through the core
device API. We shouldn't be peaking into these implementation details.

Split the device initialization from the addition to make it easier to
know the error handling actions, fix the existing memory leaks, and stop
the device layering violations.

Link: https://lore.kernel.org/linux-nvme/c4050a37-ecc9-462c-9772-65e25166f439@grimberg.me/
Tested-by: Yi Zhang <yi.zhang@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
drivers/nvme/host/apple.c
drivers/nvme/host/core.c
drivers/nvme/host/fc.c
drivers/nvme/host/nvme.h
drivers/nvme/host/pci.c
drivers/nvme/host/rdma.c
drivers/nvme/host/tcp.c
drivers/nvme/target/loop.c