Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp519900lqh; Fri, 31 May 2024 08:17:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXpE06ZXgIGj781qaVX5aT9TJ2hpegainELosS1l+UpO+ZLUn2yr6oYSXqTFn6K3SKhExPjn3owKq6jvGMPc61naqvWcMs8YSTJa7KbQw== X-Google-Smtp-Source: AGHT+IE6ITA8Nt/XcWFFvpmz5LY5q1i2hVD+n7KhnNV0fAFX9tsYJI7+DlJBWzTpgv56l1n2jGy1 X-Received: by 2002:a05:620a:2157:b0:790:6aa4:d068 with SMTP id af79cd13be357-794f5c6e14emr222490785a.15.1717168640081; Fri, 31 May 2024 08:17:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717168640; cv=pass; d=google.com; s=arc-20160816; b=nv/6rbj6URQWsa1SOqW/0KRHaxAWULXMGu8PFid3bLkz9HfdB6BKB45ZnaBlbAeX7Y y0+hUwej0/rTXdpIvfXhJP4TO+Y5cZQVg58jwhTX56KB9/mqsti//bkxYgIo0RzwXAUu o2RIYUB9f46+NTtcoD0SxweSfPAtv7uCLiwNtkMWtpgpzOnUjonkEhJaf4OHvWvNozxc oIM6/VKBRQuAgv9eqEhj0s9vcN9Cvk5cXnU1pnGhomvl/oz1A7HAzMFA3jeciJHj1NGL MVfhHCZ1WJlmHmteW9r5/T8b62S5e5g2aSK4QYAobFsEsxH4WZsZE1D32mcbg5wwVhu4 b7gg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=3QEuMPZ58UQQ/qZnvQF2UXA4/Nl17NjGc0XYDAapMeM=; fh=EelKNb4C4N/Kh+Qnxp5AWU4KZJWkttCqVVez9a39kjc=; b=i7Y5VWUzYwXX0nNiYfnmCOKsV4vrunRzl2n+qGiC8lpJ1pjnYl1W7hOrplAIctTtXb drtTffQYMxU7Nes1KUmedPKAUx+f/32XBRf5eavIppcND8Rjr2KQT8QuYbfkwStPZIhX 4+I6vvd1r11pK+Qg9gH5SZyVfwpxLnYTphODedOYGBRDGiFrViH52GTFJ2w+iFcnyNuq WiWNxGBVSdKECubxIt2eL1muWmi/9jgNHX1r9h8Qr1lbYhKGmkvmtW1+4nwtGp638w6o iK2sVWJJaTWhvHvcNtMBIk5pAS+c4KKWb4wEUfDPJ8hU9Qu1bz2zy7t4CnQT98uFNBij 6ZSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=cFpkplWf; arc=pass (i=1 spf=pass spfdomain=opensource.cirrus.com dkim=pass dkdomain=cirrus.com dmarc=pass fromdomain=opensource.cirrus.com); spf=pass (google.com: domain of linux-kernel+bounces-197058-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197058-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-794f32a7fe6si211719785a.680.2024.05.31.08.17.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 08:17:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197058-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=cFpkplWf; arc=pass (i=1 spf=pass spfdomain=opensource.cirrus.com dkim=pass dkdomain=cirrus.com dmarc=pass fromdomain=opensource.cirrus.com); spf=pass (google.com: domain of linux-kernel+bounces-197058-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197058-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 93A7B1C25BAD for ; Fri, 31 May 2024 15:16:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 37C3A176ABD; Fri, 31 May 2024 15:15:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="cFpkplWf" Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D35FE155C8B; Fri, 31 May 2024 15:15:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.152.168 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717168533; cv=none; b=T9y5kUF8YMptrDIoZB9P418Xb4fGI7MYp4n++VbudPtRvr1zyA5cYxAqkk3OjupCqIKlVDnIFHGp1U7hgVOu6ROZyut4O84u4B5yPys2R//YX673uywT1qmXrGsUVw7PU4IeTaAeqBrTkyqkEbd28A8eNqZ0AYOp9XkUc5K/cHw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717168533; c=relaxed/simple; bh=3gi9ZseK69241gs30CZ/3efH7Ik+gin5YhpjQoFRXKo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RrRwQSgQ/8SjDNLInn2QIZElJOHHySGkSKT3OMw5FPHyKHgOJisoeqQvO88bygtsQxjaucqV7DGvYe+50Gay5puKgXRDZ6QtBaUX4JCLRzUcg6cXTWHYGbwKrP5XC8nrwsijRv2mnhbpgOVsRPrRuC4qdN9EkwT/pqCSWzQl0hk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=opensource.cirrus.com; spf=pass smtp.mailfrom=opensource.cirrus.com; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b=cFpkplWf; arc=none smtp.client-ip=67.231.152.168 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=opensource.cirrus.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=opensource.cirrus.com Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44VB0WSw017940; Fri, 31 May 2024 10:15:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= PODMain02222019; bh=3QEuMPZ58UQQ/qZnvQF2UXA4/Nl17NjGc0XYDAapMeM=; b= cFpkplWfGxOwUz3vnOXcDZGerlktCy8PNK24Bl/mh3PF0Z8vxGAmTtS3PQ3C81L2 PKzk5UJ1hlp2MJuUwVG19lqKDy1Je/cG+Jxyo8pnCwDRxnuzgBCVO4gIeVerQxl9 RbUYr8qcj9KHirOnikEzWk1ZkKmdBve8IeMnvW/ZSFVZHluK7SjX/7iQ6tR6I4BO 1pRn+Y6dGWqPuU2FgAHQiXMhbd+g48pohhSqSODASzepHtDxu84ssui47KzFTYMc Kp82/oSAPA/cLaARCNFQJngAIBSczu/DP2q9GwbTD3hVJ7kILUn0oYyyPpLhcEsi tAQVe5ejMTniXAeQae7yXQ== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3ybcdhe0a3-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 31 May 2024 10:15:15 -0500 (CDT) Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Fri, 31 May 2024 16:15:12 +0100 Received: from ediswmail9.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1544.9 via Frontend Transport; Fri, 31 May 2024 16:15:12 +0100 Received: from EDIN6ZZ2FY3.ad.cirrus.com (EDIN6ZZ2FY3.ad.cirrus.com [198.61.65.72]) by ediswmail9.ad.cirrus.com (Postfix) with ESMTP id 2874882024B; Fri, 31 May 2024 15:15:12 +0000 (UTC) From: Simon Trimmer To: CC: , , , , , , , , , Simon Trimmer Subject: [PATCH 7/7] ALSA: hda: hda_component: Protect shared data with a mutex Date: Fri, 31 May 2024 16:14:09 +0100 Message-ID: <20240531151409.80284-8-simont@opensource.cirrus.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531151409.80284-1-simont@opensource.cirrus.com> References: <20240531151409.80284-1-simont@opensource.cirrus.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: nGfCjYqswV3BL8JY5UN8bmtU3PwI8r7i X-Proofpoint-ORIG-GUID: nGfCjYqswV3BL8JY5UN8bmtU3PwI8r7i X-Proofpoint-Spam-Reason: safe The hda_component contains information shared from the amp drivers to the codec that can be altered (for example as the driver unloads). Guard the update and use of these to prevent use of stale data. Signed-off-by: Simon Trimmer --- sound/pci/hda/hda_component.c | 14 +++++++++++++- sound/pci/hda/hda_component.h | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/sound/pci/hda/hda_component.c b/sound/pci/hda/hda_component.c index 84add31408f7..21cd6a5eb6b1 100644 --- a/sound/pci/hda/hda_component.c +++ b/sound/pci/hda/hda_component.c @@ -21,11 +21,13 @@ void hda_component_acpi_device_notify(struct hda_component_parent *parent, struct hda_component *comp; int i; + mutex_lock(&parent->mutex); for (i = 0; i < ARRAY_SIZE(parent->comps); i++) { comp = hda_component_from_index(parent, i); if (comp->dev && comp->acpi_notify) comp->acpi_notify(acpi_device_handle(comp->adev), event, comp->dev); } + mutex_unlock(&parent->mutex); } EXPORT_SYMBOL_NS_GPL(hda_component_acpi_device_notify, SND_HDA_SCODEC_COMPONENT); @@ -87,6 +89,7 @@ void hda_component_manager_playback_hook(struct hda_component_parent *parent, in struct hda_component *comp; int i; + mutex_lock(&parent->mutex); for (i = 0; i < ARRAY_SIZE(parent->comps); i++) { comp = hda_component_from_index(parent, i); if (comp->dev && comp->pre_playback_hook) @@ -102,6 +105,7 @@ void hda_component_manager_playback_hook(struct hda_component_parent *parent, in if (comp->dev && comp->post_playback_hook) comp->post_playback_hook(comp->dev, action); } + mutex_unlock(&parent->mutex); } EXPORT_SYMBOL_NS_GPL(hda_component_manager_playback_hook, SND_HDA_SCODEC_COMPONENT); @@ -134,11 +138,19 @@ static int hda_comp_match_dev_name(struct device *dev, void *data) int hda_component_manager_bind(struct hda_codec *cdc, struct hda_component_parent *parent) { + int ret; + /* Init shared and component specific data */ memset(parent, 0, sizeof(parent)); + mutex_init(&parent->mutex); parent->codec = cdc; - return component_bind_all(hda_codec_dev(cdc), parent); + + mutex_lock(&parent->mutex); + ret = component_bind_all(hda_codec_dev(cdc), parent); + mutex_unlock(&parent->mutex); + + return ret; } EXPORT_SYMBOL_NS_GPL(hda_component_manager_bind, SND_HDA_SCODEC_COMPONENT); diff --git a/sound/pci/hda/hda_component.h b/sound/pci/hda/hda_component.h index dd4dabeae9ee..9f786608144c 100644 --- a/sound/pci/hda/hda_component.h +++ b/sound/pci/hda/hda_component.h @@ -11,6 +11,7 @@ #include #include +#include #include #define HDA_MAX_COMPONENTS 4 @@ -28,6 +29,7 @@ struct hda_component { }; struct hda_component_parent { + struct mutex mutex; struct hda_codec *codec; struct hda_component comps[HDA_MAX_COMPONENTS]; }; @@ -93,7 +95,9 @@ static inline struct hda_component *hda_component_from_index(struct hda_componen static inline void hda_component_manager_unbind(struct hda_codec *cdc, struct hda_component_parent *parent) { + mutex_lock(&parent->mutex); component_unbind_all(hda_codec_dev(cdc), parent); + mutex_unlock(&parent->mutex); } #endif /* ifndef __HDA_COMPONENT_H__ */ -- 2.34.1