Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] remgap: Fix possible sleep-in-atomic in regmap_bulk_write()
@ 2014-03-18 11:58 Takashi Iwai
       [not found] ` <1395143914-26929-1-git-send-email-tiwai-l3A5Bk7waGM@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Takashi Iwai @ 2014-03-18 11:58 UTC (permalink / raw)
  To: Mark Brown
  Cc: Lars-Peter Clausen, Dylan Reid, abrestic-F7+t8E8rja9g9hUCZPvPmw,
	swarren-3lzwWm7+Weoh9ZMKESR00Q,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw

regmap deploys the spinlock for the protection when set up in fast_io
mode.  This may lead to sleep-in-atomic by memory allocation with
GFP_KERNEL in regmap_bulk_write().  This patch fixes it by moving the
allocation out of the lock.

Signed-off-by: Takashi Iwai <tiwai-l3A5Bk7waGM@public.gmane.org>
---
 drivers/base/regmap/regmap.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 6a19515f8a45..6d134a3cbfd3 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -1520,12 +1520,12 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
 	if (reg % map->reg_stride)
 		return -EINVAL;
 
-	map->lock(map->lock_arg);
 	/*
 	 * Some devices don't support bulk write, for
 	 * them we have a series of single write operations.
 	 */
 	if (!map->bus || map->use_single_rw) {
+		map->lock(map->lock_arg);
 		for (i = 0; i < val_count; i++) {
 			unsigned int ival;
 
@@ -1554,24 +1554,25 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
 			if (ret != 0)
 				goto out;
 		}
+out:
+		map->unlock(map->lock_arg);
 	} else {
 		void *wval;
 
 		wval = kmemdup(val, val_count * val_bytes, GFP_KERNEL);
 		if (!wval) {
-			ret = -ENOMEM;
 			dev_err(map->dev, "Error in memory allocation\n");
-			goto out;
+			return -ENOMEM;
 		}
+		map->lock(map->lock_arg);
 		for (i = 0; i < val_count * val_bytes; i += val_bytes)
 			map->format.parse_inplace(wval + i);
 
 		ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count);
+		map->unlock(map->lock_arg);
 
 		kfree(wval);
 	}
-out:
-	map->unlock(map->lock_arg);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(regmap_bulk_write);
-- 
1.9.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-03-18 20:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-18 11:58 [PATCH v2 1/2] remgap: Fix possible sleep-in-atomic in regmap_bulk_write() Takashi Iwai
     [not found] ` <1395143914-26929-1-git-send-email-tiwai-l3A5Bk7waGM@public.gmane.org>
2014-03-18 11:58   ` [PATCH v2 2/2] remgap: Fix possible sleep-in-atomic in regmap_register_patch() Takashi Iwai
     [not found]     ` <1395143914-26929-2-git-send-email-tiwai-l3A5Bk7waGM@public.gmane.org>
2014-03-18 12:03       ` Mark Brown
2014-03-18 12:22   ` [PATCH v2 1/2] remgap: Fix possible sleep-in-atomic in regmap_bulk_write() Mark Brown
     [not found]     ` <20140318122218.GQ11706-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-03-18 12:57       ` Takashi Iwai
     [not found]         ` <s5hr45zr7f1.wl%tiwai-l3A5Bk7waGM@public.gmane.org>
2014-03-18 13:04           ` Mark Brown
     [not found]             ` <20140318130426.GA11706-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-03-18 13:36               ` Takashi Iwai
     [not found]                 ` <s5hob13r5l6.wl%tiwai-l3A5Bk7waGM@public.gmane.org>
2014-03-18 20:21                   ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox