diff mbox series

[v2,1/1] ALSA: control: Use list_for_each_entry_safe()

Message ID 20240423211102.3785556-1-andriy.shevchenko@linux.intel.com (mailing list archive)
State Superseded
Headers show
Series [v2,1/1] ALSA: control: Use list_for_each_entry_safe() | expand

Commit Message

Andy Shevchenko April 23, 2024, 9:10 p.m. UTC
Instead of reiterating the list, use list_for_each_entry_safe()
that allows to continue without starting over.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Jaroslav Kysela <perex@perex.cz>
---
v2: added tag (Jaroslav)
 sound/core/control_led.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Takashi Iwai April 24, 2024, 7:24 a.m. UTC | #1
On Tue, 23 Apr 2024 23:10:22 +0200,
Andy Shevchenko wrote:
> 
> Instead of reiterating the list, use list_for_each_entry_safe()
> that allows to continue without starting over.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Reviewed-by: Jaroslav Kysela <perex@perex.cz>
> ---
> v2: added tag (Jaroslav)

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


thanks,

Takashi

>  sound/core/control_led.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/sound/core/control_led.c b/sound/core/control_led.c
> index 061a8ea23340..ea95405c76a4 100644
> --- a/sound/core/control_led.c
> +++ b/sound/core/control_led.c
> @@ -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;
> -			}
>  	}
>  }
>  
> -- 
> 2.43.0.rc1.1336.g36b5255a03ac
>
Andy Shevchenko April 24, 2024, 2:49 p.m. UTC | #2
On Wed, Apr 24, 2024 at 09:24:49AM +0200, Takashi Iwai wrote:
> On Tue, 23 Apr 2024 23:10:22 +0200,
> Andy Shevchenko wrote:
> > 
> > Instead of reiterating the list, use list_for_each_entry_safe()
> > that allows to continue without starting over.
> > 
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > Reviewed-by: Jaroslav Kysela <perex@perex.cz>
> > ---
> > 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.
diff mbox series

Patch

diff --git a/sound/core/control_led.c b/sound/core/control_led.c
index 061a8ea23340..ea95405c76a4 100644
--- a/sound/core/control_led.c
+++ b/sound/core/control_led.c
@@ -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;
-			}
 	}
 }