Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1145487pxv; Fri, 9 Jul 2021 19:27:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRWtRRlomDrXDPWWfPhQf7cdmufESuinJ0JNVT6/wdVeC0LR3o2g03KZ1nMQrcCI9wC3gO X-Received: by 2002:a05:6402:692:: with SMTP id f18mr28959698edy.327.1625884056426; Fri, 09 Jul 2021 19:27:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625884056; cv=none; d=google.com; s=arc-20160816; b=bsBVpU8vfpHqsCSGjvVNo4sH/Qp1XfrexdNVZZNlN/liaKWOE9206syCSMVnGYPCqz h+Nw7tADHxovRs3MHHFEdkmwAr1Ijh3RUA3qJlHXlbJg8G6nl+lWP2/GBeDKKjB6S1DT 41reCo0oSjTKxzy/av/BnwHixyQqACPJKUEw4/mTxAJ/3zOnVCjmhBok186FqxrSPG7i biZscDbL8mCjtg7q8Xut2TbBq9LHI4NMnEfHAfTsIp9y1cFBDx12LH/IRLhBgAK6wD8g 36lAl9hJLEZsq35H4dcH2wWdHiuw5t99VBrXWYMVrMQlzFddlxJKyQh0LuVmDmPB2uG3 dOHw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vu6rfXsRUH3JzhLcQYHEdtvWb8yTiiRpYcAL2AClRp4=; b=z3hrJD1xzKqg6JFTYRRuTwMpQRo5jnViyPmemjSxg8lUeHNO2gOnsTCH4IVyrKMZ06 FHf1PqRoO0NBgyM16Q6ySh3OEdkyYh7PzUZoihBWFSzwErsVlUCUSLnB5p2KQW6jPTXQ oDNpnlKMo+z++siTbC28II52pe9krFn9KFR+Snyg3K37itBDO9zorkmid/hew+Ak9A1y dxsupFM3+s+vFWcTBYTZyedAHwv/X4VwRDoe4P6VSwo963cZ/8zLEBZg/QFGF7sX5Dwu MJ3mUZEn80CFo7RLwHsAsgucCqLVTf6TKqzP7Zp9fobrCAuE8aGF7a3KSz4e1FegrIEI Hnjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q0J3QzKH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o12si8571849edc.382.2021.07.09.19.27.13; Fri, 09 Jul 2021 19:27:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q0J3QzKH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233003AbhGJC21 (ORCPT + 99 others); Fri, 9 Jul 2021 22:28:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:42974 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233460AbhGJC0u (ORCPT ); Fri, 9 Jul 2021 22:26:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0D8B3613E1; Sat, 10 Jul 2021 02:23:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883840; bh=nMSZoav4agHLXnYG/VNUjwfYIqAo8oXevKEPMS4VySs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q0J3QzKHihS4PVzG1FJb47JQtKF/NOi7qQzea6D6ivI0x7sgiUH9QWKqWB49R/QIW GzX3Lt3VRNrNgTGFQxPegfUbftC/t0Fy3tjIP+kWN1OWdMWYEKcI8SE3WNPFhX1Rc9 nr0CbQG43GeA2Bqrl48g72KmyZk3EDIq3H8b+otDDkh7o86mmyNEtmDXBh+JgjMIcq 4JUhK06l+XX0dS9ATlRIfLyNsHaqwY5j2aLxeyIK8Y8slEmkanrv25O8Q2ImAxv/18 7g7QD0MDGkKHt5eqeOlkqvqSzWQG+uS0H2uM3361DZH8hu9Atl33EUO+1oauWIhSUy VKiKMjW47AHQg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Geoffrey D. Bennett" , Takashi Iwai , Sasha Levin , alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 5.12 086/104] ALSA: usb-audio: scarlett2: Fix data_mutex lock Date: Fri, 9 Jul 2021 22:21:38 -0400 Message-Id: <20210710022156.3168825-86-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710022156.3168825-1-sashal@kernel.org> References: <20210710022156.3168825-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Geoffrey D. Bennett" [ Upstream commit 9b5ddea9ce5a68d7d2bedcb69901ac2a86c96c7b ] The private->vol_updated flag was being checked outside of the mutex_lock/unlock() of private->data_mutex leading to the volume data being fetched twice from the device unnecessarily or old volume data being returned. Update scarlett2_*_ctl_get() and include the private->vol_updated flag check inside the critical region. Signed-off-by: Geoffrey D. Bennett Link: https://lore.kernel.org/r/20210620164643.GA9216@m.b4.vu Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/usb/mixer_scarlett_gen2.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/sound/usb/mixer_scarlett_gen2.c b/sound/usb/mixer_scarlett_gen2.c index b2fa317ba2ab..63d6a5e45ba9 100644 --- a/sound/usb/mixer_scarlett_gen2.c +++ b/sound/usb/mixer_scarlett_gen2.c @@ -1028,11 +1028,10 @@ static int scarlett2_master_volume_ctl_get(struct snd_kcontrol *kctl, struct usb_mixer_interface *mixer = elem->head.mixer; struct scarlett2_mixer_data *private = mixer->private_data; - if (private->vol_updated) { - mutex_lock(&private->data_mutex); + mutex_lock(&private->data_mutex); + if (private->vol_updated) scarlett2_update_volumes(mixer); - mutex_unlock(&private->data_mutex); - } + mutex_unlock(&private->data_mutex); ucontrol->value.integer.value[0] = private->master_vol; return 0; @@ -1046,11 +1045,10 @@ static int scarlett2_volume_ctl_get(struct snd_kcontrol *kctl, struct scarlett2_mixer_data *private = mixer->private_data; int index = elem->control; - if (private->vol_updated) { - mutex_lock(&private->data_mutex); + mutex_lock(&private->data_mutex); + if (private->vol_updated) scarlett2_update_volumes(mixer); - mutex_unlock(&private->data_mutex); - } + mutex_unlock(&private->data_mutex); ucontrol->value.integer.value[0] = private->vol[index]; return 0; @@ -1314,11 +1312,10 @@ static int scarlett2_button_ctl_get(struct snd_kcontrol *kctl, struct usb_mixer_interface *mixer = elem->head.mixer; struct scarlett2_mixer_data *private = mixer->private_data; - if (private->vol_updated) { - mutex_lock(&private->data_mutex); + mutex_lock(&private->data_mutex); + if (private->vol_updated) scarlett2_update_volumes(mixer); - mutex_unlock(&private->data_mutex); - } + mutex_unlock(&private->data_mutex); ucontrol->value.enumerated.item[0] = private->buttons[elem->control]; return 0; -- 2.30.2