[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190903082229.21488-1-yuehaibing@huawei.com>
Date: Tue, 3 Sep 2019 16:22:29 +0800
From: YueHaibing <yuehaibing@...wei.com>
To: <bhelgaas@...gle.com>, <hch@...radead.org>
CC: <linux-pci@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
YueHaibing <yuehaibing@...wei.com>
Subject: [PATCH v2 -next] PCI: Don't use GFP_KERNEL for kstrbdup in resource_alignment_store
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@...radead.org>
Fixes: f13755318675 ("PCI: Move pci_[get|set]_resource_alignment_param() into their callers")
Signed-off-by: YueHaibing <yuehaibing@...wei.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
Powered by blists - more mailing lists