Skip to content

Commit 5716e58

Browse files
committed
firewire: ohci: release buffer for AR req/resp contexts when managed resource is released
The 1394 OHCI driver allocates several non-coherent DMA buffers for AR request and response contexts. The buffers are mapped to kernel virtual address (VMA) so that the first page locates after the last page. Even when large payload of packet is handled crossing the boundary of buffers, the driver operates continuously on VMA. No kernel API is provided for this kind of mapping, while it is possible to release the buffer when PCI device is going to be released. This commit moves the call of release helper function to the callback function of release resources. Link: https://lore.kernel.org/r/20230604054451.161076-10-o-takashi@sakamocchi.jp Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
1 parent aeaf6aa commit 5716e58

1 file changed

Lines changed: 14 additions & 17 deletions

File tree

drivers/firewire/ohci.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,9 @@ static void ar_context_release(struct ar_context *ctx)
677677
struct device *dev = ctx->ohci->card.device;
678678
unsigned int i;
679679

680+
if (!ctx->buffer)
681+
return;
682+
680683
vunmap(ctx->buffer);
681684

682685
for (i = 0; i < AR_BUFFERS; i++) {
@@ -3556,9 +3559,13 @@ static inline void pmac_ohci_off(struct pci_dev *dev) {}
35563559
static void release_ohci(struct device *dev, void *data)
35573560
{
35583561
struct pci_dev *pdev = to_pci_dev(dev);
3562+
struct fw_ohci *ohci = pci_get_drvdata(pdev);
35593563

35603564
pmac_ohci_off(pdev);
35613565

3566+
ar_context_release(&ohci->ar_response_ctx);
3567+
ar_context_release(&ohci->ar_request_ctx);
3568+
35623569
dev_notice(dev, "removed fw-ohci device\n");
35633570
}
35643571

@@ -3643,17 +3650,17 @@ static int pci_probe(struct pci_dev *dev,
36433650
err = ar_context_init(&ohci->ar_response_ctx, ohci, PAGE_SIZE/4,
36443651
OHCI1394_AsRspRcvContextControlSet);
36453652
if (err < 0)
3646-
goto fail_arreq_ctx;
3653+
return err;
36473654

36483655
err = context_init(&ohci->at_request_ctx, ohci,
36493656
OHCI1394_AsReqTrContextControlSet, handle_at_packet);
36503657
if (err < 0)
3651-
goto fail_arrsp_ctx;
3658+
return err;
36523659

36533660
err = context_init(&ohci->at_response_ctx, ohci,
36543661
OHCI1394_AsRspTrContextControlSet, handle_at_packet);
36553662
if (err < 0)
3656-
goto fail_arrsp_ctx;
3663+
return err;
36573664

36583665
reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, ~0);
36593666
ohci->ir_context_channels = ~0ULL;
@@ -3663,10 +3670,8 @@ static int pci_probe(struct pci_dev *dev,
36633670
ohci->n_ir = hweight32(ohci->ir_context_mask);
36643671
size = sizeof(struct iso_context) * ohci->n_ir;
36653672
ohci->ir_context_list = devm_kzalloc(&dev->dev, size, GFP_KERNEL);
3666-
if (!ohci->ir_context_list) {
3667-
err = -ENOMEM;
3668-
goto fail_arrsp_ctx;
3669-
}
3673+
if (!ohci->ir_context_list)
3674+
return -ENOMEM;
36703675

36713676
reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, ~0);
36723677
ohci->it_context_support = reg_read(ohci, OHCI1394_IsoXmitIntMaskSet);
@@ -3680,10 +3685,8 @@ static int pci_probe(struct pci_dev *dev,
36803685
ohci->n_it = hweight32(ohci->it_context_mask);
36813686
size = sizeof(struct iso_context) * ohci->n_it;
36823687
ohci->it_context_list = devm_kzalloc(&dev->dev, size, GFP_KERNEL);
3683-
if (!ohci->it_context_list) {
3684-
err = -ENOMEM;
3685-
goto fail_arrsp_ctx;
3686-
}
3688+
if (!ohci->it_context_list)
3689+
return -ENOMEM;
36873690

36883691
ohci->self_id = ohci->misc_buffer + PAGE_SIZE/2;
36893692
ohci->self_id_bus = ohci->misc_buffer_bus + PAGE_SIZE/2;
@@ -3720,10 +3723,6 @@ static int pci_probe(struct pci_dev *dev,
37203723

37213724
fail_msi:
37223725
pci_disable_msi(dev);
3723-
fail_arrsp_ctx:
3724-
ar_context_release(&ohci->ar_response_ctx);
3725-
fail_arreq_ctx:
3726-
ar_context_release(&ohci->ar_request_ctx);
37273726

37283727
return err;
37293728
}
@@ -3750,8 +3749,6 @@ static void pci_remove(struct pci_dev *dev)
37503749

37513750
software_reset(ohci);
37523751

3753-
ar_context_release(&ohci->ar_request_ctx);
3754-
ar_context_release(&ohci->ar_response_ctx);
37553752
pci_disable_msi(dev);
37563753

37573754
dev_notice(&dev->dev, "removing fw-ohci device\n");

0 commit comments

Comments
 (0)