From patchwork Wed Oct 19 08:28:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5519 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp337077wrs; Wed, 19 Oct 2022 06:48:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7k03WHbn2GSRqfcQtMM8as//LIAd7MKx3O6S6UhmC2CQUTCxlbXO3Jza2t8ycpzd9NVpbc X-Received: by 2002:a63:8a42:0:b0:45f:f0f0:148f with SMTP id y63-20020a638a42000000b0045ff0f0148fmr7487458pgd.93.1666187306290; Wed, 19 Oct 2022 06:48:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666187306; cv=none; d=google.com; s=arc-20160816; b=NER9CsrfJGwTA1UuAaoU8mrWptgqCBLzaJyZ7aFnFnevJ6w5JMm9yGrx8hoRdONff6 W1jOtDQjfuNjQqUhbHU/M43tsjIDO4YkK8Vn/8EmXXKjCPEMpP04tNXJUkeZVDMGSyr3 XnheyLsev8JgO8lQwrb70HtYQGtsAhjt93GIvxVC79D/ClVteqljRatFpBrhJEvLbjbr sRilM8aZqB6+1aBJds/V+W5dKG1+vzbv1UEgaJglawmMRWan5ZC0FV/vLdiU3B+obaHQ JOu5CN2I5EjSaj3QwoSjFinHr8eg2o9bBdCfN9a6DZ5K3lReG2t0L5LKuFpBYer0A5Lv BiFg== 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=YMkMpSpySSxc43BYa6DFfK55cI67/0AlyjA3EPWY6O0=; b=UKeV8Tnoxa2bvKpqCrb2WGlgoQuKxe+98m/kxxp3pSVwu1IZpJnBchfXvmQswkyptS +rHVoR9ptxuiAoU/jRi8NUU7xGUK+dLJWEmvlaD5T7zk8LQsbr/SbCpshROb5qQYlJt6 k7yqGT6RicoFu7LLyqrjIM+yCbceW5kIKNkunY8t2ZKIvESoGqQtduANxSsqiClKre8C DPQrSsjGawspAF3LRtzCZE5hD+vjHnUO4ed0OzaA9bv636RytCxSkLqEuYfAFHWlWTwz hc8wAtByzVDGy6qE9f+A8HuFgzi1waX0g7qC7pFer8r/0RDfPUenKwRH1ziKhuo9HsDb j8Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TnG5ABJn; 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 u8-20020a654c08000000b0043c9d3b9c83si18695196pgq.140.2022.10.19.06.48.12; Wed, 19 Oct 2022 06:48:26 -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=TnG5ABJn; 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 S233553AbiJSNrr (ORCPT + 99 others); Wed, 19 Oct 2022 09:47:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233038AbiJSNqT (ORCPT ); Wed, 19 Oct 2022 09:46:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B1341C8D5F; Wed, 19 Oct 2022 06:32:00 -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 ams.source.kernel.org (Postfix) with ESMTPS id 84954B8238E; Wed, 19 Oct 2022 08:56:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6613C433C1; Wed, 19 Oct 2022 08:56:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169774; bh=auWKAyOEcstI5M0Up/N11Wg8er7p4yNk4AWhb3Gv2v4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TnG5ABJnUqeT0HZMIFowigIm/rbydeqM1wHl7SFcZjppex9hDPgpvKqPqDzJJDupB fjgyueYdP8YyCZr6806z2vHd14F3jEYLtRkmrfzm1tuyMDnlSwLub9jZ1+BkduTmnR EpHrHFD2v3xd4qzPNuN3Lf9Ss/nQY1cAo+4L3Su4= 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 6.0 403/862] ALSA: dmaengine: increment buffer pointer atomically Date: Wed, 19 Oct 2022 10:28:10 +0200 Message-Id: <20221019083307.739428529@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747124020893987408?= X-GMAIL-MSGID: =?utf-8?q?1747124020893987408?= 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 5b2ca028f5aa..494ec0c207fa 100644 --- a/sound/core/pcm_dmaengine.c +++ b/sound/core/pcm_dmaengine.c @@ -133,12 +133,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); }