Skip to content

Commit 77ae53c

Browse files
Yi Yanggregkh
authored andcommitted
nvdimm: rectify the illogical code within nd_dax_probe()
[ Upstream commit b613521 ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 61b32d4 commit 77ae53c

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
@@ -113,12 +113,12 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns)
113113

114114
nvdimm_bus_lock(&ndns->dev);
115115
nd_dax = nd_dax_alloc(nd_region);
116-
nd_pfn = &nd_dax->nd_pfn;
117-
dax_dev = nd_pfn_devinit(nd_pfn, ndns);
116+
dax_dev = nd_dax_devinit(nd_dax, ndns);
118117
nvdimm_bus_unlock(&ndns->dev);
119118
if (!dax_dev)
120119
return -ENOMEM;
121120
pfn_sb = devm_kmalloc(dev, sizeof(*pfn_sb), GFP_KERNEL);
121+
nd_pfn = &nd_dax->nd_pfn;
122122
nd_pfn->pfn_sb = pfn_sb;
123123
rc = nd_pfn_validate(nd_pfn, DAX_SIG);
124124
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
@@ -326,6 +326,13 @@ struct nd_dax *to_nd_dax(struct device *dev);
326326
int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns);
327327
bool is_nd_dax(struct device *dev);
328328
struct device *nd_dax_create(struct nd_region *nd_region);
329+
static inline struct device *nd_dax_devinit(struct nd_dax *nd_dax,
330+
struct nd_namespace_common *ndns)
331+
{
332+
if (!nd_dax)
333+
return NULL;
334+
return nd_pfn_devinit(&nd_dax->nd_pfn, ndns);
335+
}
329336
#else
330337
static inline int nd_dax_probe(struct device *dev,
331338
struct nd_namespace_common *ndns)

0 commit comments

Comments
 (0)