Skip to contentSkip to conversation

input: virtio_input: don't free poller-enabled beeper on remove

PATCH Applied Ahmad Fatoum 2 participants 2 messages Nov 8 – Nov 9 Input drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 input: virtio_input: don't free poller-enabled beeper on remove

The sound card of a virtio keyboard is embedded in the driver's private data, which virtinput_remove() frees.

Drop the free and instead just disable the soundcard, so it can no longer beep. A proper fix would be to add support for unregistering sound cards, but that can follow after devm support lands.

Fixes deb9d7c18b07 ("input: virtio_input: add sound support")
---
 drivers/input/virtio_input.c | 12 ++++++++----
 drivers/sound/core.c         | 11 ++++++++++-
 include/sound.h              |  6 ++++++
 3 files changed, 24 insertions(+), 5 deletions(-)
drivers/input/virtio_input.c +8 -4
index 6e73e7873986..48a3aef2522c 100644
@@ -19,6 +19,7 @@ struct virtio_input {
 	struct virtio_input_event  evts[64];
 	struct poller_struct       poller;
 	struct sound_card          beeper;
+	bool                       beeper_registered;
 	unsigned long              sndbit[BITS_TO_LONGS(SND_CNT)];
 };
 
@@ -239,10 +240,12 @@ static int virtinput_probe(struct virtio_device *vdev)
 		beeper->beep = virtinput_send_status;
 
 		err = sound_card_register(&vi->beeper);
-		if (err)
+		if (err) {
 			dev_warn(&vdev->dev, "bell registration failed: %pe\n", ERR_PTR(err));
-		else
+		} else {
+			vi->beeper_registered = true;
 			dev_info(&vdev->dev, "bell registered\n");
+		}
 	}
 
 	return 0;
@@ -260,12 +263,13 @@ static void virtinput_remove(struct virtio_device *vdev)
 {
 	struct virtio_input *vi = vdev->priv;
 
+	if (vi->beeper_registered)
+		sound_card_disable(&vi->beeper);
+
 	vdev->config->reset(vdev);
 	poller_unregister(&vi->poller);
 	input_device_unregister(&vi->idev);
 	vdev->config->del_vqs(vdev);
-
-	kfree(vi);
 }
 
 static const struct virtio_device_id id_table[] = {
drivers/sound/core.c +10 -1
index 801b1fade552..aabcfee2822f 100644
@@ -18,6 +18,9 @@ struct beep {
 static int sound_card_do_beep(struct sound_card *card,
 			      int freq, unsigned int us)
 {
+	if (!card->beep)
+		return -ENODEV;
+
 	if (freq == -1)
 		freq = card->bell_frequency;
 
@@ -110,7 +113,7 @@ int sound_card_beep_cancel(struct sound_card *card)
 
 	poller_async_cancel(&card->poller);
 
-	ret = card->beep(card, 0, 0);
+	ret = sound_card_do_beep(card, 0, 0);
 
 	list_for_each_entry_safe(beep, tmp, &card->tune, list) {
 		list_del(&beep->list);
@@ -119,3 +122,9 @@ int sound_card_beep_cancel(struct sound_card *card)
 
 	return ret;
 }
+
+void sound_card_disable(struct sound_card *card)
+{
+	sound_card_beep_cancel(card);
+	card->beep = NULL;
+}
include/sound.h +6 -0
index 62fef106ee73..56c3c328d081 100644
@@ -25,6 +25,12 @@ int sound_card_beep_wait(struct sound_card *card, unsigned timeout_us);
 int sound_card_beep(struct sound_card *card, int freq, unsigned int us);
 int sound_card_beep_cancel(struct sound_card *card);
 
+#ifdef CONFIG_SOUND
+void sound_card_disable(struct sound_card *card);
+#else
+static inline void sound_card_disable(struct sound_card *card) {}
+#endif
+
 struct sound_card *sound_card_get_default(void);
 
 static inline int beep(int freq, unsigned us)
Signature · 1 line
2.47.3
Applied
#1 lore raw
Quoted 8 lines · Ahmad Fatoum

The sound card of a virtio keyboard is embedded in the driver's private data, which virtinput_remove() frees.

Drop the free and instead just disable the soundcard, so it can no longer beep. A proper fix would be to add support for unregistering sound cards, but that can follow after devm support lands.

[...]

Applied, thanks!

[1/1] input: virtio_input: don't free poller-enabled beeper on remove
https://git.pengutronix.de/cgit/barebox/commit/?id=4d054fece787 (link may not be stable)

Best regards,

Signature · 1 line
Sascha Hauer <[email protected]>