@@ -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);
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(-)