Avoid leak on 64bit register or reserved BAR
Subsystems (2)
PATCH 1/1 Avoid leak on 64bit register or reserved BAR
From: Alan Mikhak <[email protected]>
Always check 64bit flag before skipping BARs in pci_epf_test_alloc_space(). Otherwise will call pci_epf_alloc_space() on bind for odd loop index when BAR is 64bit but leaks on subsequent unbind by not calling pci_epf_free_space().
Signed-off-by Alan Mikhak <[email protected]>
--- drivers/pci/endpoint/functions/pci-epf-test.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/pci/endpoint/functions/pci-epf-test.c +5 -5
@@ -431,7 +431,7 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)struct device *dev = &epf->dev;struct pci_epf_bar *epf_bar;void *base; -int bar; +int bar, add;enum pci_barno test_reg_bar = epf_test->test_reg_bar;const struct pci_epc_features *epc_features;
@@ -440,13 +440,15 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) base =pci_epf_alloc_space (epf,sizeof (struct pci_epf_test_reg ), test_reg_bar);if (!base) { -dev_err (dev,"Failed to allocated register space\n" ); +dev_err (dev,"Failed to allocate register space\n" );return -ENOMEM ; } epf_test->reg[test_reg_bar] = base; -for (bar =BAR_0 ; bar <=BAR_5 ; bar++) { +for (bar =BAR_0 ; bar <=BAR_5 ; bar += add) { epf_bar = &epf->bar[bar]; + add = (epf_bar->flags &PCI_BASE_ADDRESS_MEM_TYPE_64 ) ?2 :1 ; +if (bar == test_reg_bar)continue ;
@@ -458,8 +460,6 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)dev_err (dev,"Failed to allocate space for BAR%d\n" , bar); epf_test->reg[bar] = base; -if (epf_bar->flags &PCI_BASE_ADDRESS_MEM_TYPE_64 ) - bar++; }return 0 ;
Signature · 1 line
2.7.4