Re: [PATCH] PCI/ASPM: Add missing NULL check for link in sysfs show/store callbacks
From: Lukas Wunner
Date: Mon Jul 27 2026 - 06:21:48 EST
On Mon, Jul 27, 2026 at 03:29:15PM +0800, ZhaoJinming wrote:
> The aspm_attr_show_common(), aspm_attr_store_common(), clkpm_show()
> and clkpm_store() sysfs callbacks call pcie_aspm_get_link() without
> checking the return value. A NULL return would indicate the device is
> not PCIe, has no upstream bridge, or the link state has not been
> initialized.
>
> While the aspm_ctrl_attrs_are_visible() is_visible callback already
> hides these attributes when link is NULL, add the NULL check for
> defense in depth and consistency with other callers of
> pcie_aspm_get_link() in the same file (__pci_disable_link_state,
> __pci_enable_link_state, pcie_aspm_enabled).
Well, if we don't need the checks because the ->is_visible() callback
already hides the attributes, then we shouldn't add them.
Otherwise it's quite possible that someone else comes along and deletes
the checks again because they're superfluous.
Thanks,
Lukas