From: Chancel Liu <chancel.liu@oss.nxp.com>
To: Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>,
Shenghao Ding <shenghao-ding@ti.com>, Kevin Lu <kevin-lu@ti.com>,
Baojun Xu <baojun.xu@ti.com>, Sen Wang <sen@ti.com>,
David Rhodes <david.rhodes@cirrus.com>,
Richard Fitzgerald <rf@opensource.cirrus.com>
Cc: Charles Keepax <ckeepax@opensource.cirrus.com>,
patches@opensource.cirrus.com, linux-sound@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 6/6] ASoC: cs42l56: Fix beep input device leak on card re-bind
Date: Sun, 13 Sep 2026 19:15:31 +0900 [thread overview]
Message-ID: <20260913101531.2787654-7-chancel.liu@oss.nxp.com> (raw)
In-Reply-To: <20260913101531.2787654-1-chancel.liu@oss.nxp.com>
From: Chancel Liu <chancel.liu@nxp.com>
cs42l56 allocates its beep input device with devm_input_allocate_device()
from the ASoC component probe, but the associated devres cleanup is tied
to the underlying I2C device, while cs42l56_free_beep() on the component
remove path only clears the cs42l56->beep pointer.
The input device is only leaked when the sound card is unregistered and
re-registered while the I2C device stays bound. On that path the
component probe runs again and allocates and registers a new input
device every time, leaking the previous one and its sysfs/input node.
Allocate the beep device with input_allocate_device() and pair it with
the component lifecycle: input_free_device() on registration failure and
input_unregister_device() in cs42l56_free_beep().
Signed-off-by: Chancel Liu <chancel.liu@nxp.com>
---
sound/soc/codecs/cs42l56.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/sound/soc/codecs/cs42l56.c b/sound/soc/codecs/cs42l56.c
index 4d9a22a1029c..37df94fbc887 100644
--- a/sound/soc/codecs/cs42l56.c
+++ b/sound/soc/codecs/cs42l56.c
@@ -1077,7 +1077,7 @@ static void cs42l56_init_beep(struct snd_soc_component *component)
struct cs42l56_private *cs42l56 = snd_soc_component_get_drvdata(component);
int ret;
- cs42l56->beep = devm_input_allocate_device(component->dev);
+ cs42l56->beep = input_allocate_device();
if (!cs42l56->beep) {
dev_err(component->dev, "Failed to allocate beep device\n");
return;
@@ -1098,8 +1098,10 @@ static void cs42l56_init_beep(struct snd_soc_component *component)
ret = input_register_device(cs42l56->beep);
if (ret != 0) {
+ input_free_device(cs42l56->beep);
cs42l56->beep = NULL;
dev_err(component->dev, "Failed to register beep device\n");
+ return;
}
ret = device_create_file(component->dev, &dev_attr_beep);
@@ -1115,7 +1117,10 @@ static void cs42l56_free_beep(struct snd_soc_component *component)
device_remove_file(component->dev, &dev_attr_beep);
cancel_work_sync(&cs42l56->beep_work);
- cs42l56->beep = NULL;
+ if (cs42l56->beep) {
+ input_unregister_device(cs42l56->beep);
+ cs42l56->beep = NULL;
+ }
snd_soc_component_update_bits(component, CS42L56_BEEP_TONE_CFG,
CS42L56_BEEP_EN_MASK, 0);
--
2.50.1
next prev parent reply other threads:[~2026-09-13 10:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-13 10:15 [PATCH 0/6] ASoC: codecs: Fix resource leaks " Chancel Liu
2026-09-13 10:15 ` [PATCH 1/6] ASoC: wm8962: Fix regulator notifier and beep " Chancel Liu
2026-09-14 10:56 ` Charles Keepax
2026-09-13 10:15 ` [PATCH 2/6] ASoC: wm8995: Register regulator notifiers from the bus probe Chancel Liu
2026-09-14 12:49 ` Charles Keepax
2026-09-13 10:15 ` [PATCH 3/6] ASoC: tlv320aic31xx: Register regulator notifier from the I2C probe Chancel Liu
2026-09-13 10:15 ` [PATCH 4/6] ASoC: tlv320aic3x: Register regulator notifier from the bus probe Chancel Liu
2026-09-13 10:15 ` [PATCH 5/6] ASoC: cs42l52: Fix beep input device leak on card re-bind Chancel Liu
2026-09-14 12:51 ` Charles Keepax
2026-09-13 10:15 ` Chancel Liu [this message]
2026-09-14 12:52 ` [PATCH 6/6] ASoC: cs42l56: " Charles Keepax
2026-09-14 13:58 ` [PATCH 0/6] ASoC: codecs: Fix resource leaks " Mark Brown
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=20260913101531.2787654-7-chancel.liu@oss.nxp.com \
--to=chancel.liu@oss.nxp.com \
--cc=baojun.xu@ti.com \
--cc=broonie@kernel.org \
--cc=ckeepax@opensource.cirrus.com \
--cc=david.rhodes@cirrus.com \
--cc=kevin-lu@ti.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=perex@perex.cz \
--cc=rf@opensource.cirrus.com \
--cc=sen@ti.com \
--cc=shenghao-ding@ti.com \
--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
all inboxes | Powered by JetHome®