From patchwork Tue Mar 18 06:46:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 3847551 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D5F479F370 for ; Tue, 18 Mar 2014 06:46:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C980D20138 for ; Tue, 18 Mar 2014 06:46:34 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 8FCE42012D for ; Tue, 18 Mar 2014 06:46:33 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 66B6F261AF9; Tue, 18 Mar 2014 07:46:32 +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 4C2B0261AAB; Tue, 18 Mar 2014 07:46:19 +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 643F9261AB1; Tue, 18 Mar 2014 07:46:17 +0100 (CET) Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 7B7D4261A99 for ; Tue, 18 Mar 2014 07:46:10 +0100 (CET) Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2E1107501B; Tue, 18 Mar 2014 06:46:10 +0000 (UTC) Date: Tue, 18 Mar 2014 07:46:09 +0100 Message-ID: From: Takashi Iwai To: Dylan Reid In-Reply-To: <1395115139-22243-1-git-send-email-dgreid@chromium.org> References: <1395115139-22243-1-git-send-email-dgreid@chromium.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/24.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Cc: linux-tegra@vger.kernel.org, abrestic@chromium.org, alsa-devel@alsa-project.org, broonie@kernel.org, swarren@wwwdotorg.org Subject: Re: [alsa-devel] [PATCH] ASoC: tegra: Use flat regcache. 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP At Mon, 17 Mar 2014 20:58:59 -0700, Dylan Reid wrote: > > When using an rbtree cache, there can be allocations the first time a > register is accessed. This can cause an attempt to schedule while > atomic in the case that the regmap is using a spinlock. This could be > fixed by either initializing all the registers or using a flat cache. > The register maps for tegra30_ahub and tegra30_i2s are dense and don't > save much from using a tree so convert them to flat. > > Signed-off-by: Dylan Reid Looking through regmap code, the fast_io lock seems broken in more places, not only via rbtree cache access. regmap_bulk_write() calls kmemdup() with GFP_KERNEL in the lock context. Ditto in regmap_register_patch(), which calls krealloc() with GFP_KERNEL. The former could be fixed by moving the lock like below. The fix for the latter depends on whether we need to protect map->patch_regs growth from races or not. If not, krealloc() can be moved out of the lock. Takashi diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 4b2ed0c9e80d..2a1d43e23f1f 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);