Skip to contentSkip to conversation

x86/pci: Annotate 'pci_root_ops' with __ro_after_init

PATCH In review Zubin Mithra 3 participants 3 messages Nov 5, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/pci: Annotate 'pci_root_ops' with __ro_after_init

When CONFIG_X86_INTEL_MID is set pci_root_ops is written to inside intel_mid_pci_init(which is marked __init) and not modified after. This makes pci_root_ops a suitable candidate for annotating as __ro_after_init.

---
 arch/x86/pci/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/pci/common.c +1 -1
index d4ec117c1142..204ee80cfa63 100644
@@ -67,7 +67,7 @@ static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int siz
 				  devfn, where, size, value);
 }
 
-struct pci_ops pci_root_ops = {
+struct pci_ops pci_root_ops __ro_after_init = {
 	.read = pci_read,
 	.write = pci_write,
 };
Signature · 1 line
2.19.1.930.g4563a0d9d0-goog
Reviewed-by on v1 1/1
#1 lore raw

On Mon, 5 Nov 2018, Zubin Mithra wrote:

Cc+: Bjorn

Quoted 4 lines

When CONFIG_X86_INTEL_MID is set pci_root_ops is written to inside intel_mid_pci_init(which is marked __init) and not modified after. This makes pci_root_ops a suitable candidate for annotating as __ro_after_init.

This is confusing. What about CONFIG_X86_INTEL_MID=n?

What you want to say is:

pci_root_ops is only modified from intel_mid_pci_init() which is a init function, so it can be made __ro_after_init.

or something like this. Hmm?

Other than the nitpick above:

Quoted 22 lines
---
 arch/x86/pci/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/pci/common.c +1 -1
index d4ec117c1142..204ee80cfa63 100644
@@ -67,7 +67,7 @@ static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int siz
 				  devfn, where, size, value);
 }
 
-struct pci_ops pci_root_ops = {
+struct pci_ops pci_root_ops __ro_after_init = {
 	.read = pci_read,
 	.write = pci_write,
 };
Signature · 1 line
2.19.1.930.g4563a0d9d0-goog
#2 lore raw
In reply to Zubin Mithra
Quoted 4 lines · Zubin Mithra

When CONFIG_X86_INTEL_MID is set pci_root_ops is written to inside intel_mid_pci_init(which is marked __init) and not modified after. This makes pci_root_ops a suitable candidate for annotating as __ro_after_init.

Yikes. pci_root_ops really should be const to start with, and we should use a separate struct for MID. Having structures that contain function pointers not marked const is generally a bad idea to start with.