From patchwork Tue Jun 16 13:17:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Hills X-Patchwork-Id: 11607449 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 32F9E92A for ; Tue, 16 Jun 2020 13:20:29 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B3474206F1 for ; Tue, 16 Jun 2020 13:20:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="GOCKeuXZ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=pogo.org.uk header.i=@pogo.org.uk header.b="af2K7HUp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B3474206F1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xwax.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 49A33168F; Tue, 16 Jun 2020 15:19:38 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 49A33168F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1592313627; bh=p6CLRRTeE3NqCtcDJDQce9Dz3mL1mUPlWt+8pdO3qGw=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=GOCKeuXZvcTy7vyQjX/xQQo3uKbhCWRZgtGti8WvYKRPr+FsPO+Qkuydg0xOUCAo+ GlnrjpelGpp1r3nj7TZyV+l6Ke7ITBmytIw85+jzahGHBaihlnbeWb1W6GMxG1X99l 7WDHTgGoBATSGkHS0t7R2lx/ciPGD5H0P5Ts1mlg= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 05A10F802BC; Tue, 16 Jun 2020 15:17:58 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 30BD7F802A2; Tue, 16 Jun 2020 15:17:56 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from jazz.pogo.org.uk (jazz.pogo.org.uk [213.138.114.167]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id D2901F80101 for ; Tue, 16 Jun 2020 15:17:43 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D2901F80101 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=pogo.org.uk header.i=@pogo.org.uk header.b="af2K7HUp" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=pogo.org.uk ; s=a; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender: Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=uk6p04jIyGEwhPstJTRrV0yyBWZrc9m+PRsuhl4h6bI=; b=af2K7HUpdTMT+kcPuBZ1JBnN/1 M3PLXr0arbtOX9P8ITTe9p8O/wrv6KKTQy4Z47J3Koa0FQkgnep2Yk8RgdYKg0eegvu7eYQ9EYY2A /9m3QtWcs/smNEDg9RAEmUbwEOBnbXRvCw8TFGgSbpylnmkVAccvtUJ/8ZoMoVB0stIKt5P4QF9RP i1T9MWdPwGzceRHvH5j+YH9mj/Oqlt7k4svqD/pffjdqRxErCu3riNFrIWgy2zdhjylhG2MsEcNJR sdFRZptTh6CnC+FoffbxZLPNyTMgSOgLgE2Otg5m5xFjX5K3K/mkXj7MIvztdr9eqlk8DZF3T7H2/ DRwbau4A==; Received: from cpc1-hari17-2-0-cust102.20-2.cable.virginm.net ([86.18.4.103] helo=stax.localdomain) by jazz.pogo.org.uk with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93.0.4 (FreeBSD)) (envelope-from ) id 1jlBTD-000MY3-9A; Tue, 16 Jun 2020 14:17:43 +0100 Received: from mark by stax.localdomain with local (Exim 4.84) (envelope-from ) id 1jlBTD-0001G1-1n; Tue, 16 Jun 2020 14:17:43 +0100 From: Mark Hills To: Takashi Iwai Subject: [PATCH 2/3] echoaudio: Prevent races in calls to set_audio_format() Date: Tue, 16 Jun 2020 14:17:42 +0100 Message-Id: <20200616131743.4793-2-mark@xwax.org> X-Mailer: git-send-email 2.17.5 In-Reply-To: <2006161409060.30751@stax.localdomain> References: <2006161409060.30751@stax.localdomain> Cc: alsa-devel@alsa-project.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" The function uses chip->comm_page which needs locking against other use at the same time. Signed-off-by: Mark Hills --- sound/pci/echoaudio/echoaudio.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c index 82a49dfd2384..8cf08988959f 100644 --- a/sound/pci/echoaudio/echoaudio.c +++ b/sound/pci/echoaudio/echoaudio.c @@ -711,9 +711,22 @@ static int pcm_prepare(struct snd_pcm_substream *substream) if (snd_BUG_ON(pipe_index >= px_num(chip))) return -EINVAL; - if (snd_BUG_ON(!is_pipe_allocated(chip, pipe_index))) + + /* + * We passed checks we can do independently; now take + * exclusive control + */ + + spin_lock(&chip->lock); + + if (snd_BUG_ON(!is_pipe_allocated(chip, pipe_index))) { + spin_unlock(&chip->lock); return -EINVAL; + } + set_audio_format(chip, pipe_index, &format); + spin_unlock(&chip->lock); + return 0; }