[alsa-devel] [PATCH v2 2/2] remgap: Fix possible sleep-in-atomic in regmap_register_patch()
Takashi Iwai
tiwai at suse.de
Tue Mar 18 12:58:34 CET 2014
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 at suse.de>
---
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
More information about the Alsa-devel
mailing list