Skip to contentSkip to conversation

PCI: endpoint: Return error code when callback is not implemented

PATCH In review Rick Wertenbroek 2 participants 2 messages Aug 17, 2023 – Aug 18, 2023

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

PATCH 1/1 PCI: endpoint: Return error code when callback is not implemented

Return an error code when the callback for an endpoint controller function is not implemented (is null). Among all the functions, only map_msi_irq() had an error returned if the callback was null. Extend this error handling to other functions as well.

---
 drivers/pci/endpoint/pci-epc-core.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/pci/endpoint/pci-epc-core.c +7 -7
index 5a4a8b0be626..14f4256b9410 100644
@@ -196,7 +196,7 @@ int pci_epc_start(struct pci_epc *epc)
 		return -EINVAL;
 
 	if (!epc->ops->start)
-		return 0;
+		return -EINVAL;
 
 	mutex_lock(&epc->lock);
 	ret = epc->ops->start(epc);
@@ -228,7 +228,7 @@ int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 		return -EINVAL;
 
 	if (!epc->ops->raise_irq)
-		return 0;
+		return -EINVAL;
 
 	mutex_lock(&epc->lock);
 	ret = epc->ops->raise_irq(epc, func_no, vfunc_no, type, interrupt_num);
@@ -340,7 +340,7 @@ int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u8 interrupts)
 		return -EINVAL;
 
 	if (!epc->ops->set_msi)
-		return 0;
+		return -EINVAL;
 
 	encode_int = order_base_2(interrupts);
 
@@ -408,7 +408,7 @@ int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 		return -EINVAL;
 
 	if (!epc->ops->set_msix)
-		return 0;
+		return -EINVAL;
 
 	mutex_lock(&epc->lock);
 	ret = epc->ops->set_msix(epc, func_no, vfunc_no, interrupts - 1, bir,
@@ -469,7 +469,7 @@ int pci_epc_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 		return -EINVAL;
 
 	if (!epc->ops->map_addr)
-		return 0;
+		return -EINVAL;
 
 	mutex_lock(&epc->lock);
 	ret = epc->ops->map_addr(epc, func_no, vfunc_no, phys_addr, pci_addr,
@@ -537,7 +537,7 @@ int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 		return -EINVAL;
 
 	if (!epc->ops->set_bar)
-		return 0;
+		return -EINVAL;
 
 	mutex_lock(&epc->lock);
 	ret = epc->ops->set_bar(epc, func_no, vfunc_no, epf_bar);
@@ -575,7 +575,7 @@ int pci_epc_write_header(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 		return -EINVAL;
 
 	if (!epc->ops->write_header)
-		return 0;
+		return -EINVAL;
 
 	mutex_lock(&epc->lock);
 	ret = epc->ops->write_header(epc, func_no, vfunc_no, header);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 6 lines · Rick Wertenbroek

Return an error code when the callback for an endpoint controller function is not implemented (is null). Among all the functions, only map_msi_irq() had an error returned if the callback was null. Extend this error handling to other functions as well.

We should check for the mandatory ops definition in pci_epf_register_driver() for function drivers and in __pci_epc_create() for controller drivers.

Quoted 18 lines
---
 drivers/pci/endpoint/pci-epc-core.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/pci/endpoint/pci-epc-core.c +1 -1
index 5a4a8b0be626..14f4256b9410 100644
@@ -196,7 +196,7 @@ int pci_epc_start(struct pci_epc *epc)
 		return -EINVAL;
 
 	if (!epc->ops->start)
-		return 0;
+		return -EINVAL;
 
 	mutex_lock(&epc->lock);
 	ret = epc->ops->start(epc);

drivers/pci/endpoint/pci-epc-core.c int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no, u8 vfunc_no, · line 231

Quoted 5 lines
drivers/pci/endpoint/pci-epc-core.c +1 -1
@@ -228,7 +228,7 @@ int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 		return -EINVAL;
 
 	if (!epc->ops->raise_irq)
-		return 0;
+		return -EINVAL;

ENOTSUPP ?

drivers/pci/endpoint/pci-epc-core.c int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u8 interrupts) · line 343

Quoted 9 lines
drivers/pci/endpoint/pci-epc-core.c +1 -1
 	mutex_lock(&epc->lock);
 	ret = epc->ops->raise_irq(epc, func_no, vfunc_no, type, interrupt_num);
@@ -340,7 +340,7 @@ int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u8 interrupts)
 		return -EINVAL;
 
 	if (!epc->ops->set_msi)
-		return 0;
+		return -EINVAL;

ENOTSUPP ?

drivers/pci/endpoint/pci-epc-core.c int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no, · line 411

Quoted 9 lines
drivers/pci/endpoint/pci-epc-core.c +1 -1
 	encode_int = order_base_2(interrupts);
 
@@ -408,7 +408,7 @@ int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 		return -EINVAL;
 
 	if (!epc->ops->set_msix)
-		return 0;
+		return -EINVAL;

ENOTSUPP ?

drivers/pci/endpoint/pci-epc-core.c int pci_epc_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no, · line 472

Quoted 9 lines
drivers/pci/endpoint/pci-epc-core.c +1 -1
 	mutex_lock(&epc->lock);
 	ret = epc->ops->set_msix(epc, func_no, vfunc_no, interrupts - 1, bir,
@@ -469,7 +469,7 @@ int pci_epc_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 		return -EINVAL;
 
 	if (!epc->ops->map_addr)
-		return 0;
+		return -EINVAL;

This one is definitely mandatory and should always be defined. So check in __pci_epc_create() ?

drivers/pci/endpoint/pci-epc-core.c int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no, · line 540

Quoted 9 lines
drivers/pci/endpoint/pci-epc-core.c +1 -1
 	mutex_lock(&epc->lock);
 	ret = epc->ops->map_addr(epc, func_no, vfunc_no, phys_addr, pci_addr,
@@ -537,7 +537,7 @@ int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 		return -EINVAL;
 
 	if (!epc->ops->set_bar)
-		return 0;
+		return -EINVAL;

Same.

drivers/pci/endpoint/pci-epc-core.c int pci_epc_write_header(struct pci_epc *epc, u8 func_no, u8 vfunc_no, · line 578

Quoted 9 lines
drivers/pci/endpoint/pci-epc-core.c +1 -1
 	mutex_lock(&epc->lock);
 	ret = epc->ops->set_bar(epc, func_no, vfunc_no, epf_bar);
@@ -575,7 +575,7 @@ int pci_epc_write_header(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 		return -EINVAL;
 
 	if (!epc->ops->write_header)
-		return 0;
+		return -EINVAL;

Same.

Quoted 3 lines
drivers/pci/endpoint/pci-epc-core.c +0 -0
 	mutex_lock(&epc->lock);
 	ret = epc->ops->write_header(epc, func_no, vfunc_no, header);
Signature · 2 lines
Damien Le Moal
Western Digital Research