From patchwork Tue Mar 18 11:58:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 3848141 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C1225BF540 for ; Tue, 18 Mar 2014 11:58:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E2EB92039D for ; Tue, 18 Mar 2014 11:58:56 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id A99672038E for ; Tue, 18 Mar 2014 11:58:55 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id C48802608B7; Tue, 18 Mar 2014 12:58:53 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NO_DNS_FOR_FROM, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 86F06260320; Tue, 18 Mar 2014 12:58:43 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id E623E260786; Tue, 18 Mar 2014 12:58:41 +0100 (CET) Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id F209B260320 for ; Tue, 18 Mar 2014 12:58:34 +0100 (CET) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id EA00A75015; Tue, 18 Mar 2014 11:58:34 +0000 (UTC) From: Takashi Iwai To: Mark Brown Date: Tue, 18 Mar 2014 12:58:34 +0100 Message-Id: <1395143914-26929-2-git-send-email-tiwai@suse.de> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1395143914-26929-1-git-send-email-tiwai@suse.de> References: <1395143914-26929-1-git-send-email-tiwai@suse.de> Cc: alsa-devel@alsa-project.org, Lars-Peter Clausen , swarren@wwwdotorg.org, abrestic@chromium.org, linux-tegra@vger.kernel.org, Dylan Reid Subject: [alsa-devel] [PATCH v2 2/2] remgap: Fix possible sleep-in-atomic in regmap_register_patch() X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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;