Skip to content

Commit b613521

Browse files
Yi Yangweiny2
authored andcommitted
nvdimm: rectify the illogical code within nd_dax_probe()
When nd_dax is NULL, nd_pfn is consequently NULL as well. Nevertheless, it is inadvisable to perform pointer arithmetic or address-taking on a NULL pointer. Introduce the nd_dax_devinit() function to enhance the code's logic and improve its readability. Signed-off-by: Yi Yang <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Ira Weiny <[email protected]>
1 parent f7f5074 commit b613521

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

drivers/nvdimm/dax_devs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns)
106106

107107
nvdimm_bus_lock(&ndns->dev);
108108
nd_dax = nd_dax_alloc(nd_region);
109-
nd_pfn = &nd_dax->nd_pfn;
110-
dax_dev = nd_pfn_devinit(nd_pfn, ndns);
109+
dax_dev = nd_dax_devinit(nd_dax, ndns);
111110
nvdimm_bus_unlock(&ndns->dev);
112111
if (!dax_dev)
113112
return -ENOMEM;
114113
pfn_sb = devm_kmalloc(dev, sizeof(*pfn_sb), GFP_KERNEL);
114+
nd_pfn = &nd_dax->nd_pfn;
115115
nd_pfn->pfn_sb = pfn_sb;
116116
rc = nd_pfn_validate(nd_pfn, DAX_SIG);
117117
dev_dbg(dev, "dax: %s\n", rc == 0 ? dev_name(dax_dev) : "<none>");

drivers/nvdimm/nd.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,13 @@ struct nd_dax *to_nd_dax(struct device *dev);
600600
int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns);
601601
bool is_nd_dax(const struct device *dev);
602602
struct device *nd_dax_create(struct nd_region *nd_region);
603+
static inline struct device *nd_dax_devinit(struct nd_dax *nd_dax,
604+
struct nd_namespace_common *ndns)
605+
{
606+
if (!nd_dax)
607+
return NULL;
608+
return nd_pfn_devinit(&nd_dax->nd_pfn, ndns);
609+
}
603610
#else
604611
static inline int nd_dax_probe(struct device *dev,
605612
struct nd_namespace_common *ndns)

0 commit comments

Comments
 (0)