From patchwork Fri Jan 16 17:16:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 5649661 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 65F83C058D for ; Fri, 16 Jan 2015 17:18:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 88F262034C for ; Fri, 16 Jan 2015 17:18:28 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 63EFC2010F for ; Fri, 16 Jan 2015 17:18:27 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 9EFDA265750; Fri, 16 Jan 2015 18:18:19 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 6F9B5260632; Fri, 16 Jan 2015 18:16:59 +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 AB84226041B; Fri, 16 Jan 2015 18:16:55 +0100 (CET) Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 04993260427 for ; Fri, 16 Jan 2015 18:16:47 +0100 (CET) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D1D0AADAB; Fri, 16 Jan 2015 17:16:46 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Date: Fri, 16 Jan 2015 18:16:43 +0100 Message-Id: <1421428603-6739-5-git-send-email-tiwai@suse.de> X-Mailer: git-send-email 2.2.1 In-Reply-To: <1421428603-6739-1-git-send-email-tiwai@suse.de> References: <1421428603-6739-1-git-send-email-tiwai@suse.de> Cc: Pavel Hofman Subject: [alsa-devel] [PATCH 4/4] ALSA: ak411x: Fix race of reinit() calls 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 Protect the call with a mutex, as this may be called in parallel (either from the PCM rate change and the clock change). Signed-off-by: Takashi Iwai --- include/sound/ak4113.h | 1 + include/sound/ak4114.h | 1 + sound/i2c/other/ak4113.c | 3 +++ sound/i2c/other/ak4114.c | 3 +++ 4 files changed, 8 insertions(+) diff --git a/include/sound/ak4113.h b/include/sound/ak4113.h index f4fbf6888e78..58c145620c3c 100644 --- a/include/sound/ak4113.h +++ b/include/sound/ak4113.h @@ -287,6 +287,7 @@ struct ak4113 { ak4113_read_t *read; void *private_data; atomic_t wq_processing; + struct mutex reinit_mutex; spinlock_t lock; unsigned char regmap[AK4113_WRITABLE_REGS]; struct snd_kcontrol *kctls[AK4113_CONTROLS]; diff --git a/include/sound/ak4114.h b/include/sound/ak4114.h index e681df2c95e1..b6feb7e225f2 100644 --- a/include/sound/ak4114.h +++ b/include/sound/ak4114.h @@ -169,6 +169,7 @@ struct ak4114 { ak4114_read_t * read; void * private_data; atomic_t wq_processing; + struct mutex reinit_mutex; spinlock_t lock; unsigned char regmap[6]; unsigned char txcsb[5]; diff --git a/sound/i2c/other/ak4113.c b/sound/i2c/other/ak4113.c index c2b14d981fa1..88844881cbff 100644 --- a/sound/i2c/other/ak4113.c +++ b/sound/i2c/other/ak4113.c @@ -89,6 +89,7 @@ int snd_ak4113_create(struct snd_card *card, ak4113_read_t *read, chip->private_data = private_data; INIT_DELAYED_WORK(&chip->work, ak4113_stats); atomic_set(&chip->wq_processing, 0); + mutex_init(&chip->reinit_mutex); for (reg = 0; reg < AK4113_WRITABLE_REGS ; reg++) chip->regmap[reg] = pgm[reg]; @@ -141,7 +142,9 @@ void snd_ak4113_reinit(struct ak4113 *chip) { if (atomic_inc_return(&chip->wq_processing) == 1) cancel_delayed_work_sync(&chip->work); + mutex_lock(&chip->reinit_mutex); ak4113_init_regs(chip); + mutex_unlock(&chip->reinit_mutex); /* bring up statistics / event queing */ if (atomic_dec_and_test(&chip->wq_processing)) schedule_delayed_work(&chip->work, HZ / 10); diff --git a/sound/i2c/other/ak4114.c b/sound/i2c/other/ak4114.c index ee639f57b664..5a4cf3fab4ae 100644 --- a/sound/i2c/other/ak4114.c +++ b/sound/i2c/other/ak4114.c @@ -100,6 +100,7 @@ int snd_ak4114_create(struct snd_card *card, chip->private_data = private_data; INIT_DELAYED_WORK(&chip->work, ak4114_stats); atomic_set(&chip->wq_processing, 0); + mutex_init(&chip->reinit_mutex); for (reg = 0; reg < 6; reg++) chip->regmap[reg] = pgm[reg]; @@ -156,7 +157,9 @@ void snd_ak4114_reinit(struct ak4114 *chip) { if (atomic_inc_return(&chip->wq_processing) == 1) cancel_delayed_work_sync(&chip->work); + mutex_lock(&chip->reinit_mutex); ak4114_init_regs(chip); + mutex_unlock(&chip->reinit_mutex); /* bring up statistics / event queing */ if (atomic_dec_and_test(&chip->wq_processing)) schedule_delayed_work(&chip->work, HZ / 10);