From: Simon Trimmer <simont@opensource.cirrus.com>
To: <tiwai@suse.com>
Cc: <linux-sound@vger.kernel.org>, <alsa-devel@alsa-project.org>,
<linux-kernel@vger.kernel.org>, <patches@opensource.cirrus.com>,
<soyer@irl.hu>, <shenghao-ding@ti.com>, <kevin-lu@ti.com>,
<baojun.xu@ti.com>, Simon Trimmer <simont@opensource.cirrus.com>
Subject: [PATCH 4/4] ALSA: hda: hda_component: Protect shared data with a mutex
Date: Mon, 17 Jun 2024 16:41:05 +0100 [thread overview]
Message-ID: <20240617154105.108635-5-simont@opensource.cirrus.com> (raw)
In-Reply-To: <20240617154105.108635-1-simont@opensource.cirrus.com>
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 <simont@opensource.cirrus.com>
---
sound/pci/hda/hda_component.c | 13 ++++++++++++-
sound/pci/hda/hda_component.h | 4 ++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/sound/pci/hda/hda_component.c b/sound/pci/hda/hda_component.c
index 1a9950b76866..7b19cb38b4e0 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,18 @@ 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 <linux/acpi.h>
#include <linux/component.h>
+#include <linux/mutex.h>
#include <sound/hda_codec.h>
#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
next prev parent reply other threads:[~2024-06-17 15:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-17 15:41 [PATCH v3 0/4] ALSA: hda: Improvements to hda_component Simon Trimmer
2024-06-17 15:41 ` [PATCH 1/4] ALSA: hda: hda_component: Introduce component parent structure Simon Trimmer
2024-06-17 15:41 ` [PATCH 2/4] ALSA: hda: hda_component: Change codecs to use " Simon Trimmer
2024-06-17 15:41 ` [PATCH 3/4] ALSA: hda: hda_component: Move codec field into the parent Simon Trimmer
2024-06-17 15:41 ` Simon Trimmer [this message]
2024-06-18 9:53 ` [PATCH v3 0/4] ALSA: hda: Improvements to hda_component Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240617154105.108635-5-simont@opensource.cirrus.com \
--to=simont@opensource.cirrus.com \
--cc=alsa-devel@alsa-project.org \
--cc=baojun.xu@ti.com \
--cc=kevin-lu@ti.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=shenghao-ding@ti.com \
--cc=soyer@irl.hu \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox