* [PATCH 0/2] ASoC: fix devm use in pcm512x and wm8994
@ 2026-12-01 19:25 Arina Kharlamova via B4 Relay
2026-12-01 19:25 ` [PATCH 1/2] ASoC: pcm512x: Keep the no-PLL constraint in the private data Arina Kharlamova via B4 Relay
2026-12-01 19:25 ` [PATCH 2/2] ASoC: wm8994: Put the MCLK clocks when the codec is unbound Arina Kharlamova via B4 Relay
0 siblings, 2 replies; 8+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-01 19:25 UTC (permalink / raw)
To: Kevin Lu, Baojun Xu, Sen Wang, Liam Girdwood, Mark Brown,
Jaroslav Kysela, Takashi Iwai, Peter Rosin, Krzysztof Kozlowski,
Sylwester Nawrocki, Charles Keepax, Shenghao Ding
Cc: linux-sound, patches, Arina Kharlamova
pcm512x allocates with devm on every stream open. wm8994 gets its
MCLK clocks with devm on the parent MFD device but keeps them in its
own private data, which is freed first on unbind.
I found this with spec2patch. I model-checked the probe and remove paths
of the driver with CBMC against formal specifications of the kernel APIs
it calls. The specifications are checked against the kernel source, and
some of them are proved in Rocq against a transcription of the kernel
code. I also checked lock usage separately. With the help of an AI
coding assistant (Claude); I reviewed the analysis and the fix.
Compile-tested only, not tested on hardware.
To: Shenghao Ding <shenghao-ding@ti.com>
---
Arina Kharlamova (2):
ASoC: pcm512x: Keep the no-PLL constraint in the private data
ASoC: wm8994: Put the MCLK clocks when the codec is unbound
sound/soc/codecs/pcm512x.c | 13 +++++--------
sound/soc/codecs/wm8994.c | 15 +++++++++++++--
2 files changed, 18 insertions(+), 10 deletions(-)
---
base-commit: 20ee6031645dbed8ddf8f4833edf415f3760607f
change-id: 20261201-s2p-lpr-asoc-d83e231bc4a1
Best regards,
--
Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 1/2] ASoC: pcm512x: Keep the no-PLL constraint in the private data
2026-12-01 19:25 [PATCH 0/2] ASoC: fix devm use in pcm512x and wm8994 Arina Kharlamova via B4 Relay
@ 2026-12-01 19:25 ` Arina Kharlamova via B4 Relay
2026-12-01 19:25 ` [PATCH 2/2] ASoC: wm8994: Put the MCLK clocks when the codec is unbound Arina Kharlamova via B4 Relay
1 sibling, 0 replies; 8+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-01 19:25 UTC (permalink / raw)
To: Kevin Lu, Baojun Xu, Sen Wang, Liam Girdwood, Mark Brown,
Jaroslav Kysela, Takashi Iwai, Peter Rosin, Krzysztof Kozlowski,
Sylwester Nawrocki, Charles Keepax, Shenghao Ding
Cc: linux-sound, patches, Arina Kharlamova
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
pcm512x_dai_startup_master() allocates the ratnums constraint and its
snd_ratnum with devm every time a stream is opened while the codec is
the clock provider without the PLL. Nothing frees them, so each open
adds two allocations that stay until the codec is unbound.
Embed both in struct pcm512x_priv and fill them in on startup as
before.
Fixes: 8124930713f2 ("ASoC: pcm512x: Support mastering BCLK/LRCLK without using the PLL")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
sound/soc/codecs/pcm512x.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c
index f6f07de133c4..dd5ba46634b1 100644
--- a/sound/soc/codecs/pcm512x.c
+++ b/sound/soc/codecs/pcm512x.c
@@ -51,6 +51,8 @@ struct pcm512x_priv {
struct mutex mutex;
unsigned int bclk_ratio;
int force_pll_on;
+ struct snd_ratnum rats_no_pll;
+ struct snd_pcm_hw_constraint_ratnums constraints_no_pll;
};
/*
@@ -586,8 +588,9 @@ static int pcm512x_dai_startup_master(struct snd_pcm_substream *substream,
struct snd_soc_component *component = dai->component;
struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
struct device *dev = dai->dev;
- struct snd_pcm_hw_constraint_ratnums *constraints_no_pll;
- struct snd_ratnum *rats_no_pll;
+ struct snd_pcm_hw_constraint_ratnums *constraints_no_pll =
+ &pcm512x->constraints_no_pll;
+ struct snd_ratnum *rats_no_pll = &pcm512x->rats_no_pll;
if (IS_ERR(pcm512x->sclk)) {
dev_err(dev, "Need SCLK for master mode: %ld\n",
@@ -603,13 +606,7 @@ static int pcm512x_dai_startup_master(struct snd_pcm_substream *substream,
SNDRV_PCM_HW_PARAM_FRAME_BITS,
SNDRV_PCM_HW_PARAM_CHANNELS, -1);
- constraints_no_pll = devm_kzalloc_obj(dev, *constraints_no_pll);
- if (!constraints_no_pll)
- return -ENOMEM;
constraints_no_pll->nrats = 1;
- rats_no_pll = devm_kzalloc_obj(dev, *rats_no_pll);
- if (!rats_no_pll)
- return -ENOMEM;
constraints_no_pll->rats = rats_no_pll;
rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
rats_no_pll->den_min = 1;
--
Git-157)
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 2/2] ASoC: wm8994: Put the MCLK clocks when the codec is unbound
2026-12-01 19:25 [PATCH 0/2] ASoC: fix devm use in pcm512x and wm8994 Arina Kharlamova via B4 Relay
2026-12-01 19:25 ` [PATCH 1/2] ASoC: pcm512x: Keep the no-PLL constraint in the private data Arina Kharlamova via B4 Relay
@ 2026-12-01 19:25 ` Arina Kharlamova via B4 Relay
2026-12-02 11:24 ` Krzysztof Kozlowski
` (2 more replies)
1 sibling, 3 replies; 8+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-01 19:25 UTC (permalink / raw)
To: Kevin Lu, Baojun Xu, Sen Wang, Liam Girdwood, Mark Brown,
Jaroslav Kysela, Takashi Iwai, Peter Rosin, Krzysztof Kozlowski,
Sylwester Nawrocki, Charles Keepax, Shenghao Ding
Cc: linux-sound, patches, Arina Kharlamova
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
wm8994_probe() gets MCLK1 and MCLK2 with devm_clk_bulk_get_optional()
on the parent MFD device, but the clk_bulk_data array is in the codec
private data. When the codec is unbound the array is freed while the
devres entry of the parent still points to it, and clk_bulk_put() then
uses the freed array when the parent goes away. Each new codec probe
also adds another entry to the parent.
Get the clocks with clk_bulk_get_optional() and put them from a devm
action of the codec device.
Fixes: 419e2f508336 ("ASoC: wm8994: Add support for setting MCLK clock rate")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
sound/soc/codecs/wm8994.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
index fcaeff208eb7..8134be7277f6 100644
--- a/sound/soc/codecs/wm8994.c
+++ b/sound/soc/codecs/wm8994.c
@@ -4703,6 +4703,13 @@ static const struct snd_soc_component_driver soc_component_dev_wm8994 = {
.endianness = 1,
};
+static void wm8994_put_mclk(void *data)
+{
+ struct wm8994_priv *wm8994 = data;
+
+ clk_bulk_put(ARRAY_SIZE(wm8994->mclk), wm8994->mclk);
+}
+
static int wm8994_probe(struct platform_device *pdev)
{
struct wm8994_priv *wm8994;
@@ -4720,13 +4727,17 @@ static int wm8994_probe(struct platform_device *pdev)
wm8994->mclk[WM8994_MCLK1].id = "MCLK1";
wm8994->mclk[WM8994_MCLK2].id = "MCLK2";
- ret = devm_clk_bulk_get_optional(pdev->dev.parent, ARRAY_SIZE(wm8994->mclk),
- wm8994->mclk);
+ ret = clk_bulk_get_optional(pdev->dev.parent, ARRAY_SIZE(wm8994->mclk),
+ wm8994->mclk);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to get clocks: %d\n", ret);
return ret;
}
+ ret = devm_add_action_or_reset(&pdev->dev, wm8994_put_mclk, wm8994);
+ if (ret < 0)
+ return ret;
+
pm_runtime_enable(&pdev->dev);
pm_runtime_idle(&pdev->dev);
--
Git-157)
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 2/2] ASoC: wm8994: Put the MCLK clocks when the codec is unbound
2026-12-01 19:25 ` [PATCH 2/2] ASoC: wm8994: Put the MCLK clocks when the codec is unbound Arina Kharlamova via B4 Relay
@ 2026-12-02 11:24 ` Krzysztof Kozlowski
2026-12-02 11:58 ` Charles Keepax
2026-12-02 13:11 ` Krzysztof Kozlowski
2026-12-02 17:45 ` Charles Keepax
2 siblings, 1 reply; 8+ messages in thread
From: Krzysztof Kozlowski @ 2026-12-02 11:24 UTC (permalink / raw)
To: arina.kharlamova, Kevin Lu, Baojun Xu, Sen Wang, Liam Girdwood,
Mark Brown, Jaroslav Kysela, Takashi Iwai, Peter Rosin,
Sylwester Nawrocki, Charles Keepax, Shenghao Ding
Cc: linux-sound, patches
On 01/12/2026 20:25, Arina Kharlamova via B4 Relay wrote:
> static int wm8994_probe(struct platform_device *pdev)
> {
> struct wm8994_priv *wm8994;
> @@ -4720,13 +4727,17 @@ static int wm8994_probe(struct platform_device *pdev)
> wm8994->mclk[WM8994_MCLK1].id = "MCLK1";
> wm8994->mclk[WM8994_MCLK2].id = "MCLK2";
>
> - ret = devm_clk_bulk_get_optional(pdev->dev.parent, ARRAY_SIZE(wm8994->mclk),
> - wm8994->mclk);
> + ret = clk_bulk_get_optional(pdev->dev.parent, ARRAY_SIZE(wm8994->mclk),
> + wm8994->mclk);
I don't get why the clocks are get on the parent device, looks like some
copy-paste code, so I think this should be fixed instead by
devm_clk_bulk_get_optional() on this device, not on the parent.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 2/2] ASoC: wm8994: Put the MCLK clocks when the codec is unbound
2026-12-02 11:24 ` Krzysztof Kozlowski
@ 2026-12-02 11:58 ` Charles Keepax
2026-12-02 13:10 ` Krzysztof Kozlowski
0 siblings, 1 reply; 8+ messages in thread
From: Charles Keepax @ 2026-12-02 11:58 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: arina.kharlamova, Kevin Lu, Baojun Xu, Sen Wang, Liam Girdwood,
Mark Brown, Jaroslav Kysela, Takashi Iwai, Peter Rosin,
Sylwester Nawrocki, Shenghao Ding, linux-sound, patches
On Wed, Dec 02, 2026 at 12:24:29PM +0100, Krzysztof Kozlowski wrote:
> On 01/12/2026 20:25, Arina Kharlamova via B4 Relay wrote:
> > static int wm8994_probe(struct platform_device *pdev)
> > {
> > struct wm8994_priv *wm8994;
> > @@ -4720,13 +4727,17 @@ static int wm8994_probe(struct platform_device *pdev)
> > wm8994->mclk[WM8994_MCLK1].id = "MCLK1";
> > wm8994->mclk[WM8994_MCLK2].id = "MCLK2";
> >
> > - ret = devm_clk_bulk_get_optional(pdev->dev.parent, ARRAY_SIZE(wm8994->mclk),
> > - wm8994->mclk);
> > + ret = clk_bulk_get_optional(pdev->dev.parent, ARRAY_SIZE(wm8994->mclk),
> > + wm8994->mclk);
>
>
> I don't get why the clocks are get on the parent device, looks like some
> copy-paste code, so I think this should be fixed instead by
> devm_clk_bulk_get_optional() on this device, not on the parent.
I believe this is because its an MFD and uses a node for
the whole chip. Maybe could do something with copying the fwnode
to the child first the getting against yourself but not really
thought through if that would work.
Thanks,
Charles
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 2/2] ASoC: wm8994: Put the MCLK clocks when the codec is unbound
2026-12-02 11:58 ` Charles Keepax
@ 2026-12-02 13:10 ` Krzysztof Kozlowski
0 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2026-12-02 13:10 UTC (permalink / raw)
To: Charles Keepax
Cc: arina.kharlamova, Kevin Lu, Baojun Xu, Sen Wang, Liam Girdwood,
Mark Brown, Jaroslav Kysela, Takashi Iwai, Peter Rosin,
Sylwester Nawrocki, Shenghao Ding, linux-sound, patches
On 02/12/2026 12:58, Charles Keepax wrote:
> On Wed, Dec 02, 2026 at 12:24:29PM +0100, Krzysztof Kozlowski wrote:
>> On 01/12/2026 20:25, Arina Kharlamova via B4 Relay wrote:
>>> static int wm8994_probe(struct platform_device *pdev)
>>> {
>>> struct wm8994_priv *wm8994;
>>> @@ -4720,13 +4727,17 @@ static int wm8994_probe(struct platform_device *pdev)
>>> wm8994->mclk[WM8994_MCLK1].id = "MCLK1";
>>> wm8994->mclk[WM8994_MCLK2].id = "MCLK2";
>>>
>>> - ret = devm_clk_bulk_get_optional(pdev->dev.parent, ARRAY_SIZE(wm8994->mclk),
>>> - wm8994->mclk);
>>> + ret = clk_bulk_get_optional(pdev->dev.parent, ARRAY_SIZE(wm8994->mclk),
>>> + wm8994->mclk);
>>
>>
>> I don't get why the clocks are get on the parent device, looks like some
>> copy-paste code, so I think this should be fixed instead by
>> devm_clk_bulk_get_optional() on this device, not on the parent.
>
> I believe this is because its an MFD and uses a node for
> the whole chip. Maybe could do something with copying the fwnode
> to the child first the getting against yourself but not really
> thought through if that would work.
Indeed
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] ASoC: wm8994: Put the MCLK clocks when the codec is unbound
2026-12-01 19:25 ` [PATCH 2/2] ASoC: wm8994: Put the MCLK clocks when the codec is unbound Arina Kharlamova via B4 Relay
2026-12-02 11:24 ` Krzysztof Kozlowski
@ 2026-12-02 13:11 ` Krzysztof Kozlowski
2026-12-02 17:45 ` Charles Keepax
2 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2026-12-02 13:11 UTC (permalink / raw)
To: arina.kharlamova, Kevin Lu, Baojun Xu, Sen Wang, Liam Girdwood,
Mark Brown, Jaroslav Kysela, Takashi Iwai, Peter Rosin,
Sylwester Nawrocki, Charles Keepax, Shenghao Ding
Cc: linux-sound, patches
On 01/12/2026 20:25, Arina Kharlamova via B4 Relay wrote:
> From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
>
> wm8994_probe() gets MCLK1 and MCLK2 with devm_clk_bulk_get_optional()
> on the parent MFD device, but the clk_bulk_data array is in the codec
> private data. When the codec is unbound the array is freed while the
> devres entry of the parent still points to it, and clk_bulk_put() then
> uses the freed array when the parent goes away. Each new codec probe
> also adds another entry to the parent.
>
> Get the clocks with clk_bulk_get_optional() and put them from a devm
> action of the codec device.
>
> Fixes: 419e2f508336 ("ASoC: wm8994: Add support for setting MCLK clock rate")
> Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
> ---
> sound/soc/codecs/wm8994.c | 15 +++++++++++++--
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 2/2] ASoC: wm8994: Put the MCLK clocks when the codec is unbound
2026-12-01 19:25 ` [PATCH 2/2] ASoC: wm8994: Put the MCLK clocks when the codec is unbound Arina Kharlamova via B4 Relay
2026-12-02 11:24 ` Krzysztof Kozlowski
2026-12-02 13:11 ` Krzysztof Kozlowski
@ 2026-12-02 17:45 ` Charles Keepax
2 siblings, 0 replies; 8+ messages in thread
From: Charles Keepax @ 2026-12-02 17:45 UTC (permalink / raw)
To: arina.kharlamova
Cc: Kevin Lu, Baojun Xu, Sen Wang, Liam Girdwood, Mark Brown,
Jaroslav Kysela, Takashi Iwai, Peter Rosin, Krzysztof Kozlowski,
Sylwester Nawrocki, Shenghao Ding, linux-sound, patches
On Tue, Dec 01, 2026 at 11:25:50PM +0400, Arina Kharlamova via B4 Relay wrote:
> From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
>
> wm8994_probe() gets MCLK1 and MCLK2 with devm_clk_bulk_get_optional()
> on the parent MFD device, but the clk_bulk_data array is in the codec
> private data. When the codec is unbound the array is freed while the
> devres entry of the parent still points to it, and clk_bulk_put() then
> uses the freed array when the parent goes away. Each new codec probe
> also adds another entry to the parent.
>
> Get the clocks with clk_bulk_get_optional() and put them from a devm
> action of the codec device.
>
> Fixes: 419e2f508336 ("ASoC: wm8994: Add support for setting MCLK clock rate")
> Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
> ---
Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Thanks,
Charles
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-12-02 17:46 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 19:25 [PATCH 0/2] ASoC: fix devm use in pcm512x and wm8994 Arina Kharlamova via B4 Relay
2026-12-01 19:25 ` [PATCH 1/2] ASoC: pcm512x: Keep the no-PLL constraint in the private data Arina Kharlamova via B4 Relay
2026-12-01 19:25 ` [PATCH 2/2] ASoC: wm8994: Put the MCLK clocks when the codec is unbound Arina Kharlamova via B4 Relay
2026-12-02 11:24 ` Krzysztof Kozlowski
2026-12-02 11:58 ` Charles Keepax
2026-12-02 13:10 ` Krzysztof Kozlowski
2026-12-02 13:11 ` Krzysztof Kozlowski
2026-12-02 17:45 ` Charles Keepax
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox