[PATCH] virtio: make PCI devices take a virtio_pci module ref



Nothing takes a ref on virtio_pci, so even if you have
devices in use, rmmod will attempt to unload the module.

Fix by simply making each device take a ref on the module.

Signed-off-by: Mark McLoughlin <markmc@xxxxxxxxxx>
Reported-by: Michael Tokarev <mjt@xxxxxxxxxx>
---
drivers/virtio/virtio_pci.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index c7dc37c..147a17f 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -322,6 +322,9 @@ static int __devinit virtio_pci_probe(struct pci_dev *pci_dev,
return -ENODEV;
}

+ if (!try_module_get(THIS_MODULE))
+ return -ENODEV;
+
/* allocate our structure and fill it out */
vp_dev = kzalloc(sizeof(struct virtio_pci_device), GFP_KERNEL);
if (vp_dev == NULL)
@@ -393,6 +396,7 @@ static void __devexit virtio_pci_remove(struct pci_dev *pci_dev)
pci_release_regions(pci_dev);
pci_disable_device(pci_dev);
kfree(vp_dev);
+ module_put(THIS_MODULE);
}

#ifdef CONFIG_PM
--
1.6.0.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: FW : airo suspend problem
    ... After a fsck and some manual fix for symbolic links, ... Symlink /etc/rc0.d/S32portmap (inode #375205) is invalid. ... Inode 131393 ref count is 17665, ...
    (Linux-Kernel)
  • Re: vfs-scale, general questions (Re: NFS root lockups with -next 20110113)
    ... Other than the fix, here are more generic questions about vfs-scale work. ... Well dget and mntget is not a problem, ... only dget when already guaranteeing a ref on the dentry. ... I made a small hash table of rename locks. ...
    (Linux-Kernel)
  • Re: #Ref! Returned
    ... Thanks Ken, I wasn't aware of the F9 function, I received a fix from Frank ... the #Ref! ... the range name area to the Employee Name, as if there is no Employee Name, ... > don't know this, but you can highlight on the formula bar, only one of ...
    (microsoft.public.excel.programming)
  • [patch 61/67] invalidate_inode_pages2(): ignore page refcounts
    ... The recent fix to invalidate_inode_pagesmanaged to ... the lru_cache_addbatching pagevecs also hold a ref. ... Net result is transient failures in invalidate_inode_pages2. ... NFS directory invalidation and presumably also block-backed ...
    (Linux-Kernel)
  • Re: SUMIF function referring to values on different Worksheet
    ... I did fix this but the formula still doesn't work. ... > Wrap around? ... >>> Copying this formula gave me a REF error. ... >> SUMIF ...
    (microsoft.public.excel.worksheet.functions)