From patchwork Mon Oct 24 11:29:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9262 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp462223wru; Mon, 24 Oct 2022 06:45:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5XX6pDU6CXCTsz8xYAuGRKX7v2gaSJnYv1dobUcUUm5ZPKpCbhb5wgFDJwAVkTnLmhmaZO X-Received: by 2002:a17:906:9b8b:b0:78d:8276:ff47 with SMTP id dd11-20020a1709069b8b00b0078d8276ff47mr27989252ejc.430.1666619134330; Mon, 24 Oct 2022 06:45:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666619134; cv=none; d=google.com; s=arc-20160816; b=aV51O7l0GidfYtsBLW1nbnuxS9iCwk28XGP1N/SJ40s0M5AgXJrZlR3LtwDyjiULg/ U8A+R7xYdJqFbOUcePuYU9wPShNjN9aMVmApJtt4XPXWdjB/rNn27YezxcebUjU6Zbvj lm5xlPVKhbJqd7pfImcHsRyvvdvJh2lRmdkhUUZTHyZUsRnSfT1VXHatZ+zdFSVKfDro iPOuKybgDtvkoTtRwvqU/BX5hfGlejpqZ8ieHGzW4GI0y+zrZCDTp7ZsfGtkk/FrnP3g TAMtIpl197hw4juHsin7i+oZ8gwOSqkNKSr116vq0g1zpsgV1R5GFA8ZRX8qvy6H77DV t23A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UqAIdn87Ujh8usUPNpV4HRvmKA8nMXeLBTNSykKk0Bw=; b=rlQM2FwHKIw35sPXkTMf7oqxehCeoqZZzMFLdLn+7FnEMwXmfzt3pS4D4IE1VRHHm5 Dw4ObDPIlE2YXoIV3uU/SFvovoRYSbuel9YK96/gYxD4AlkUhVYnp7wscksdA4MiIXhB sqWxkhHdcyc8GG3vuqFVLtKfGh40nybeqFM1ZmW/Ps+3f5DSLCAL41p/ucRGjEFoamMA FWaTEr7YZA9+0s/g0PQ4Sqs8v3UFihS0t2ML1ZpDAc4KRBUqO24ShlWOTqu7UbEsE9yL 6si4lULcv1W7QYD1QrhSp1nGfwGspt0m/MymGHM55XZ0F/oMNS3PqqxDt9OglMPBYmfe yd4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2YFp3Mi0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l15-20020a170906794f00b0078333d9f17bsi30556239ejo.819.2022.10.24.06.45.10; Mon, 24 Oct 2022 06:45:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2YFp3Mi0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236080AbiJXNhz (ORCPT + 99 others); Mon, 24 Oct 2022 09:37:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233541AbiJXNdi (ORCPT ); Mon, 24 Oct 2022 09:33:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EEC1209A6; Mon, 24 Oct 2022 05:34:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B51BD612BB; Mon, 24 Oct 2022 12:23:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0B8AC433C1; Mon, 24 Oct 2022 12:23:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614182; bh=oei25bppX7opojlLxFImrhg7rgEMZXfr7N6+E7cS4gc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2YFp3Mi064UJA5WDeV7Jv224y+a5llOy7Mf2heA991TD8i6ZEiDx8F1gTO+dTnqVS YcxTP4jjugZd2q4g2N6/3AcKnURfb4jlJgz40FcON8Vmz3wyMv9r8IP2hwTly4m9p+ WpLuMz7ykoz9NXm6UI9wOmPfB8JK7xTCw/rUP8tM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andreas Pape , Eugeniu Rosca , Takashi Iwai , Sasha Levin Subject: [PATCH 5.10 164/390] ALSA: dmaengine: increment buffer pointer atomically Date: Mon, 24 Oct 2022 13:29:21 +0200 Message-Id: <20221024113029.693302618@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747576825148411357?= X-GMAIL-MSGID: =?utf-8?q?1747576825148411357?= From: Andreas Pape [ Upstream commit d1c442019594692c64a70a86ad88eb5b6db92216 ] Setting pointer and afterwards checking for wraparound leads to the possibility of returning the inconsistent pointer position. This patch increments buffer pointer atomically to avoid this issue. Fixes: e7f73a1613567a ("ASoC: Add dmaengine PCM helper functions") Signed-off-by: Andreas Pape Signed-off-by: Eugeniu Rosca Link: https://lore.kernel.org/r/1664211493-11789-1-git-send-email-erosca@de.adit-jv.com Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/core/pcm_dmaengine.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c index 4d0e8fe535a1..be58505889a3 100644 --- a/sound/core/pcm_dmaengine.c +++ b/sound/core/pcm_dmaengine.c @@ -130,12 +130,14 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_set_config_from_dai_data); static void dmaengine_pcm_dma_complete(void *arg) { + unsigned int new_pos; struct snd_pcm_substream *substream = arg; struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); - prtd->pos += snd_pcm_lib_period_bytes(substream); - if (prtd->pos >= snd_pcm_lib_buffer_bytes(substream)) - prtd->pos = 0; + new_pos = prtd->pos + snd_pcm_lib_period_bytes(substream); + if (new_pos >= snd_pcm_lib_buffer_bytes(substream)) + new_pos = 0; + prtd->pos = new_pos; snd_pcm_period_elapsed(substream); }