All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai-l3A5Bk7waGM@public.gmane.org>
To: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>,
	Dylan Reid <dgreid-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
	abrestic-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org,
	swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org
Subject: [PATCH v2 2/2] remgap: Fix possible sleep-in-atomic in regmap_register_patch()
Date: Tue, 18 Mar 2014 12:58:34 +0100	[thread overview]
Message-ID: <1395143914-26929-2-git-send-email-tiwai@suse.de> (raw)
In-Reply-To: <1395143914-26929-1-git-send-email-tiwai-l3A5Bk7waGM@public.gmane.org>

Just like the previous, fix the possible sleep-in-atomic in
regmap_register_patch() by moving the allocation out of the lock.

This makes the function unsafe for concurrent access as map->patch and
map->patch_regs are changed without lock now.  But such a use case
must be very rare, thus we take rather simplicity over complexity, and
add a note in the function description mentioning this restriction.

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

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 6d134a3cbfd3..e6827cee29a3 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2174,6 +2174,10 @@ EXPORT_SYMBOL_GPL(regmap_async_complete);
  * apply them immediately.  Typically this is used to apply
  * corrections to be applied to the device defaults on startup, such
  * as the updates some vendors provide to undocumented registers.
+ *
+ * Note that the function gives no protection over concurrent access
+ * to map->patch and map->patch_regs.  If needed, apply some lock in
+ * the caller side.
  */
 int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
 			  int num_regs)
@@ -2186,6 +2190,16 @@ int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
 	    num_regs))
 		return 0;
 
+	p = krealloc(map->patch,
+		     sizeof(struct reg_default) * (map->patch_regs + num_regs),
+		     GFP_KERNEL);
+	if (!p)
+		return -ENOMEM;
+
+	memcpy(p + map->patch_regs, regs, num_regs * sizeof(*regs));
+	map->patch = p;
+	map->patch_regs += num_regs;
+
 	map->lock(map->lock_arg);
 
 	bypass = map->cache_bypass;
@@ -2203,17 +2217,6 @@ int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
 		}
 	}
 
-	p = krealloc(map->patch,
-		     sizeof(struct reg_default) * (map->patch_regs + num_regs),
-		     GFP_KERNEL);
-	if (p) {
-		memcpy(p + map->patch_regs, regs, num_regs * sizeof(*regs));
-		map->patch = p;
-		map->patch_regs += num_regs;
-	} else {
-		ret = -ENOMEM;
-	}
-
 out:
 	map->async = false;
 	map->cache_bypass = bypass;
-- 
1.9.0

  parent reply	other threads:[~2014-03-18 11:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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   ` Takashi Iwai [this message]
     [not found]     ` <1395143914-26929-2-git-send-email-tiwai-l3A5Bk7waGM@public.gmane.org>
2014-03-18 12:03       ` [PATCH v2 2/2] remgap: Fix possible sleep-in-atomic in regmap_register_patch() 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

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=1395143914-26929-2-git-send-email-tiwai@suse.de \
    --to=tiwai-l3a5bk7wagm@public.gmane.org \
    --cc=abrestic-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=dgreid-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.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.