Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [Medium] The internal `get_rp_completer_type()` function was not updated to 
use the new `pcie_tph_completer_type()` helper, leading to an API contract 
violation in `pcie_tph_enabled_req_type()`.
--

commit d64d0831457ed161ad198682067e0f147ca1411e
Author: Zhiping Zhang <[email protected]>

PCI/TPH: Add requester/completer type helpers

This patch introduces pcie_tph_enabled_req_type() and
pcie_tph_completer_type() to allow drivers to query TPH requester mode
and completer capabilities without accessing pci_dev internals directly.
It also ensures the reserved 0b10 completer capability encoding is
folded into a "not supported" value for callers.

> diff --git a/drivers/pci/tph.c b/drivers/pci/tph.c
> index 655ffd60e62f6..e7693fd9d6763 100644
> --- a/drivers/pci/tph.c
> +++ b/drivers/pci/tph.c
> @@ -173,6 +173,51 @@ u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev)
>  }
>  EXPORT_SYMBOL(pcie_tph_get_st_table_loc);
>  
> +/**
> + * pcie_tph_enabled_req_type - Return the device's enabled TPH requester type
> + * @pdev: PCI device to query
> + *
> + * Return: PCI_TPH_REQ_DISABLE, PCI_TPH_REQ_TPH_ONLY or PCI_TPH_REQ_EXT_TPH.
> + */
> +u8 pcie_tph_enabled_req_type(struct pci_dev *pdev)
> +{
> +     return pdev->tph_req_type;
> +}

[Severity: Medium]
Could this helper return an undocumented value of 2 if a Root Port's TPH
Completer Supported field incorrectly exposes the reserved 0b10 value?

The internal get_rp_completer_type() function was not updated to use the new
pcie_tph_completer_type() helper, so it retains its manual decoding:

drivers/pci/tph.c:get_rp_completer_type() {
    ...
    return FIELD_GET(PCI_EXP_DEVCAP2_TPH_COMP_MASK, reg);
}

If get_rp_completer_type() returns 2, pcie_enable_tph() can assign this to
pdev->tph_req_type via the min() calculation:

drivers/pci/tph.c:pcie_enable_tph() {
    ...
    rp_req_type = get_rp_completer_type(pdev);
    
    /* Final req_type is the smallest value of two */
    pdev->tph_req_type = min(pdev->tph_req_type, rp_req_type);
}

Should get_rp_completer_type() be refactored to use pcie_tph_completer_type()
to properly fold the reserved 0b10 encoding and avoid this API contract
violation?

[ ... ]

-- 
Sashiko AI review · 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to