From patchwork Mon Oct 24 11:30:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10162 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp640198wru; Mon, 24 Oct 2022 13:31:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5XHFAjq0IkUvN6HsbiOJ9pz7Q5LpE+2ebajzxVrEItbR9eXs5ZJSP6tADXHIBEJrg250ob X-Received: by 2002:a63:5a08:0:b0:43c:9fcc:cc54 with SMTP id o8-20020a635a08000000b0043c9fcccc54mr29422015pgb.229.1666643519009; Mon, 24 Oct 2022 13:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666643519; cv=none; d=google.com; s=arc-20160816; b=ZIWYbTwQ9tEtg+hUyR2+qIzqNwvVnGvCpgdMQ6GAhJ12Bb68cv5Pvsf/FPcADDagpz ihdBiGOgQk0FQl4fVB11usXOw0YUQLz5mc1uetBB5DvebkXmKUnD3T8cWrVQ69HLwAra 08QZcx0hMxNopQbK/HoU4eGFzdwztopzwwtEjQtg0OA62X7Do7EG+l874y7DIMfkuGfr iWsxIyBbF8aTtHh7tsyV8vuIzEZlCfsGF3rJAjArUBPcjJDVuLJVAfprT66quw1GOziU VrT+h94w2ZGskl7SOW56QZgKJqOV9GFppYMerDlZBa5/q9KrtFQjB48SHpao8iuLr9WP 05GA== 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=IPyrfujMdNPsHMq0pdgkV781o95MtUKL7tRYO3GeQ8o=; b=X6i9ypVFbOmht7rsvj8Zw+Q7QXqH8n4E9Wbs0uGct/Wvb5JB3Jrc5tHtpHuC4HeDpe JVOTtcKuZt9q+jzjt/I/RJrZqPUSckTGg6qWM+InOQQGIB5LnjmuCEd++Jq3XO9Pjl0V edvzhseUxvU3ehEXUNyjYjvmY7v4xq0tk7EsNwf+fKydBvhM3s/hYawO96jytd+WH/P8 A9MqoGDgbNL5xkRKEL81pfTikjeqm4E2Phl6KWEXW9kCDekbfmhpwT0MYeODrpVGeqaQ WP4eYccQu/gMCQusRKTJkHFiZ+hj1D7gz2Q5CjJDg3dMflgO1QB1Lu1l5gMKPgjPqCvU nWRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cDPJkvEo; 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 c34-20020a631c22000000b0045e96393e37si567361pgc.20.2022.10.24.13.31.46; Mon, 24 Oct 2022 13:31:58 -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=cDPJkvEo; 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 S231791AbiJXUV6 (ORCPT + 99 others); Mon, 24 Oct 2022 16:21:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229798AbiJXUVM (ORCPT ); Mon, 24 Oct 2022 16:21:12 -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 E14CA186D78; Mon, 24 Oct 2022 11:37:44 -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 B3599B81269; Mon, 24 Oct 2022 12:09:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16A3CC433D6; Mon, 24 Oct 2022 12:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613345; bh=PKw48NvRM6Pv0obQueP1baQfXMf9H18bxdys05abGAI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cDPJkvEoVf5VVGFSVChPWwcUa6F5K2RTuWFWgCXITjrxsQm52HkplZQSOrUDT1z75 8EIKvFmXZ2F0Z40J4iwzyfQj889pn8PeNKiD6FJlGa+DsB67Rwki+I9V1uuSQYYz2H 1r2DkYphgddakRQ729o5EZ8RDJlYZWDR6rkFlraA= 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.4 102/255] ALSA: dmaengine: increment buffer pointer atomically Date: Mon, 24 Oct 2022 13:30:12 +0200 Message-Id: <20221024113005.863585249@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@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?1747602395012026038?= X-GMAIL-MSGID: =?utf-8?q?1747602395012026038?= 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 89a05926ac73..5d9a24ca6f3e 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); }