Re: PCI driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Manu Abraham wrote:
>Rolf Eike Beer wrote:
>>Manu Abraham wrote:

>>>static int __devinit mantis_pci_probe(struct pci_dev *pdev, const struct
>>>pci_device_id *mantis_pci_table)
>>>{
>>>	u8 revision, latency;
>>>	u8 data[2];
>>>	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;
>>>	}
>>>
>>>	pdev = pci_get_device(PCI_VENDOR_ID_MANTIS, PCI_DEVICE_ID_MANTIS_R11,
>>>NULL);
>>
>>This is not needed anymore then. Your probe function will get called with
>> for any pci dev your driver can handle.
>
>I will just check it up again to see what went wrong ..
>
>>>	if (pdev) {
>>>		dprintk(verbose, MANTIS_ERROR, 1, "Got a device");
>>>		mantis->mantis_addr = pci_resource_start(pdev, 0);
>>>		if (!request_mem_region(pci_resource_start(pdev, 0),
>>>			pci_resource_len(pdev, 0), DRIVER_NAME)) {
>>>			dprintk(verbose, MANTIS_ERROR, 1, "Request for memory region failed");

[...]

>>>		pci_set_drvdata(pdev, mantis);
>>>		dprintk(verbose, MANTIS_ERROR, 0, "Mantis Rev %d, ", mantis->revision);
>>>		dprintk(verbose, MANTIS_ERROR, 0, "irq: %d, latency: %d\nmemory:
>>>0x%04x, mmio: %p\n", pdev->irq, mantis->latency,
>>>			mantis->mantis_addr, mantis->mantis_mmio);
>>>
>>>		pci_dev_put(pdev);
>>
>>No, DON'T DO THAT! This will drop the a reference count from the struct
>>pci_dev, which means it can get freed while your driver still wants to work
>>with it.
>
>Hmm.. I thought after i make a call to pci_get_device(), i have to do a
>pci_dev_put() after the usage ..
>I was a bit lost when to use pci_dev_put() in this case.

That is true, but you should not call pci_get_device() in this function at 
all.

Eike

Attachment: pgpL4xgYDC0eK.pgp
Description: PGP signature


[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux