Received: by 10.223.185.116 with SMTP id b49csp1046503wrg; Fri, 23 Feb 2018 10:57:18 -0800 (PST) X-Google-Smtp-Source: AH8x2245TYLYTmagKJRnpwpC++u31BCL0IjC6GsticcsKQbN64gGRrNsSiooSdgAcsipYBWlTCGM X-Received: by 10.98.135.76 with SMTP id i73mr2706950pfe.140.1519412238163; Fri, 23 Feb 2018 10:57:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519412238; cv=none; d=google.com; s=arc-20160816; b=FlUryHOgIJmf8Y1O///EUfIALlO2uEBzYAE8buDB1aQtmc+knGJEkTrMjsOrEjS3P/ Hidbl1dF1fs5FAN5Y0+ZOSUWQKGmGS58Ube74L4b7H6XSsOz348FO9uFeMr/G4J/Ly+4 bp475L34D/4JGVlQM1ZL5ncEtmE5SxX3EpUBgx2eCpAxmJsJQMLUUUUKSCeO2OuH57o4 BGt9DZmPggUph78B1ErUhJqNWbJbbYAXyvKMVm4WUkbR7XZBjAeyrl4TMNsLZKZ40szT rxfbvY9HfnSFaIIAO5GAdYyWwOrSmmp6+WRZlW6KxukkwwBPbnoEqkja6bQgJXZxwl3M inVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=+lSSeiGboGBGy7+nvLD7oEGyc/Izjtvgu1ocfOVBKRQ=; b=FbVTcydGrDnHjJ0+5kSZT1Aza0DMIHyUej4Q98Ry/OJ9AMLoW2OZQAg/C/BFMANgeX m3NcaaRMtRGgQ/dRHLCJ47c2yQI6rlqj2kcyQMubLcGmEAqWYNAQIXZzexLBvtMUdbrm er0CMsQKcOxhkAuXe5wLb/EatWd1cmvXy+AyYlQZ0CnWJHuvet4F9Hi5KjbopjwjiR6d UdCky6y1fEdIhF9E82oon0mfo2iCzk8K2F962AEZCKYriZIo+bgelxA5fC0MaohMjeuu YyXkDl/ndD3yC4cZfeWCH1+cf+VnLa0Z9vTnvOp7tkI8y2Pk5MUIEyVwWlDfWbJ2crUp GE+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q5si2193306pff.398.2018.02.23.10.57.03; Fri, 23 Feb 2018 10:57:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965202AbeBWSzz (ORCPT + 99 others); Fri, 23 Feb 2018 13:55:55 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:48416 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964958AbeBWSzw (ORCPT ); Fri, 23 Feb 2018 13:55:52 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 739321225; Fri, 23 Feb 2018 18:55:51 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiada Wang , Takashi Sakamoto , Kuninori Morimoto , Mark Brown , Sasha Levin Subject: [PATCH 4.14 142/159] ASoC: rsnd: ssi: fix race condition in rsnd_ssi_pointer_update Date: Fri, 23 Feb 2018 19:27:30 +0100 Message-Id: <20180223170800.182800801@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170743.086611315@linuxfoundation.org> References: <20180223170743.086611315@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiada Wang [ Upstream commit 33f801366bdf3f8b67dfe325b84f4051a090d01e ] Currently there is race condition between set of byte_pos and wrap it around when new buffer starts. If .pointer is called in-between it will result in inconsistent pointer position be returned from .pointer callback. This patch increments buffer pointer atomically to avoid this issue. Signed-off-by: Jiada Wang Reviewed-by: Takashi Sakamoto Acked-by: Kuninori Morimoto Signed-off-by: Mark Brown Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- sound/soc/sh/rcar/ssi.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) --- a/sound/soc/sh/rcar/ssi.c +++ b/sound/soc/sh/rcar/ssi.c @@ -449,25 +449,29 @@ static bool rsnd_ssi_pointer_update(stru int byte) { struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); + bool ret = false; + int byte_pos; - ssi->byte_pos += byte; + byte_pos = ssi->byte_pos + byte; - if (ssi->byte_pos >= ssi->next_period_byte) { + if (byte_pos >= ssi->next_period_byte) { struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); ssi->period_pos++; ssi->next_period_byte += ssi->byte_per_period; if (ssi->period_pos >= runtime->periods) { - ssi->byte_pos = 0; + byte_pos = 0; ssi->period_pos = 0; ssi->next_period_byte = ssi->byte_per_period; } - return true; + ret = true; } - return false; + WRITE_ONCE(ssi->byte_pos, byte_pos); + + return ret; } /* @@ -838,7 +842,7 @@ static int rsnd_ssi_pointer(struct rsnd_ struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); - *pointer = bytes_to_frames(runtime, ssi->byte_pos); + *pointer = bytes_to_frames(runtime, READ_ONCE(ssi->byte_pos)); return 0; }