Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a55709ba authored by Jay Fenlason's avatar Jay Fenlason Committed by Stefan Richter
Browse files

firewire: fw-ohci: don't leak dma memory on module removal



The transmit and receive context dma memory was not being freed on
module removal.  Neither was the config rom memory.  Fix that.

The ab->next assignment is pure paranoia.

Signed-off-by: default avatarJay Fenlason <fenlason@redhat.com>
Signed-off-by: default avatarStefan Richter <stefanr@s5r6.in-berlin.de>
parent 77e55719
Loading
Loading
Loading
Loading
+27 −0
Original line number Original line Diff line number Diff line
@@ -476,6 +476,7 @@ static int ar_context_add_page(struct ar_context *ctx)
	if (ab == NULL)
	if (ab == NULL)
		return -ENOMEM;
		return -ENOMEM;


	ab->next = NULL;
	memset(&ab->descriptor, 0, sizeof(ab->descriptor));
	memset(&ab->descriptor, 0, sizeof(ab->descriptor));
	ab->descriptor.control        = cpu_to_le16(DESCRIPTOR_INPUT_MORE |
	ab->descriptor.control        = cpu_to_le16(DESCRIPTOR_INPUT_MORE |
						    DESCRIPTOR_STATUS |
						    DESCRIPTOR_STATUS |
@@ -496,6 +497,21 @@ static int ar_context_add_page(struct ar_context *ctx)
	return 0;
	return 0;
}
}


static void ar_context_release(struct ar_context *ctx)
{
	struct ar_buffer *ab, *ab_next;
	size_t offset;
	dma_addr_t ab_bus;

	for (ab = ctx->current_buffer; ab; ab = ab_next) {
		ab_next = ab->next;
		offset = offsetof(struct ar_buffer, data);
		ab_bus = le32_to_cpu(ab->descriptor.data_address) - offset;
		dma_free_coherent(ctx->ohci->card.device, PAGE_SIZE,
				  ab, ab_bus);
	}
}

#if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32)
#if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32)
#define cond_le32_to_cpu(v) \
#define cond_le32_to_cpu(v) \
	(ohci->old_uninorth ? (__force __u32)(v) : le32_to_cpu(v))
	(ohci->old_uninorth ? (__force __u32)(v) : le32_to_cpu(v))
@@ -2491,8 +2507,19 @@ static void pci_remove(struct pci_dev *dev)


	software_reset(ohci);
	software_reset(ohci);
	free_irq(dev->irq, ohci);
	free_irq(dev->irq, ohci);

	if (ohci->next_config_rom && ohci->next_config_rom != ohci->config_rom)
		dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE,
				  ohci->next_config_rom, ohci->next_config_rom_bus);
	if (ohci->config_rom)
		dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE,
				  ohci->config_rom, ohci->config_rom_bus);
	dma_free_coherent(ohci->card.device, SELF_ID_BUF_SIZE,
	dma_free_coherent(ohci->card.device, SELF_ID_BUF_SIZE,
			  ohci->self_id_cpu, ohci->self_id_bus);
			  ohci->self_id_cpu, ohci->self_id_bus);
	ar_context_release(&ohci->ar_request_ctx);
	ar_context_release(&ohci->ar_response_ctx);
	context_release(&ohci->at_request_ctx);
	context_release(&ohci->at_response_ctx);
	kfree(ohci->it_context_list);
	kfree(ohci->it_context_list);
	kfree(ohci->ir_context_list);
	kfree(ohci->ir_context_list);
	pci_iounmap(dev, ohci->registers);
	pci_iounmap(dev, ohci->registers);