Skip to contentSkip to conversation

ALSA: control: Use list_for_each_entry_safe()

PATCH Superseded Andy Shevchenko 2 participants 3 messages Apr 23, 2024 – Apr 24, 2024 Sound

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ALSA: control: Use list_for_each_entry_safe()

Instead of reiterating the list, use list_for_each_entry_safe() that allows to continue without starting over.

---
v2: added tag (Jaroslav)

 sound/core/control_led.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
sound/core/control_led.c +3 -6
index 061a8ea23340..ea95405c76a4 100644
@@ -290,16 +290,13 @@ static void snd_ctl_led_clean(struct snd_card *card)
 {
 	unsigned int group;
 	struct snd_ctl_led *led;
-	struct snd_ctl_led_ctl *lctl;
+	struct snd_ctl_led_ctl *lctl, *_lctl;
 
 	for (group = 0; group < MAX_LED; group++) {
 		led = &snd_ctl_leds[group];
-repeat:
-		list_for_each_entry(lctl, &led->controls, list)
-			if (!card || lctl->card == card) {
+		list_for_each_entry_safe(lctl, _lctl, &led->controls, list)
+			if (!card || lctl->card == card)
 				snd_ctl_led_ctl_destroy(lctl);
-				goto repeat;
-			}
 	}
 }
 
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#1 lore raw
Quoted 8 lines · Andy Shevchenko

Instead of reiterating the list, use list_for_each_entry_safe() that allows to continue without starting over.

---
v2: added tag (Jaroslav)

We have a similar repeat in snd_ctl_led_reset().
Wouldn't it be better to catch both?

thanks,

Takashi

Quoted 30 lines
 sound/core/control_led.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
sound/core/control_led.c +3 -6
index 061a8ea23340..ea95405c76a4 100644
@@ -290,16 +290,13 @@ static void snd_ctl_led_clean(struct snd_card *card)
 {
 	unsigned int group;
 	struct snd_ctl_led *led;
-	struct snd_ctl_led_ctl *lctl;
+	struct snd_ctl_led_ctl *lctl, *_lctl;
 
 	for (group = 0; group < MAX_LED; group++) {
 		led = &snd_ctl_leds[group];
-repeat:
-		list_for_each_entry(lctl, &led->controls, list)
-			if (!card || lctl->card == card) {
+		list_for_each_entry_safe(lctl, _lctl, &led->controls, list)
+			if (!card || lctl->card == card)
 				snd_ctl_led_ctl_destroy(lctl);
-				goto repeat;
-			}
 	}
 }
 
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#2 lore raw
Quoted 6 lines · Takashi Iwai
Quoted 4 lines · Andy Shevchenko

Instead of reiterating the list, use list_for_each_entry_safe() that allows to continue without starting over.

Quoted 7 lines
Quoted 4 lines

---
v2: added tag (Jaroslav)

We have a similar repeat in snd_ctl_led_reset().
Wouldn't it be better to catch both?

Sure, v3 is on its way.

Signature · 2 lines
With Best Regards,
Andy Shevchenko