All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@codeaurora.org>
To: Mark Brown <broonie@kernel.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] regmap: Allocate buffers with GFP_ATOMIC when fast_io == true
Date: Thu, 10 Sep 2015 12:27:01 -0700	[thread overview]
Message-ID: <1441913221-19622-1-git-send-email-sboyd@codeaurora.org> (raw)

If a regmap is using fast_io, allocate buffers in the write APIs
with GFP_ATOMIC instead of GFP_KERNEL. Otherwise we may schedule
while atomic.

Reported-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
---
 drivers/base/regmap/internal.h |  1 +
 drivers/base/regmap/regmap.c   | 16 +++++++++++-----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
index 873ddf91c9d3..3470ec146f12 100644
--- a/drivers/base/regmap/internal.h
+++ b/drivers/base/regmap/internal.h
@@ -59,6 +59,7 @@ struct regmap {
 	regmap_lock lock;
 	regmap_unlock unlock;
 	void *lock_arg; /* This is passed to lock/unlock functions */
+	gfp_t alloc_flags;
 
 	struct device *dev; /* Device we do I/O on */
 	void *work_buf;     /* Scratch buffer used to format I/O */
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 29128c6af445..0ad22f4d40b1 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -563,6 +563,12 @@ struct regmap *regmap_init(struct device *dev,
 		}
 		map->lock_arg = map;
 	}
+
+	if ((bus && bus->fast_io) || config->fast_io)
+		map->alloc_flags = GFP_ATOMIC;
+	else
+		map->alloc_flags = GFP_KERNEL;
+
 	map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
 	map->format.pad_bytes = config->pad_bits / 8;
 	map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8);
@@ -1296,7 +1302,7 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg,
 				return -ENOMEM;
 
 			async->work_buf = kzalloc(map->format.buf_size,
-						  GFP_KERNEL | GFP_DMA);
+						  map->alloc_flags | GFP_DMA);
 			if (!async->work_buf) {
 				kfree(async);
 				return -ENOMEM;
@@ -1358,7 +1364,7 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg,
 	/* If that didn't work fall back on linearising by hand. */
 	if (ret == -ENOTSUPP) {
 		len = map->format.reg_bytes + map->format.pad_bytes + val_len;
-		buf = kzalloc(len, GFP_KERNEL);
+		buf = kzalloc(len, map->alloc_flags);
 		if (!buf)
 			return -ENOMEM;
 
@@ -1729,7 +1735,7 @@ out:
 		if (!val_count)
 			return -EINVAL;
 
-		wval = kmemdup(val, val_count * val_bytes, GFP_KERNEL);
+		wval = kmemdup(val, val_count * val_bytes, map->alloc_flags);
 		if (!wval) {
 			dev_err(map->dev, "Error in memory allocation\n");
 			return -ENOMEM;
@@ -1771,7 +1777,7 @@ static int _regmap_raw_multi_reg_write(struct regmap *map,
 	if (!len)
 		return -EINVAL;
 
-	buf = kzalloc(len, GFP_KERNEL);
+	buf = kzalloc(len, map->alloc_flags);
 	if (!buf)
 		return -ENOMEM;
 
@@ -1909,7 +1915,7 @@ static int _regmap_multi_reg_write(struct regmap *map,
 		if (range) {
 			size_t len = sizeof(struct reg_sequence)*num_regs;
 			struct reg_sequence *base = kmemdup(regs, len,
-							   GFP_KERNEL);
+							   map->alloc_flags);
 			if (!base)
 				return -ENOMEM;
 			ret = _regmap_range_multi_paged_reg_write(map, base,
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


             reply	other threads:[~2015-09-10 19:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-10 19:27 Stephen Boyd [this message]
2015-09-11 10:28 ` [PATCH] regmap: Allocate buffers with GFP_ATOMIC when fast_io == true Mark Brown
2015-09-11 16:16   ` Stephen Boyd
2015-09-11 17:24     ` Mark Brown

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=1441913221-19622-1-git-send-email-sboyd@codeaurora.org \
    --to=sboyd@codeaurora.org \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@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.