Skip to content

Commit 0e27aec

Browse files
kishonbjorn-helgaas
authored andcommitted
PCI: endpoint: Make *_free_bar() to return error codes on failure
Modify pci_epc_get_next_free_bar() and pci_epc_get_first_free_bar() to return error values if there are no free BARs available. Link: https://lore.kernel.org/r/20210201195809.7342-5-kishon@ti.com Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent fa8fef0 commit 0e27aec

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

drivers/pci/endpoint/functions/pci-epf-test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,8 @@ static int pci_epf_test_bind(struct pci_epf *epf)
834834
linkup_notifier = epc_features->linkup_notifier;
835835
core_init_notifier = epc_features->core_init_notifier;
836836
test_reg_bar = pci_epc_get_first_free_bar(epc_features);
837+
if (test_reg_bar < 0)
838+
return -EINVAL;
837839
pci_epf_configure_bar(epf, epc_features);
838840
}
839841

drivers/pci/endpoint/pci-epc-core.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ EXPORT_SYMBOL_GPL(pci_epc_get);
9090
* Invoke to get the first unreserved BAR that can be used by the endpoint
9191
* function. For any incorrect value in reserved_bar return '0'.
9292
*/
93-
unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features
94-
*epc_features)
93+
enum pci_barno
94+
pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features)
9595
{
9696
return pci_epc_get_next_free_bar(epc_features, BAR_0);
9797
}
@@ -105,13 +105,13 @@ EXPORT_SYMBOL_GPL(pci_epc_get_first_free_bar);
105105
* Invoke to get the next unreserved BAR starting from @bar that can be used
106106
* for endpoint function. For any incorrect value in reserved_bar return '0'.
107107
*/
108-
unsigned int pci_epc_get_next_free_bar(const struct pci_epc_features
109-
*epc_features, enum pci_barno bar)
108+
enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features
109+
*epc_features, enum pci_barno bar)
110110
{
111111
unsigned long free_bar;
112112

113113
if (!epc_features)
114-
return 0;
114+
return BAR_0;
115115

116116
/* If 'bar - 1' is a 64-bit BAR, move to the next BAR */
117117
if ((epc_features->bar_fixed_64bit << 1) & 1 << bar)
@@ -126,7 +126,7 @@ unsigned int pci_epc_get_next_free_bar(const struct pci_epc_features
126126

127127
free_bar = find_next_zero_bit(&free_bar, 6, bar);
128128
if (free_bar > 5)
129-
return 0;
129+
return NO_BAR;
130130

131131
return free_bar;
132132
}

include/linux/pci-epc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ int pci_epc_start(struct pci_epc *epc);
201201
void pci_epc_stop(struct pci_epc *epc);
202202
const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
203203
u8 func_no);
204-
unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features
205-
*epc_features);
206-
unsigned int pci_epc_get_next_free_bar(const struct pci_epc_features
207-
*epc_features, enum pci_barno bar);
204+
enum pci_barno
205+
pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features);
206+
enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features
207+
*epc_features, enum pci_barno bar);
208208
struct pci_epc *pci_epc_get(const char *epc_name);
209209
void pci_epc_put(struct pci_epc *epc);
210210

include/linux/pci-epf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ enum pci_notify_event {
2121
};
2222

2323
enum pci_barno {
24+
NO_BAR = -1,
2425
BAR_0,
2526
BAR_1,
2627
BAR_2,

0 commit comments

Comments
 (0)