Skip to contentSkip to conversation

PCI: endpoint: Set .owner = THIS_MODULE in struct pci_epc_ops

PATCH New Ian Rogers 2 participants 5 messages Dec 3

Subsystems (8)
lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

cover PCI: endpoint: Set .owner = THIS_MODULE in struct pci_epc_ops

pci_epc_get() / pci_epc_put() reference count epc->ops->owner, while none of the four struct pci_epc_ops definitions under drivers/pci/controller/ initialize .owner:

1. pcie-cadence-ep (tristate CONFIG_PCIE_CADENCE_EP) - fixes missing module pinning when built as a module (has Fixes tag).
2. pcie-designware-ep, pcie-rcar-ep, and pcie-rockchip-ep (currently bool) - initialized for consistency and to prepare for annotating pci_epc_ops::owner with __must_init.

Tooling note: Found using Clang's require_explicit_initialization attribute; an AI coding assistant helped audit call sites, verify Kconfig module eligibility and Fixes commits, and draft the changelogs. All four files were build-tested with LLVM=1.

Ian Rogers (2):
PCI: cadence: Set .owner = THIS_MODULE in cdns_pcie_epc_ops
PCI: endpoint: Set .owner = THIS_MODULE in remaining pci_epc_ops

 drivers/pci/controller/cadence/pcie-cadence-ep.c | 1 +
 drivers/pci/controller/dwc/pcie-designware-ep.c  | 2 ++
 drivers/pci/controller/pcie-rcar-ep.c            | 2 ++
 drivers/pci/controller/pcie-rockchip-ep.c        | 2 ++
 4 files changed, 7 insertions(+)

base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244

Signature · 1 line
2.56.1.839.g22a8290db9-goog
author
#1 lore raw

PATCH 1/2 PCI: cadence: Set .owner = THIS_MODULE in cdns_pcie_epc_ops

pci_epc_get() calls try_module_get(epc->ops->owner) and pci_epc_put() calls module_put(epc->ops->owner), while __pci_epc_create() ignores its owner parameter because epc->ops is const struct pci_epc_ops *. Because pcie-cadence-ep can be built as a module (CONFIG_PCIE_CADENCE_EP), omitting .owner leaves the module unpinned while an endpoint controller reference is held.

Set .owner = THIS_MODULE in cdns_pcie_epc_ops, found with Clang's require_explicit_initialization attribute.

Fixes 37dddf14f1ae ("PCI: cadence: Add EndPoint Controller driver for Cadence PCIe controller")
---
 drivers/pci/controller/cadence/pcie-cadence-ep.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/controller/cadence/pcie-cadence-ep.c +1 -0
index a967f7762283..eda5e2da90db 100644
@@ -648,6 +648,7 @@ static const struct pci_epc_ops cdns_pcie_epc_ops = {
 	.map_msi_irq	= cdns_pcie_ep_map_msi_irq,
 	.start		= cdns_pcie_ep_start,
 	.get_features	= cdns_pcie_ep_get_features,
+	.owner		= THIS_MODULE,
 };
 
 void cdns_pcie_ep_disable(struct cdns_pcie_ep *ep)
Signature · 1 line
2.56.1.839.g22a8290db9-goog
#2 lore raw

Re: [PATCH 1/2] PCI: cadence: Set .owner = THIS_MODULE in cdns_pcie_epc_ops

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] PCI: cadence: Fixes tag cites 37dddf14f1ae instead of f876904e4436 --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] PCI: cadence: Fixes tag cites 37dddf14f1ae instead of f876904e4436
--

commit 7d16f45d8dc004d424a29a6333f5e5299a95a021
Author: Ian Rogers <[email protected]>

Quoted 9 lines

PCI: cadence: Set .owner = THIS_MODULE in cdns_pcie_epc_ops

pci_epc_get() calls try_module_get(epc->ops->owner) and pci_epc_put() calls module_put(epc->ops->owner), while __pci_epc_create() ignores its owner parameter because epc->ops is const struct pci_epc_ops *. Because pcie-cadence-ep can be built as a module (CONFIG_PCIE_CADENCE_EP), omitting .owner leaves the module unpinned while an endpoint controller reference is held.

Quoted 5 lines

Set .owner = THIS_MODULE in cdns_pcie_epc_ops, found with Clang's require_explicit_initialization attribute.

Fixes 37dddf14f1ae ("PCI: cadence: Add EndPoint Controller driver for Cadence PCIe controller")

[Severity: Low]
Should the Fixes tag point to f876904e4436 ("PCI: cadence: Add support to build pcie-cadence library as a kernel module") instead?

In the cited commit, CONFIG_PCIE_CADENCE_EP was bool and built-in only, so THIS_MODULE expanded to NULL. The unpinned-module bug began when the driver was converted to tristate, and citing the older commit can trigger unnecessary backports to stable trees where it cannot be built as a module.

Fixes f876904e4436 ("PCI: cadence: Add support to build pcie-cadence library as a kernel module")
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author
#3 lore raw

PATCH 2/2 PCI: endpoint: Set .owner = THIS_MODULE in remaining pci_epc_ops

In reply to Ian Rogers

pcie-designware-ep, pcie-rcar-ep, and pcie-rockchip-ep are currently bool Kconfig options (where THIS_MODULE is NULL), so omitting .owner in their struct pci_epc_ops definitions does not affect runtime module reference counting today.

Initialize .owner = THIS_MODULE in all three for consistency across all struct pci_epc_ops definitions and to prepare for annotating pci_epc_ops::owner with Clang's require_explicit_initialization attribute.

---
 drivers/pci/controller/dwc/pcie-designware-ep.c | 2 ++
 drivers/pci/controller/pcie-rcar-ep.c           | 2 ++
 drivers/pci/controller/pcie-rockchip-ep.c       | 2 ++
 3 files changed, 6 insertions(+)
drivers/pci/controller/dwc/pcie-designware-ep.c +2 -0
index e6060bb0bbbd..d5223597b5c9 100644
@@ -8,6 +8,7 @@
 
 #include <linux/align.h>
 #include <linux/bitfield.h>
+#include <linux/module.h>
 #include <linux/of.h>
 #include <linux/overflow.h>
 #include <linux/platform_device.h>
@@ -949,6 +950,7 @@ static const struct pci_epc_ops epc_ops = {
 	.get_features		= dw_pcie_ep_get_features,
 	.get_aux_resources_count	= dw_pcie_ep_get_aux_resources_count,
 	.get_aux_resources	= dw_pcie_ep_get_aux_resources,
+	.owner			= THIS_MODULE,
 };
 
 /**
drivers/pci/controller/pcie-rcar-ep.c +2 -0
index e33c66caa1a6..b9df4699178c 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/delay.h>
+#include <linux/module.h>
 #include <linux/of_address.h>
 #include <linux/of_platform.h>
 #include <linux/pci.h>
@@ -463,6 +464,7 @@ static const struct pci_epc_ops rcar_pcie_epc_ops = {
 	.start		= rcar_pcie_ep_start,
 	.stop		= rcar_pcie_ep_stop,
 	.get_features	= rcar_pcie_ep_get_features,
+	.owner		= THIS_MODULE,
 };
 
 static const struct of_device_id rcar_pcie_ep_of_match[] = {
drivers/pci/controller/pcie-rockchip-ep.c +2 -0
index a20536d50c9c..4a6c9dfeab83 100644
@@ -14,6 +14,7 @@
 #include <linux/iopoll.h>
 #include <linux/kernel.h>
 #include <linux/irq.h>
+#include <linux/module.h>
 #include <linux/of.h>
 #include <linux/pci-epc.h>
 #include <linux/platform_device.h>
@@ -704,6 +705,7 @@ static const struct pci_epc_ops rockchip_pcie_epc_ops = {
 	.start		= rockchip_pcie_ep_start,
 	.stop		= rockchip_pcie_ep_stop,
 	.get_features	= rockchip_pcie_ep_get_features,
+	.owner		= THIS_MODULE,
 };
 
 static int rockchip_pcie_ep_get_resources(struct rockchip_pcie *rockchip,
Signature · 1 line
2.56.1.839.g22a8290db9-goog
#4 lore raw
In reply to Ian Rogers
Sashiko has finished reviewing this 2-patch series:

Sashiko has finished reviewing this 2-patch series:

- Patch 2: no issues found.
- Patch 1 ("PCI: cadence: Set .owner = THIS_MODULE in cdns_pcie_..."): 1 potential issue (1 Low)

A detailed review has been sent as a separate reply to patch 1.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]