lkml.org 
[lkml]   [2019]   [Sep]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 -next] PCI: Don't use GFP_KERNEL for kstrbdup in resource_alignment_store
Date
When allocating memory, the GFP_KERNEL cannot be used during the
spin_lock period. It may cause scheduling when holding spin_lock.

Suggested-by: Christoph Hellwig <hch@infradead.org>
Fixes: f13755318675 ("PCI: Move pci_[get|set]_resource_alignment_param() into their callers")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
v2: move alloc out of spinlock
---
drivers/pci/pci.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 484e353..a3d5920 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -6145,14 +6145,17 @@ static ssize_t resource_alignment_show(struct bus_type *bus, char *buf)
static ssize_t resource_alignment_store(struct bus_type *bus,
const char *buf, size_t count)
{
- spin_lock(&resource_alignment_lock);
+ char *param = kstrndup(buf, count, GFP_KERNEL);

- kfree(resource_alignment_param);
- resource_alignment_param = kstrndup(buf, count, GFP_KERNEL);
+ if (!param)
+ return -ENOMEM;

+ spin_lock(&resource_alignment_lock);
+ kfree(resource_alignment_param);
+ resource_alignment_param = param;
spin_unlock(&resource_alignment_lock);

- return resource_alignment_param ? count : -ENOMEM;
+ return count;
}

static BUS_ATTR_RW(resource_alignment);
--
2.7.4

\
 
 \ /
  Last update: 2019-09-03 10:25    [W:0.049 / U:1.824 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site