From: Richard Fitzgerald <rf@opensource.cirrus.com>
To: <vkoul@kernel.org>, <yung-chuan.liao@linux.intel.com>,
<pierre-louis.bossart@linux.intel.com>, <lgirdwood@gmail.com>,
<peter.ujfalusi@linux.intel.com>,
<ranjani.sridharan@linux.intel.com>,
<kai.vehmanen@linux.intel.com>, <daniel.baluta@nxp.com>,
<sanyog.r.kale@intel.com>, <broonie@kernel.org>
Cc: <alsa-devel@alsa-project.org>,
<sound-open-firmware@alsa-project.org>,
<linux-kernel@vger.kernel.org>, <patches@opensource.cirrus.com>,
Richard Fitzgerald <rf@opensource.cirrus.com>
Subject: [PATCH 2/7] soundwire: intel_init: Separate shutdown and cleanup
Date: Wed, 7 Sep 2022 11:13:57 +0100 [thread overview]
Message-ID: <20220907101402.4685-3-rf@opensource.cirrus.com> (raw)
In-Reply-To: <20220907101402.4685-1-rf@opensource.cirrus.com>
Move the freeing of context data out of sdw_intel_exit() into a new
exported function sdw_intel_remove().
This splits shutdown and cleanup into separate stages, allowing the
calling code to perform its own shutdown after the bus has shutdown but
before the context has been deleted.
The struct sdw_intel_ctx pointer is passed to the calling code by
sdw_intel_probe() and the calling code passes it back as an opaque token.
When the caller is removed it must have the opportunity to teardown its
use of this token after the bus driver has stopped but before the
context memory has been freed. It should not be doing its teardown
before calling sdw_intel_exit() because that will break any bus activity
currently in progress and the removal of child drivers.
Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
drivers/soundwire/intel_init.c | 24 ++++++++++++++++++++----
include/linux/soundwire/sdw_intel.h | 2 ++
sound/soc/sof/intel/hda.c | 4 +++-
3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/drivers/soundwire/intel_init.c b/drivers/soundwire/intel_init.c
index d091513919df..078e01f67830 100644
--- a/drivers/soundwire/intel_init.c
+++ b/drivers/soundwire/intel_init.c
@@ -292,6 +292,13 @@ static struct sdw_intel_ctx
return NULL;
}
+static void sdw_intel_remove_controller(struct sdw_intel_ctx *ctx)
+{
+ kfree(ctx->ids);
+ kfree(ctx->ldev);
+ kfree(ctx);
+}
+
static int
sdw_intel_startup_controller(struct sdw_intel_ctx *ctx)
{
@@ -360,6 +367,18 @@ struct sdw_intel_ctx
}
EXPORT_SYMBOL_NS(sdw_intel_probe, SOUNDWIRE_INTEL_INIT);
+/**
+ * sdw_intel_remove() - SoundWire Intel remove routine
+ * @ctx: SoundWire context allocated in the probe
+ *
+ * Free all the context created by sdw_intel_probe.
+ */
+void sdw_intel_remove(struct sdw_intel_ctx *ctx)
+{
+ return sdw_intel_remove_controller(ctx);
+}
+EXPORT_SYMBOL_NS(sdw_intel_remove, SOUNDWIRE_INTEL_INIT);
+
/**
* sdw_intel_startup() - SoundWire Intel startup
* @ctx: SoundWire context allocated in the probe
@@ -376,14 +395,11 @@ EXPORT_SYMBOL_NS(sdw_intel_startup, SOUNDWIRE_INTEL_INIT);
* sdw_intel_exit() - SoundWire Intel exit
* @ctx: SoundWire context allocated in the probe
*
- * Delete the controller instances created and cleanup
+ * Stop the controller instances.
*/
void sdw_intel_exit(struct sdw_intel_ctx *ctx)
{
sdw_intel_cleanup(ctx);
- kfree(ctx->ids);
- kfree(ctx->ldev);
- kfree(ctx);
}
EXPORT_SYMBOL_NS(sdw_intel_exit, SOUNDWIRE_INTEL_INIT);
diff --git a/include/linux/soundwire/sdw_intel.h b/include/linux/soundwire/sdw_intel.h
index 2e9fd91572d4..7f7327cab712 100644
--- a/include/linux/soundwire/sdw_intel.h
+++ b/include/linux/soundwire/sdw_intel.h
@@ -282,6 +282,8 @@ void sdw_intel_process_wakeen_event(struct sdw_intel_ctx *ctx);
struct sdw_intel_ctx *
sdw_intel_probe(struct sdw_intel_res *res);
+void sdw_intel_remove(struct sdw_intel_ctx *ctx);
+
int sdw_intel_startup(struct sdw_intel_ctx *ctx);
void sdw_intel_exit(struct sdw_intel_ctx *ctx);
diff --git a/sound/soc/sof/intel/hda.c b/sound/soc/sof/intel/hda.c
index 8639ea63a10d..ee67e21e739f 100644
--- a/sound/soc/sof/intel/hda.c
+++ b/sound/soc/sof/intel/hda.c
@@ -241,8 +241,10 @@ static int hda_sdw_exit(struct snd_sof_dev *sdev)
hda_sdw_int_enable(sdev, false);
- if (hdev->sdw)
+ if (hdev->sdw) {
sdw_intel_exit(hdev->sdw);
+ sdw_intel_remove(hdev->sdw);
+ }
hdev->sdw = NULL;
return 0;
--
2.30.2
next prev parent reply other threads:[~2022-09-07 10:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-07 10:13 [PATCH 0/7] soundwire: Fix driver removal Richard Fitzgerald
2022-09-07 10:13 ` [PATCH 1/7] soundwire: bus: Do not forcibly disable child pm_runtime Richard Fitzgerald
2022-09-12 10:43 ` Pierre-Louis Bossart
2022-09-07 10:13 ` Richard Fitzgerald [this message]
2022-09-07 10:13 ` [PATCH 3/7] ASoC: SOF: Intel: Don't disable Soundwire interrupt before the bus has shut down Richard Fitzgerald
2022-09-07 11:26 ` Mark Brown
2022-09-07 10:13 ` [PATCH 4/7] soundwire: bus: Add remove callback to struct sdw_master_ops Richard Fitzgerald
2022-09-07 10:14 ` [PATCH 5/7] soundwire: intel: Don't disable interrupt until children are removed Richard Fitzgerald
2022-09-12 10:53 ` Pierre-Louis Bossart
2022-09-12 15:36 ` Richard Fitzgerald
2022-09-12 17:12 ` Pierre-Louis Bossart
2022-09-13 9:29 ` Richard Fitzgerald
2022-09-07 10:14 ` [PATCH 6/7] soundwire: intel: Don't disable pm_runtime " Richard Fitzgerald
2022-09-07 10:14 ` [PATCH 7/7] soundwire: bus: Fix premature removal of sdw_slave objects Richard Fitzgerald
2022-09-12 10:57 ` Pierre-Louis Bossart
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=20220907101402.4685-3-rf@opensource.cirrus.com \
--to=rf@opensource.cirrus.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=daniel.baluta@nxp.com \
--cc=kai.vehmanen@linux.intel.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=peter.ujfalusi@linux.intel.com \
--cc=pierre-louis.bossart@linux.intel.com \
--cc=ranjani.sridharan@linux.intel.com \
--cc=sanyog.r.kale@intel.com \
--cc=sound-open-firmware@alsa-project.org \
--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