From patchwork Sat Oct 22 07:23:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7385 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1096730wrr; Sat, 22 Oct 2022 01:05:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6beMk22tpbbxizbRdqKFZwqAiUxh9xX9dOa/pnVNKU15xr4dKaZYrMQ0TrCGLmIIr4Yk7b X-Received: by 2002:a63:e755:0:b0:46e:c2ac:5fd1 with SMTP id j21-20020a63e755000000b0046ec2ac5fd1mr4836920pgk.184.1666425949554; Sat, 22 Oct 2022 01:05:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425949; cv=none; d=google.com; s=arc-20160816; b=Gubmpp8EXP0JP9JcHtpR8Fw+wCq6UD25dXLYdiwHhe7UYx6Dbw7PBhaDxszNMyPU1f MqoHHrf3ms93W2N69imjCMFVjouiigcRxS9PCsIzSX5UbfKqbaLhoxHHwzaaIZD3XVtc TSgsyjQOQNkTF7709oiCzTYnVmKQrZIqxGupxVGLtkbz9BozY0xVad8vE0XceTY+N1WB ysMaB1e1xpXb2BP1PFM07NYY+U+iQkxWVQr3P0yOCNV1XKNGFl2DFb34kMey/xRJKCHX x6pNBMn+MR1UZTTTI3zMs9X90R7RDZFtHsyv+p+hviC+xgLwsD4/RbZjnREfzIo70/WD ffoA== 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=s4aS4XaRu1bhUNVY0OLHl+T+zWzBYN5ZpMtqv8Lm1sM=; b=m0jVI9u9pY+yXNTkM3aBygflPYOdgX6dFAvBVzwXgjaKm7L8CILO/zzPKsHIONy1iv LT13pi/vrHdt2HZALU2e26oDfOsLyAUA10xrYgye4RSZFPKvV0X3AFjhmf+DwwHLNNzE fsBAgRjWiCc43GBqMFeAzb8IzLjWTZfp+u3QAprYpA7W8z9QreU4rdOTlvn+TWln4MVq mj2DN7hxQy/xSdE/c2TIR0biVMCFy0tJgOxjIGwpNDi968r0I65ChCIjzV1Ir0W1YzXf 6Frixtns7ntj8rmt601odgniyqD6MuupA2LEDlrjVcw927+DW250bXhYPj+4JPc1HHgK BXNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=14OMXf4U; 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 r3-20020a632043000000b00438894246e8si27225392pgm.169.2022.10.22.01.05.33; Sat, 22 Oct 2022 01:05:49 -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=14OMXf4U; 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 S232993AbiJVIEf (ORCPT + 99 others); Sat, 22 Oct 2022 04:04:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232475AbiJVH7D (ORCPT ); Sat, 22 Oct 2022 03:59:03 -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 F1540B71; Sat, 22 Oct 2022 00:49:19 -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 EEF7CB82E0C; Sat, 22 Oct 2022 07:49:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D172C433D6; Sat, 22 Oct 2022 07:49:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424952; bh=D3pgGgzO7UPi97hX7mChXw0CmsUbUFVWqqVAoDheCr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=14OMXf4UGaoWZeWCMxtf+5GCLD8X2djExB5J8PR7c2b8b2VHS8pipgJAOthlSqqnY //E8MGnqt1QPTqJOA7S0XyJNWJkAk5cZ5pSL0bCjaSAVfUofRUmhXOfpwhnpYRHVvi /qdVN7pGZejBN0SD20uIu99a2QInxZEbVKQPGfMA= 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.19 338/717] ALSA: dmaengine: increment buffer pointer atomically Date: Sat, 22 Oct 2022 09:23:37 +0200 Message-Id: <20221022072510.288484702@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747374256453425255?= X-GMAIL-MSGID: =?utf-8?q?1747374256453425255?= 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 af6f717e1e7e..c6ccb75036ae 100644 --- a/sound/core/pcm_dmaengine.c +++ b/sound/core/pcm_dmaengine.c @@ -131,12 +131,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); }