ASoC: cs35l56: Use devres to destroy workqueue
Subsystems (3)
Richard Fitzgerald
maintainerPATCH 1/1 ASoC: cs35l56: Use devres to destroy workqueue
In cs35l56_dsp_init() use devm_add_action_or_reset() to add a devres cleanup function that flushes and destroys the workqueue. This replaces manually calling destroy_workqueue().
The error path in cs35l56_common_probe() did not call destroy_workqueue(). Using devres keeps the destroy_workqueue() automatically ordered relative to all the other devres-managed cleanup.
The call to destroy_workqueue() in cs35l56_remove() has been deleted.
The use of devres cleanup was suggested by https://sashiko.dev to avoid a small cleanup inversion window if destroy_workqueue() is called in the error path of cs35l56_common_probe().
--- sound/soc/codecs/cs35l56.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
sound/soc/codecs/cs35l56.c +14 -2
@@ -1627,6 +1627,14 @@ static int cs35l56_control_add_nop(struct wm_adsp *dsp, struct cs_dsp_coeff_ctlreturn 0 ; } +static void cs35l56_dsp_workqueue_destroy (void *data) +{ +struct workqueue_struct *wq = data; + +flush_workqueue (wq); +destroy_workqueue (wq); +} +static int cs35l56_dsp_init (struct cs35l56_private *cs35l56) {struct wm_adsp *dsp;
@@ -1636,6 +1644,12 @@ static int cs35l56_dsp_init(struct cs35l56_private *cs35l56)if (!cs35l56->dsp_wq)return -ENOMEM ; + ret =devm_add_action_or_reset (cs35l56->base.dev, + cs35l56_dsp_workqueue_destroy, + cs35l56->dsp_wq); +if (ret) +return ret; +INIT_WORK (&cs35l56->dsp_work, cs35l56_dsp_work); dsp = &cs35l56->dsp;
@@ -2066,8 +2080,6 @@ void cs35l56_remove(struct cs35l56_private *cs35l56)if (cs35l56->base.irq)devm_free_irq (cs35l56->base.dev, cs35l56->base.irq, &cs35l56->base); -destroy_workqueue (cs35l56->dsp_wq); -pm_runtime_dont_use_autosuspend (cs35l56->base.dev);pm_runtime_suspend (cs35l56->base.dev);pm_runtime_disable (cs35l56->base.dev);
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerQuoted 54 lines · Richard Fitzgerald
In
cs35l56_dsp_init()usedevm_add_action_or_reset()to add a devres cleanup function that flushes and destroys the workqueue. This replaces manually callingdestroy_workqueue().The error path in
cs35l56_common_probe()did not calldestroy_workqueue(). Using devres keeps thedestroy_workqueue()automatically ordered relative to all the other devres-managed cleanup.The call to
destroy_workqueue()incs35l56_remove()has been deleted.The use of devres cleanup was suggested by https://sashiko.dev to avoid a small cleanup inversion window if
destroy_workqueue()is called in the error path ofcs35l56_common_probe().Fixes e49611252900 ("ASoC: cs35l56: Add driver for Cirrus Logic CS35L56")Signed-off-by Richard Fitzgerald <[email protected]>--- sound/soc/codecs/cs35l56.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)sound/soc/codecs/cs35l56.c +14
-0@@ -1627,6 +1627,14 @@ static int cs35l56_control_add_nop(struct wm_adsp *dsp, struct cs_dsp_coeff_ctlreturn 0 ; } +static void cs35l56_dsp_workqueue_destroy (void *data) +{ +struct workqueue_struct *wq = data; + +flush_workqueue (wq); +destroy_workqueue (wq); +} +static int cs35l56_dsp_init (struct cs35l56_private *cs35l56) {struct wm_adsp *dsp;@@ -1636,6 +1644,12 @@ static int cs35l56_dsp_init(struct cs35l56_private *cs35l56)if (!cs35l56->dsp_wq)return -ENOMEM ; + ret =devm_add_action_or_reset (cs35l56->base.dev, + cs35l56_dsp_workqueue_destroy, + cs35l56->dsp_wq); +if (ret) +return ret; +INIT_WORK (&cs35l56->dsp_work, cs35l56_dsp_work); dsp = &cs35l56->dsp;
sound/soc/codecs/cs35l56.c void cs35l56_remove(struct cs35l56_private *cs35l56) · line 2070
Quoted 5 lines
sound/soc/codecs/cs35l56.c +0
-2@@ -2066,8 +2080,6 @@ void cs35l56_remove(struct cs35l56_private *cs35l56)if (cs35l56->base.irq)devm_free_irq (cs35l56->base.dev, cs35l56->base.irq, &cs35l56->base); -destroy_workqueue (cs35l56->dsp_wq); -
Sashiko points out that this should be replaced by a flush so the workqueue is empty before the following cleanup steps.
Quoted 3 lines
sound/soc/codecs/cs35l56.c +0
-0pm_runtime_dont_use_autosuspend (cs35l56->base.dev);pm_runtime_suspend (cs35l56->base.dev);pm_runtime_disable (cs35l56->base.dev);