Re: [PATCH v5 13/16] cxl/pci: Add error handler for CXL PCIe Port RAS errors

Bowman, Terry
2025-02-07T19:23:12Z

On 2/7/2025 2:01 AM, Gregory Price wrote:
> On Tue, Jan 07, 2025 at 08:38:49AM -0600, Terry Bowman wrote:
>> +static void __iomem *cxl_pci_port_ras(struct pci_dev *pdev)
>> +{
>> + struct cxl_port *port;
>> +
>> + if (!pdev)
>> + return NULL;
>> +
>> + if ((pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT) ||
>> + (pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM)) {
>> + struct cxl_dport *dport;
>> + void __iomem *ras_base;
>> +
>> + port = find_cxl_port(&pdev->dev, &dport);
>> + ras_base = dport ? dport->regs.ras : NULL;
> I'm fairly certain dport can come back here uninitialized, you
> probably want to put this inside the `if (port)` block and
> pre-initialize dport to NULL.
Right, it can. NULL dport check here covers this, no?:

ras_base = dport ? dport->regs.ras : NULL;

Terry

>> + if (port)
>> + put_device(&port->dev);
>> + return ras_base;
> You can probably even simplify this down to something like
>
> struct_cxl_dport *dport = NULL;
>
> port = find_cxl_port(&pdev->dev, &dport);
> if (port)
> put_device(&port->dev);
>
> return dport ? dport->regs.ras : NULL;
>
>
> ~Gregory