All of lore.kernel.org
 help / color / mirror / Atom feed
From: YueHaibing <yuehaibing@huawei.com>
To: <bhelgaas@google.com>, <hch@infradead.org>
Cc: <linux-pci@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	YueHaibing <yuehaibing@huawei.com>
Subject: [PATCH v2 -next] PCI: Don't use GFP_KERNEL for kstrbdup in resource_alignment_store
Date: Tue, 3 Sep 2019 16:22:29 +0800	[thread overview]
Message-ID: <20190903082229.21488-1-yuehaibing@huawei.com> (raw)
In-Reply-To: <20190831124932.18759-1-yuehaibing@huawei.com>

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



      parent reply	other threads:[~2019-09-03  8:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-31 12:49 [PATCH -next] PCI: Use GFP_ATOMIC in resource_alignment_store() YueHaibing
2019-08-31 12:49 ` YueHaibing
2019-09-02  7:50 ` Christoph Hellwig
2019-09-02  7:50   ` Christoph Hellwig
2019-09-03 15:51   ` Logan Gunthorpe
2019-09-03 15:51     ` Logan Gunthorpe
2019-09-05 21:47     ` Bjorn Helgaas
2019-09-05 21:47       ` Bjorn Helgaas
2019-09-03  8:22 ` YueHaibing [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190903082229.21488-1-yuehaibing@huawei.com \
    --to=yuehaibing@huawei.com \
    --cc=bhelgaas@google.com \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.