]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
libnvdimm/label: Add a helper for nlabel validation
authorDan Williams <dan.j.williams@intel.com>
Tue, 24 Aug 2021 16:06:24 +0000 (09:06 -0700)
committerDan Williams <dan.j.williams@intel.com>
Tue, 24 Aug 2021 19:08:29 +0000 (12:08 -0700)
In the CXL namespace label there is no need for nlabel since that is
inferred from the region. Add a helper that moves nsl_get_label() behind
a helper that validates the number of labels relative to the region.

Link: https://lore.kernel.org/r/162982118423.1124374.11980785134458815600.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/nvdimm/namespace_devs.c
drivers/nvdimm/nd.h

index d4959981c7d4fcdfa967aee20597b7d51942b5b2..28ed14052e362bd59608e0a5c281e2c29b9911b1 100644 (file)
@@ -1848,12 +1848,11 @@ static bool has_uuid_at_pos(struct nd_region *nd_region, const uuid_t *uuid,
 
                list_for_each_entry(label_ent, &nd_mapping->labels, list) {
                        struct nd_namespace_label *nd_label = label_ent->label;
-                       u16 position, nlabel;
+                       u16 position;
 
                        if (!nd_label)
                                continue;
                        position = nsl_get_position(ndd, nd_label);
-                       nlabel = nsl_get_nlabel(ndd, nd_label);
 
                        if (!nsl_validate_isetcookie(ndd, nd_label, cookie))
                                continue;
@@ -1870,7 +1869,7 @@ static bool has_uuid_at_pos(struct nd_region *nd_region, const uuid_t *uuid,
                                return false;
                        }
                        found_uuid = true;
-                       if (nlabel != nd_region->ndr_mappings)
+                       if (!nsl_validate_nlabel(nd_region, ndd, nd_label))
                                continue;
                        if (position != pos)
                                continue;
index ec3c9aad7f50a611d0b8ed384d3a8eb9d46f4de6..036638bdb7e3fd972a95d2a8aa5edb3cd5bc6cd3 100644 (file)
@@ -342,6 +342,13 @@ struct nd_region {
        struct nd_mapping mapping[];
 };
 
+static inline bool nsl_validate_nlabel(struct nd_region *nd_region,
+                                      struct nvdimm_drvdata *ndd,
+                                      struct nd_namespace_label *nd_label)
+{
+       return nsl_get_nlabel(ndd, nd_label) == nd_region->ndr_mappings;
+}
+
 struct nd_blk_region {
        int (*enable)(struct nvdimm_bus *nvdimm_bus, struct device *dev);
        int (*do_io)(struct nd_blk_region *ndbr, resource_size_t dpa,