Message ID | c9f9975c-b4ae-1234-56ed-dce4b052080d@huawei.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | nvdimm: cleanup resources when the initialization fails | expand |
On Thu, Apr 9, 2020 at 8:16 PM Wu Bo <wubo40@huawei.com> wrote: > > From: Wu Bo <wubo40@huawei.com> > > When the initialization fails, add the cleanup resources > in pmem_attach_disk() function Are you familiar with devm? devm routines take care of this automatically on driver probe error conditions.
On 2020/4/10 11:20, Dan Williams wrote: > On Thu, Apr 9, 2020 at 8:16 PM Wu Bo <wubo40@huawei.com> wrote: >> >> From: Wu Bo <wubo40@huawei.com> >> >> When the initialization fails, add the cleanup resources >> in pmem_attach_disk() function > > Are you familiar with devm? > > devm routines take care of this automatically on driver probe error conditions. > Sorry, i did not pay attention to devm_add_action_or_reset() will automatically call clean up action on driver probe error conditions. Please ignore this patch. thanks.
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index 2df6994..f235a59 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -383,7 +383,7 @@ static int pmem_attach_disk(struct device *dev, struct device *gendev; struct gendisk *disk; void *addr; - int rc; + int rc = -ENOMEM; unsigned long flags = 0UL; pmem = devm_kzalloc(dev, sizeof(*pmem), GFP_KERNEL); @@ -392,14 +392,14 @@ static int pmem_attach_disk(struct device *dev, rc = devm_namespace_enable(dev, ndns, nd_info_block_reserve()); if (rc) - return rc; + goto out_free_pmem; /* while nsio_rw_bytes is active, parse a pfn info block if present */ if (is_nd_pfn(dev)) { nd_pfn = to_nd_pfn(dev); rc = nvdimm_setup_pfn(nd_pfn, &pmem->pgmap); if (rc) - return rc; + goto out_free_pmem; }