]> Git Repo - J-linux.git/commitdiff
nvdimm: rectify the illogical code within nd_dax_probe()
authorYi Yang <[email protected]>
Fri, 8 Nov 2024 08:55:26 +0000 (08:55 +0000)
committerIra Weiny <[email protected]>
Wed, 13 Nov 2024 18:58:37 +0000 (12:58 -0600)
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]>
drivers/nvdimm/dax_devs.c
drivers/nvdimm/nd.h

index 6b4922de30477e5f5aca72971dad8e8050c06b50..37b743acbb7bad583baa94f72bd9184811129eae 100644 (file)
@@ -106,12 +106,12 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns)
 
        nvdimm_bus_lock(&ndns->dev);
        nd_dax = nd_dax_alloc(nd_region);
-       nd_pfn = &nd_dax->nd_pfn;
-       dax_dev = nd_pfn_devinit(nd_pfn, ndns);
+       dax_dev = nd_dax_devinit(nd_dax, ndns);
        nvdimm_bus_unlock(&ndns->dev);
        if (!dax_dev)
                return -ENOMEM;
        pfn_sb = devm_kmalloc(dev, sizeof(*pfn_sb), GFP_KERNEL);
+       nd_pfn = &nd_dax->nd_pfn;
        nd_pfn->pfn_sb = pfn_sb;
        rc = nd_pfn_validate(nd_pfn, DAX_SIG);
        dev_dbg(dev, "dax: %s\n", rc == 0 ? dev_name(dax_dev) : "<none>");
index 2dbb1dca17b534a09ddf6ccb4bfeb4c77bf4dee2..5ca06e9a2d2925859db8d99597550ebc4f75e061 100644 (file)
@@ -600,6 +600,13 @@ struct nd_dax *to_nd_dax(struct device *dev);
 int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns);
 bool is_nd_dax(const struct device *dev);
 struct device *nd_dax_create(struct nd_region *nd_region);
+static inline struct device *nd_dax_devinit(struct nd_dax *nd_dax,
+                                           struct nd_namespace_common *ndns)
+{
+       if (!nd_dax)
+               return NULL;
+       return nd_pfn_devinit(&nd_dax->nd_pfn, ndns);
+}
 #else
 static inline int nd_dax_probe(struct device *dev,
                struct nd_namespace_common *ndns)
This page took 0.057758 seconds and 4 git commands to generate.