mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sergey Vlasov <vsu@altlinux.ru>
To: Manu Abraham <manu@linuxtv.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: free free irq and Oops on cat /proc/interrupts (2)
Date: Sat, 17 Sep 2005 23:10:58 +0400	[thread overview]
Message-ID: <20050917191058.GJ11302@procyon.home> (raw)
In-Reply-To: <432C5F93.80506@linuxtv.org>

[-- Attachment #1: Type: text/plain, Size: 1971 bytes --]

On Sat, Sep 17, 2005 at 10:25:23PM +0400, Manu Abraham wrote:
[skip]
> static int __devinit mantis_pci_probe(struct pci_dev *pdev,
> 				const struct pci_device_id *mantis_pci_table)
> {
> 	u8 revision, latency;
> 	struct mantis_pci *mantis;
> 
> 	mantis = (struct mantis_pci *)
> 				kmalloc(sizeof (struct mantis_pci), GFP_KERNEL);
> 	if (mantis == NULL) {
> 		dprintk(verbose, MANTIS_ERROR, 1, "Out of memory");
> 		return -ENOMEM;
> 	}
> 	if (pci_enable_device(pdev)) {
> 		dprintk(verbose, MANTIS_ERROR, 1, "Mantis PCI enable failed");
> 		goto err;
> 	}
> 	dprintk(verbose, MANTIS_ERROR, 1, "<2:>IRQ=%d", pdev->irq);
> 
> 	dprintk(verbose, MANTIS_ERROR, 1, "Got a device");
> 	if (request_irq(pdev->irq, mantis_pci_irq, SA_SHIRQ | SA_INTERRUPT, 
> 						DRIVER_NAME, mantis) < 0) {

Some code is obviously missing here...

> 	dprintk(verbose, MANTIS_DEBUG, 1, "We got an IRQ");
> 	return 0;
> 
> err:
> 	dprintk(verbose, MANTIS_DEBUG, 1, "<freak out>");
> 	kfree(mantis);
> 	return -ENODEV;
> }
> 
> 
> 
> static void __devexit mantis_pci_remove(struct pci_dev *pdev)
> {
> 	free_irq(pdev->irq, pdev);

Here is the next problem - you must give free_irq() the same pointer
that you have passed to request_irq().  So you need a way to get from
a struct pci_dev for your device to the corresponding struct
mantis_pci.  This is done as follows:

1) In your mantis_pci_probe(), when you have initialized the device
successfully, put the pointer to you data structure into the PCI
device structure:

	pci_set_drvdata(pdev, mantis);

2) In mantis_pci_remove() (and later in other PCI driver functions,
like suspend/resume) get this pointer back:

	struct mantis_pci *mantis = pci_get_drvdata(pdev);

Then use that pointer where you need it (e.g., in free_irq()).

3) mantis_pci_remove() should also clear out the pointer to the driver
data:

	pci_set_drvdata(pdev, NULL);

> 	pci_disable_device(pdev);
> }

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2005-09-17 19:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-17 15:20 Manu Abraham
2005-09-17 17:56 ` Sergey Vlasov
2005-09-17 18:25   ` Manu Abraham
2005-09-17 19:10     ` Sergey Vlasov [this message]
2005-09-17 19:28       ` Manu Abraham
2005-09-17 19:49         ` Sergey Vlasov
2005-09-17 19:49           ` Manu Abraham
2005-09-17 22:09           ` Manu Abraham
2005-09-17 18:39 ` Jiri Slaby
2005-09-17 19:24   ` Manu Abraham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050917191058.GJ11302@procyon.home \
    --to=vsu@altlinux.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manu@linuxtv.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®