Skip to contentSkip to conversation

ALSA: vmaster: Propagate slave error

PATCH New Takashi Iwai 1 participant 2 messages Mar 8, 2018 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ALSA: vmaster: Propagate slave error

In slave_update() of vmaster code ignores the error from the slave get() callback and copies the values. It's not only about the missing error code but also that this may potentially lead to a leak of uninitialized variables when the slave get() don't clear them.

This patch fixes slave_update() not to copy the potentially uninitialized values when an error is returned from the slave get() callback, and to propagate the error value properly.

---
 sound/core/vmaster.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
sound/core/vmaster.c +4 -1
index 8632301489fa..b67de2bb06a2 100644
@@ -68,10 +68,13 @@ static int slave_update(struct link_slave *slave)
 		return -ENOMEM;
 	uctl->id = slave->slave.id;
 	err = slave->slave.get(&slave->slave, uctl);
+	if (err < 0)
+		goto error;
 	for (ch = 0; ch < slave->info.count; ch++)
 		slave->vals[ch] = uctl->value.integer.value[ch];
+ error:
 	kfree(uctl);
-	return 0;
+	return err < 0 ? err : 0;
 }
 
 /* get the slave ctl info and save the initial values */
Signature · 1 line
2.16.2
#1 lore raw

PATCH 2/2 ALSA: vmaster: Zero-clear ctl before calling slave get

Use kzalloc() instead of kmalloc() so that we don't need to rely fully on the slave get() callback to clear the control value that might be copied to user-space.

---
 sound/core/vmaster.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/vmaster.c +1 -1
index b67de2bb06a2..9e96186742d0 100644
@@ -63,7 +63,7 @@ static int slave_update(struct link_slave *slave)
 	struct snd_ctl_elem_value *uctl;
 	int err, ch;
 
-	uctl = kmalloc(sizeof(*uctl), GFP_KERNEL);
+	uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
 	if (!uctl)
 		return -ENOMEM;
 	uctl->id = slave->slave.id;
Signature · 1 line
2.16.2