Skip to contentSkip to conversation

PCI: kirin: Make structure kirin_dw_pcie_ops constant

PATCH Applied Nishka Dasgupta 3 participants 3 messages Aug 19, 2019 – Aug 21, 2019

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

PATCH 1/1 PCI: kirin: Make structure kirin_dw_pcie_ops constant

Static variable kirin_dw_pcie_ops, of type dw_pcie_ops, is used only once, when it is assigned to the constant field ops of variable pci (having type dw_pcie). Hence kirin_dw_pcie_ops is never modified. Therefore, make it constant to protect it from unintended modification. Issue found with Coccinelle.

---
 drivers/pci/controller/dwc/pcie-kirin.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-kirin.c +1 -1
index 8df1914226be..c19617a912bd 100644
@@ -436,7 +436,7 @@ static int kirin_pcie_host_init(struct pcie_port *pp)
 	return 0;
 }
 
-static struct dw_pcie_ops kirin_dw_pcie_ops = {
+static const struct dw_pcie_ops kirin_dw_pcie_ops = {
 	.read_dbi = kirin_pcie_read_dbi,
 	.write_dbi = kirin_pcie_write_dbi,
 	.link_up = kirin_pcie_link_up,
Signature · 1 line
2.19.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Nishka Dasgupta

Static variable kirin_dw_pcie_ops, of type dw_pcie_ops, is used only once, when it is assigned to the constant field ops of variable pci (having type dw_pcie). Hence kirin_dw_pcie_ops is never modified. Therefore, make it constant to protect it from unintended modification. Issue found with Coccinelle.

---
 drivers/pci/controller/dwc/pcie-kirin.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-kirin.c +0 -0
index 8df1914226be..c19617a912bd 100644

drivers/pci/controller/dwc/pcie-kirin.c static int kirin_pcie_host_init(struct pcie_port *pp) · line 442

Quoted 8 lines
drivers/pci/controller/dwc/pcie-kirin.c +1 -1
@@ -436,7 +436,7 @@ static int kirin_pcie_host_init(struct pcie_port *pp)
 	return 0;
 }
 
-static struct dw_pcie_ops kirin_dw_pcie_ops = {
+static const struct dw_pcie_ops kirin_dw_pcie_ops = {
 	.read_dbi = kirin_pcie_read_dbi,
 	.write_dbi = kirin_pcie_write_dbi,
 	.link_up = kirin_pcie_link_up,

This makes sense, and const is applied to the same structure in many of the other controller drivers.

Quoted 3 lines
Signature · 1 line
2.19.1
#2 lore raw
In reply to Nishka Dasgupta
Quoted 10 lines · Nishka Dasgupta

Static variable kirin_dw_pcie_ops, of type dw_pcie_ops, is used only once, when it is assigned to the constant field ops of variable pci (having type dw_pcie). Hence kirin_dw_pcie_ops is never modified. Therefore, make it constant to protect it from unintended modification. Issue found with Coccinelle.

---
 drivers/pci/controller/dwc/pcie-kirin.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to pci/dwc for v5.4, thanks.

Lorenzo

Quoted 16 lines
drivers/pci/controller/dwc/pcie-kirin.c +1 -1
index 8df1914226be..c19617a912bd 100644
@@ -436,7 +436,7 @@ static int kirin_pcie_host_init(struct pcie_port *pp)
 	return 0;
 }
 
-static struct dw_pcie_ops kirin_dw_pcie_ops = {
+static const struct dw_pcie_ops kirin_dw_pcie_ops = {
 	.read_dbi = kirin_pcie_read_dbi,
 	.write_dbi = kirin_pcie_write_dbi,
 	.link_up = kirin_pcie_link_up,
Signature · 1 line
2.19.1