Skip to contentSkip to conversation

PCI: dwc: Move "dbi", "dbi2", and "addr_space" resource setup into common code

bug report Dan Carpenter 2 participants 2 messages Dec 1, 2020 PCI

lore
Share & tools
lore
#0 lore raw

Hello Rob Herring,

The patch a0fd361db8e5: "PCI: dwc: Move "dbi", "dbi2", and "addr_space" resource setup into common code" from Nov 5, 2020, leads to the following static checker warning:

	drivers/pci/controller/dwc/pcie-designware-host.c:337 dw_pcie_host_init()
	warn: 'pci->dbi_base' is an error pointer or valid

drivers/pci/controller/dwc/pcie-designware-host.c
304 cfg_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "config");
305 if (cfg_res) {
306 pp->cfg0_size = resource_size(cfg_res);
307 pp->cfg0_base = cfg_res->start;
308 } else if (!pp->va_cfg0_base) {
309 dev_err(dev, "Missing *config* reg space\n");
310 }
311
312 if (!pci->dbi_base) {
313 struct resource *dbi_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi");

   314                  pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_res);
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

We set pci->dbi_base here now.

315 if (IS_ERR(pci->dbi_base))
316 return PTR_ERR(pci->dbi_base);
317 }
318
319 bridge = devm_pci_alloc_host_bridge(dev, 0);
320 if (!bridge)
321 return -ENOMEM;
322
323 pp->bridge = bridge;
324
325 /* Get the I/O and memory ranges from DT */
326 resource_list_for_each_entry(win, &bridge->windows) {
327 switch (resource_type(win->res)) {
328 case IORESOURCE_IO:

   329                          pp->io_size = resource_size(win->res);
   330                          pp->io_bus_addr = win->res->start - win->offset;
   331                          pp->io_base = pci_pio_to_address(win->res->start);
   332                          break;
   333                  case 0:
   334                          dev_err(dev, "Missing *config* reg space\n");
   335                          pp->cfg0_size = resource_size(win->res);
   336                          pp->cfg0_base = win->res->start;
   337                          if (!pci->dbi_base) {
                                    ^^^^^^^^^^^^^^

So this is dead code because pci->dbi_base is never NULL.

   338                                  pci->dbi_base = devm_pci_remap_cfgspace(dev,
   339                                                                  pp->cfg0_base,
   340                                                                  pp->cfg0_size);
   341                                  if (!pci->dbi_base) {
   342                                          dev_err(dev, "Error with ioremap\n");
   343                                          return -ENOMEM;
   344                                  }
   345                          }
   346                          break;
   347                  }
   348          }

regards,
dan carpenter

#1 lore raw
Quoted 49 lines · Dan Carpenter

Hello Rob Herring,

The patch a0fd361db8e5: "PCI: dwc: Move "dbi", "dbi2", and "addr_space" resource setup into common code" from Nov 5, 2020, leads to the following static checker warning:

        drivers/pci/controller/dwc/pcie-designware-host.c:337 dw_pcie_host_init()
        warn: 'pci->dbi_base' is an error pointer or valid

drivers/pci/controller/dwc/pcie-designware-host.c

   304          cfg_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "config");
   305          if (cfg_res) {
   306                  pp->cfg0_size = resource_size(cfg_res);
   307                  pp->cfg0_base = cfg_res->start;
   308          } else if (!pp->va_cfg0_base) {
   309                  dev_err(dev, "Missing *config* reg space\n");
   310          }
   311
   312          if (!pci->dbi_base) {
   313                  struct resource *dbi_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi");
   314                  pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_res);
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

We set pci->dbi_base here now.

   315                  if (IS_ERR(pci->dbi_base))
   316                          return PTR_ERR(pci->dbi_base);
   317          }
   318
   319          bridge = devm_pci_alloc_host_bridge(dev, 0);
   320          if (!bridge)
   321                  return -ENOMEM;
   322
   323          pp->bridge = bridge;
   324
   325          /* Get the I/O and memory ranges from DT */
   326          resource_list_for_each_entry(win, &bridge->windows) {
   327                  switch (resource_type(win->res)) {
   328                  case IORESOURCE_IO:
   329                          pp->io_size = resource_size(win->res);
   330                          pp->io_bus_addr = win->res->start - win->offset;
   331                          pp->io_base = pci_pio_to_address(win->res->start);
   332                          break;
   333                  case 0:
   334                          dev_err(dev, "Missing *config* reg space\n");
   335                          pp->cfg0_size = resource_size(win->res);
   336                          pp->cfg0_base = win->res->start;
   337                          if (!pci->dbi_base) {
                                    ^^^^^^^^^^^^^^
Quoted 1 line

So this is dead code because pci->dbi_base is never NULL.

I think this code should not be needed any more. It was for compatibility with old DTs. I'll check the history.

Rob

Quoted 15 lines
   338                                  pci->dbi_base = devm_pci_remap_cfgspace(dev,
   339                                                                  pp->cfg0_base,
   340                                                                  pp->cfg0_size);
   341                                  if (!pci->dbi_base) {
   342                                          dev_err(dev, "Error with ioremap\n");
   343                                          return -ENOMEM;
   344                                  }
   345                          }
   346                          break;
   347                  }
   348          }

regards,
dan carpenter