Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7152521rwi; Mon, 24 Oct 2022 10:27:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4yubN5rKvJ/oTEBBBG1vPLbs4XiUQzEW2+VbvAkAl2PjZwQ4FhvXO3F4ycScrwDD4DAzkR X-Received: by 2002:a17:903:40cd:b0:186:8869:739c with SMTP id t13-20020a17090340cd00b001868869739cmr14400003pld.97.1666632422764; Mon, 24 Oct 2022 10:27:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666632422; cv=none; d=google.com; s=arc-20160816; b=yut+qc3HpTPdnn+bipAKPlg+CiIwOV20o+bf11767s7NHKB3RPFePI7bh1vO5JlV3v P0dlhhN1lN9C/QOyQ1epZGmODCUDpJNmUB8Qg1+vYAoHRCAbmwmlb91Xnkaq8WH26/bv Hobx+f4sgzc3E5UX8wavVr4Q7FzLL5fIr3czn4IlPfLG7oUsjjdP6g/WBtlN3uIbOmLx ALVv+d/xAvTseRpgz5nK90vJS5WtszMWm19FAXMR2RClNfLKBv3ZnefzBjpMFsVYs2zd 349ACcoHb9QZDKAfdkzyvMNgtuIeFGMEDhbmrSD+zUnghcYVVDnzpggkL0Iaa9Ddf1R8 aT4Q== 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=jhClmv/4OFgRakic9tvTLB6c0xJfsOQdZuerEksrzJw=; b=NmbLWCstrOwbmHgpMnpZZalDRtSGBUFuqOzxjcIrorJdkI1AK7TeZ+0Gbdzzj1LEos 2LB1lPqO5vTXbgGx8hPR0TpCG3jWVqEvJ8skyQqz2V8RPDCOH4D6Ty7Dya2serpOM0QM W2G7TxOcf8tLSS+mf80EXaxXiUn/Q2c5lp6qBfpEvjuLu9LJf7HqJnRa2OWTSblQ8HUG VBi8qV6OB2eoQKiRmDSlHN+UrOjdPDA3j+vXhXRvdub/XnDR6ozXlVSJMBcTOFIX+NSH 7Yj/r1RRsBvHoalL/N63s0AM2+jYoXecJZbWJbFqHwjMWp9qalMpamWYQfLYEvYlTg2X 44RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TH8i8gCU; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pj11-20020a17090b4f4b00b0020d542eb5f0si11812892pjb.110.2022.10.24.10.26.50; Mon, 24 Oct 2022 10:27:02 -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=TH8i8gCU; 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 S233813AbiJXROm (ORCPT + 99 others); Mon, 24 Oct 2022 13:14:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231697AbiJXRNa (ORCPT ); Mon, 24 Oct 2022 13:13:30 -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 E88405A8C8; Mon, 24 Oct 2022 08:49:05 -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 9578D6129A; Mon, 24 Oct 2022 11:59:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A479BC433C1; Mon, 24 Oct 2022 11:59:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612746; bh=bZwGPZDTogpLUxzxQ5yHMwfGBVlcNdR2myoMTG7FLZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TH8i8gCU3hrYEcz6rEEgo865pgk7d1YaUVyJ5TvXUFMcwzOjWLkvTNVJauDLlGC79 cGUGjcb2mcs83nPB8fVmOXouRnWUB2RYRjzNOCdBUplqqbHUlSunwkmm0CBg8z+w5P KyxFiXcOSlZhoR1EvKA+nlALyImmBJhkIkBLNgXQ= 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 4.19 103/229] ALSA: dmaengine: increment buffer pointer atomically Date: Mon, 24 Oct 2022 13:30:22 +0200 Message-Id: <20221024113002.353044201@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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 8eb58c709b14..6f6da1128edc 100644 --- a/sound/core/pcm_dmaengine.c +++ b/sound/core/pcm_dmaengine.c @@ -139,12 +139,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); } -- 2.35.1