WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [Patch] linux: avoid kmalloc while disabling interrupts

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [Patch] linux: avoid kmalloc while disabling interrupts
From: Akio Takebe <takebe_akio@xxxxxxxxxxxxxx>
Date: Tue, 09 Sep 2008 16:41:48 +0900
Delivery-date: Tue, 09 Sep 2008 00:42:14 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 2.0.0.16 (X11/20080723)
Hi,

We should avoid using kmalloc while interrupts is disabled.
kmalloc may sleep.

Signed-off-by: Akio Takebe <takebe_akio@xxxxxxxxxxxxxx>

Best Regards,

Akio Takebe
diff -r e86f9e05144a drivers/xen/pciback/controller.c
--- a/drivers/xen/pciback/controller.c  Mon Sep 08 14:02:13 2008 +0100
+++ b/drivers/xen/pciback/controller.c  Tue Sep 09 16:28:20 2008 +0900
@@ -101,15 +101,15 @@
        unsigned long flags;
        int ret = 0, found = 0;
 
+       /* Look to see if we already have a domain:bus for this controller */
        spin_lock_irqsave(&dev_data->lock, flags);
-
-       /* Look to see if we already have a domain:bus for this controller */
        list_for_each_entry(cntrl_entry, &dev_data->list, list) {
                if (cntrl_entry->controller == dev_controller) {
                        found = 1;
                        break;
                }
        }
+       spin_unlock_irqrestore(&dev_data->lock, flags);
 
        if (!found) {
                cntrl_entry = kmalloc(sizeof(*cntrl_entry), GFP_ATOMIC);
@@ -128,9 +128,10 @@
                        dev_data->next_bus = 0;
                }
 
+               spin_lock_irqsave(&dev_data->lock, flags);
                INIT_LIST_HEAD(&cntrl_entry->dev_list);
-
                list_add_tail(&cntrl_entry->list, &dev_data->list);
+               spin_unlock_irqrestore(&dev_data->lock, flags);
        }
 
        if (PCI_SLOT(cntrl_entry->next_devfn) > PCI_MAX_SLOTS) {
@@ -149,24 +150,24 @@
 
        dev_entry = kmalloc(sizeof(*dev_entry), GFP_ATOMIC);
        if (!dev_entry) {
+               spin_lock_irqsave(&dev_data->lock, flags);
                if (list_empty(&cntrl_entry->dev_list)) {
                        list_del(&cntrl_entry->list);
                        kfree(cntrl_entry);
                }
                ret = -ENOMEM;
+               spin_unlock_irqrestore(&dev_data->lock, flags);
                goto out;
        }
 
        dev_entry->dev = dev;
        dev_entry->devfn = cntrl_entry->next_devfn;
 
+       spin_lock_irqsave(&dev_data->lock, flags);
        list_add_tail(&dev_entry->list, &cntrl_entry->dev_list);
-
        cntrl_entry->next_devfn += PCI_DEVFN(1, 0);
-
+       spin_unlock_irqrestore(&dev_data->lock, flags);
 out:
-       spin_unlock_irqrestore(&dev_data->lock, flags);
-
        /* TODO: Publish virtual domain:bus:slot.func here. */
 
        return ret;
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>