From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: vkoul@kernel.org
Cc: yung-chuan.liao@linux.intel.com, pierre-louis.bossart@linux.dev,
peter.ujfalusi@linux.intel.com, linux-sound@vger.kernel.org,
patches@opensource.cirrus.com, linux-kernel@vger.kernel.org
Subject: [PATCH v2 3/3] soundwire: intel_auxdevice: Don't disable IRQs before removing children
Date: Fri, 25 Sep 2026 16:42:16 +0100 [thread overview]
Message-ID: <20260925154216.3520136-4-ckeepax@opensource.cirrus.com> (raw)
In-Reply-To: <20260925154216.3520136-1-ckeepax@opensource.cirrus.com>
Currently the auxiliary device for the link disables IRQs before it
calls sdw_bus_master_delete(). This has the side effect that none
of the devices on the link can access their own registers whilst
their remove functions run, because the IRQs are required for bus
transactions to function.
There appear to be two things that currently block leaving the
IRQs enabled during peripheral removal. Firstly, the IRQ handler
iterates through a linked list of all the links, once a link is
removed the memory pointed at by this linked list is freed, but
not removed from the linked_list. Secondly, the potential that
an IRQ runs after the controller itself has been destroyed.
For the first problem add a list_del() for the linked list item,
note whilst the list itself is contained in the intel_init portion
of the code, the list remove needs to be attached to the auxiliary
device for the link, since that owns the memory that the list points
at. Locking is also required to ensure the IRQ handler runs either
before or after any additions/removals from the list. A new lock is
added for this, the shim_lock is used to gate access to the shared
registers so doesn't feel a super obvious fit for managing the list.
For the second problem utilise the newly added helper that allows
destroying the peripherals separately, allowing the auxiliary device
to disable IRQs before running its own cleanup.
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
Changes since v1:
- Use new sdw_bus_slaves_delete() helper, which allows us to disable
IRQs before destroying the master completely.
drivers/soundwire/intel.h | 1 +
drivers/soundwire/intel_auxdevice.c | 7 ++++++-
drivers/soundwire/intel_init.c | 21 +++++++++++++++++++++
include/linux/soundwire/sdw_intel.h | 1 +
4 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/drivers/soundwire/intel.h b/drivers/soundwire/intel.h
index 7a2e7e73ad632..ec82ac8d54adb 100644
--- a/drivers/soundwire/intel.h
+++ b/drivers/soundwire/intel.h
@@ -47,6 +47,7 @@ struct sdw_intel_link_res {
u32 link_mask;
struct sdw_cdns *cdns;
struct list_head list;
+ struct mutex *link_lock; /* lock protecting list */
struct hdac_bus *hbus;
};
diff --git a/drivers/soundwire/intel_auxdevice.c b/drivers/soundwire/intel_auxdevice.c
index 901a71262094f..1439cef43462d 100644
--- a/drivers/soundwire/intel_auxdevice.c
+++ b/drivers/soundwire/intel_auxdevice.c
@@ -508,8 +508,13 @@ static void intel_link_remove(struct auxiliary_device *auxdev)
if (!bus->prop.hw_disabled) {
sdw_intel_debugfs_exit(sdw);
cancel_delayed_work_sync(&cdns->attach_dwork);
- sdw_cdns_enable_interrupt(cdns, false);
}
+
+ sdw_bus_slaves_delete(bus);
+
+ if (!bus->prop.hw_disabled)
+ sdw_cdns_enable_interrupt(cdns, false);
+
sdw_bus_master_delete(bus);
}
diff --git a/drivers/soundwire/intel_init.c b/drivers/soundwire/intel_init.c
index ad48d67fa9358..a7437cd420288 100644
--- a/drivers/soundwire/intel_init.c
+++ b/drivers/soundwire/intel_init.c
@@ -28,6 +28,15 @@ static void intel_link_dev_release(struct device *dev)
kfree(ldev);
}
+static void intel_link_list_del(void *data)
+{
+ struct sdw_intel_link_res *link = data;
+
+ mutex_lock(link->link_lock);
+ list_del(&link->list);
+ mutex_unlock(link->link_lock);
+}
+
/* alloc, init and add link devices */
static struct sdw_intel_link_dev *intel_link_dev_register(struct sdw_intel_res *res,
struct sdw_intel_ctx *ctx,
@@ -79,6 +88,7 @@ static struct sdw_intel_link_dev *intel_link_dev_register(struct sdw_intel_res *
link->shim_lock = res->eml_lock;
link->mic_privacy = res->mic_privacy;
}
+ link->link_lock = &ctx->link_lock;
link->ops = res->ops;
link->dev = res->dev;
@@ -145,8 +155,10 @@ irqreturn_t sdw_intel_thread(int irq, void *dev_id)
struct sdw_intel_ctx *ctx = dev_id;
struct sdw_intel_link_res *link;
+ mutex_lock(&ctx->link_lock);
list_for_each_entry(link, &ctx->link_list, list)
sdw_cdns_irq(irq, link->cdns);
+ mutex_unlock(&ctx->link_lock);
return IRQ_HANDLED;
}
@@ -165,6 +177,7 @@ static struct sdw_intel_ctx
u32 link_mask;
int num_slaves = 0;
int count;
+ int ret;
int i;
if (!res)
@@ -210,6 +223,7 @@ static struct sdw_intel_ctx
ctx->link_mask = res->link_mask;
ctx->handle = res->handle;
mutex_init(&ctx->shim_lock);
+ mutex_init(&ctx->link_lock);
link_mask = ctx->link_mask;
@@ -246,7 +260,14 @@ static struct sdw_intel_ctx
i++;
goto err;
}
+
+ mutex_lock(&ctx->link_lock);
list_add_tail(&link->list, &ctx->link_list);
+ mutex_unlock(&ctx->link_lock);
+ ret = devm_add_action_or_reset(&ldev->auxdev.dev, intel_link_list_del, link);
+ if (ret)
+ goto err;
+
bus = &link->cdns->bus;
/* Calculate number of slaves */
list_for_each(node, &bus->slaves)
diff --git a/include/linux/soundwire/sdw_intel.h b/include/linux/soundwire/sdw_intel.h
index 9710f2dc04e29..7495d35ed2fc3 100644
--- a/include/linux/soundwire/sdw_intel.h
+++ b/include/linux/soundwire/sdw_intel.h
@@ -307,6 +307,7 @@ struct sdw_intel_ctx {
acpi_handle handle;
struct sdw_intel_link_dev **ldev;
struct list_head link_list;
+ struct mutex link_lock; /* lock protecting link_list */
struct mutex shim_lock; /* lock for access to shared SHIM registers */
u32 shim_mask;
u32 shim_base;
--
2.47.3
prev parent reply other threads:[~2026-09-25 15:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 15:42 [PATCH v2 0/3] Allow SoundWire devices to communicate during remove Charles Keepax
2026-09-25 15:42 ` [PATCH v2 1/3] soundwire: bus: Don't unassign dev_num before unregistering device Charles Keepax
2026-09-25 15:42 ` [PATCH v2 2/3] soundwire: bus: Expose a helper to remove devices from the bus Charles Keepax
2026-09-25 15:42 ` Charles Keepax [this message]
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=20260925154216.3520136-4-ckeepax@opensource.cirrus.com \
--to=ckeepax@opensource.cirrus.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=peter.ujfalusi@linux.intel.com \
--cc=pierre-louis.bossart@linux.dev \
--cc=vkoul@kernel.org \
--cc=yung-chuan.liao@linux.intel.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
all inboxes | Powered by JetHome®