cxl/pci: Ignore unknown register block types
authorBen Widawsky <ben.widawsky@intel.com>
Fri, 16 Jul 2021 23:15:46 +0000 (16:15 -0700)
committerDan Williams <dan.j.williams@intel.com>
Fri, 6 Aug 2021 15:27:02 +0000 (08:27 -0700)
In an effort to explicit avoid supporting vendor specific register
blocks (which can happily be mapped from userspace), entirely skip
probing unknown types. The secondary benefit of this will be revealed
in the future with code simplification.

Signed-off-by: Ben Widawsky <ben.widawsky@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/20210716231548.174778-2-ben.widawsky@intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/cxl/pci.c

index 193983e6edce75a8f32c499a6579ef967d6e2797..90a1c895e4426b518777e7d4c0138108b21ec187 100644 (file)
@@ -1118,14 +1118,6 @@ static int cxl_mem_setup_regs(struct cxl_mem *cxlm)
                u64 offset;
                u8 bar;
 
-               map = kzalloc(sizeof(*map), GFP_KERNEL);
-               if (!map) {
-                       ret = -ENOMEM;
-                       goto free_maps;
-               }
-
-               list_add(&map->list, &register_maps);
-
                pci_read_config_dword(pdev, regloc, &reg_lo);
                pci_read_config_dword(pdev, regloc + 4, &reg_hi);
 
@@ -1135,6 +1127,18 @@ static int cxl_mem_setup_regs(struct cxl_mem *cxlm)
                dev_dbg(dev, "Found register block in bar %u @ 0x%llx of type %u\n",
                        bar, offset, reg_type);
 
+               /* Ignore unknown register block types */
+               if (reg_type > CXL_REGLOC_RBI_MEMDEV)
+                       continue;
+
+               map = kzalloc(sizeof(*map), GFP_KERNEL);
+               if (!map) {
+                       ret = -ENOMEM;
+                       goto free_maps;
+               }
+
+               list_add(&map->list, &register_maps);
+
                base = cxl_mem_map_regblock(cxlm, bar, offset);
                if (!base) {
                        ret = -ENOMEM;