From: Luis Chamberlain mcgrof@kernel.org
mainline inclusion from mainline-v5.16-rc1 commit 5a192ccc32e2981f721343c750b8cfb4c3f41007 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IAD301 CVE: NA
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
--------------------------------
Now that device_add_disk() supports returning an error, use that. We must unwind alloc_dax() on error.
Reviewed-by: Christoph Hellwig hch@lst.de Signed-off-by: Luis Chamberlain mcgrof@kernel.org Link: https://lore.kernel.org/r/20211103230437.1639990-7-mcgrof@kernel.org Signed-off-by: Jens Axboe axboe@kernel.dk Conflicts: drivers/nvdimm/pmem.c [ Commit accf58afb689f81daadde("nvdimm/pmem: cleanup the disk if pmem_release_disk() is yet assigned") is not applied. ] Signed-off-by: Zhihao Cheng chengzhihao1@huawei.com --- drivers/nvdimm/pmem.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index d5dd79b59b16..9947cc2bd2fc 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -498,7 +498,13 @@ static int pmem_attach_disk(struct device *dev, gendev = disk_to_dev(disk); gendev->groups = pmem_attribute_groups;
- device_add_disk(dev, disk, NULL); + rc = device_add_disk_safe(dev, disk, NULL); + if (rc) { + kill_dax(dax_dev); + put_dax(dax_dev); + put_disk(disk); + return rc; + } if (devm_add_action_or_reset(dev, pmem_release_disk, pmem)) return -ENOMEM;