Skip to contentSkip to conversation

ALSA: control: Fix unannotated kfree() cleanup

PATCH In review Takashi Iwai 2 participants 2 messages Mar 20, 2024 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: control: Fix unannotated kfree() cleanup

The recent conversion to the automatic kfree() forgot to mark a variable with __free(kfree), leading to memory leaks. Fix it.

Fixes 1052d9882269 ("ALSA: control: Use automatic cleanup of kfree()")
---
 sound/core/control.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/core/control.c +2 -2
index 8367fd485371..fb0c60044f7b 100644
@@ -1275,12 +1275,12 @@ static int snd_ctl_elem_read(struct snd_card *card,
 static int snd_ctl_elem_read_user(struct snd_card *card,
 				  struct snd_ctl_elem_value __user *_control)
 {
-	struct snd_ctl_elem_value *control;
+	struct snd_ctl_elem_value *control __free(kfree) = NULL;
 	int result;
 
 	control = memdup_user(_control, sizeof(*control));
 	if (IS_ERR(control))
-		return PTR_ERR(control);
+		return PTR_ERR(no_free_ptr(control));
 
 	result = snd_ctl_elem_read(card, control);
 	if (result < 0)
Signature · 1 line
2.43.0
Tested-by on v1 1/1
#1 lore raw
Quoted 20 lines · Takashi Iwai

The recent conversion to the automatic kfree() forgot to mark a variable with __free(kfree), leading to memory leaks. Fix it.

Fixes 1052d9882269 ("ALSA: control: Use automatic cleanup of kfree()")
---
  sound/core/control.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
sound/core/control.c +0 -1
index 8367fd485371..fb0c60044f7b 100644
@@ -1275,12 +1275,12 @@ static int snd_ctl_elem_read(struct snd_card *card,
  static int snd_ctl_elem_read_user(struct snd_card *card,
  				  struct snd_ctl_elem_value __user *_control)
  {
-	struct snd_ctl_elem_value *control;

sound/core/control.c static int snd_ctl_elem_read(struct snd_card *card, · line 1286

Quoted 10 lines
sound/core/control.c +2 -1
+	struct snd_ctl_elem_value *control __free(kfree) = NULL;
  	int result;
 
  	control = memdup_user(_control, sizeof(*control));
  	if (IS_ERR(control))
-		return PTR_ERR(control);
+		return PTR_ERR(no_free_ptr(control));
 
  	result = snd_ctl_elem_read(card, control);
  	if (result < 0)

Hi,

Thanks for the fix at such a short notice.

Just re-ran the kselftests for alsa, so far no kmemleak.

The test was done in the same environment, Ubuntu 22.04 LTS with torvalds tree kernel (vanilla v6.8-11743-ga4145ce1e7bc + fixes).

You can add:

at your convenience.

Best regards,
Mirsad Todorovac