Re: [PATCH v3] PCI: Correct PCIe port type field encoding

From: Mika Westerberg

Date: Tue Nov 24 2026 - 08:26:48 EST


On Tue, Nov 24, 2026 at 08:50:38AM +0000, Gokulkrishna Sekar wrote:
> set_pcie_port_type() validates PCIe port topology and corrects
> invalid upstream/downstream port type information in the cached
> pcie_flags_reg value.
>
> When performing these corrections, the code updates
> PCI_EXP_FLAGS_TYPE using PCI_EXP_TYPE_UPSTREAM or
> PCI_EXP_TYPE_DOWNSTREAM directly. The PCI_EXP_TYPE_* values are
> decoded port type numbers, not values encoded for the
> PCI_EXP_FLAGS_TYPE bitfield, so the corrected type is stored in the
> wrong bit position.
>
> As a result, a device whose type has been corrected may subsequently
> be reported as PCI_EXP_TYPE_ENDPOINT instead of the intended
> upstream or downstream port type.
>
> Use FIELD_MODIFY() to update PCI_EXP_FLAGS_TYPE so the corrected
> port type is encoded consistently with the format used in the PCI
> Express Capabilities Register.
>
> Fixes: ca78410403dd ("PCI: Get rid of dev->has_secondary_link flag")
> Reported-by: Gowthami Thiagarajan <gthiagarajan@xxxxxxxxxxx>
> Link: https://lore.kernel.org/all/20241213070241.3334854-1-gthiagarajan@xxxxxxxxxxx/
> Signed-off-by: Gokulkrishna Sekar <Gokulkrishna.Sekar@xxxxxxxxxx>

Reviewed-by: Mika Westerberg (Intel) <westeri@xxxxxxxxxx>