kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ALSA: firewire-lib: Fix 'amdtp_domain_start()' when no AMDTP_OUT_STREAM stream is found
@ 2021-06-24 18:49 Christophe JAILLET
  2021-06-24 21:05 ` Takashi Sakamoto
  2021-06-25  7:38 ` Takashi Iwai
  0 siblings, 2 replies; 4+ messages in thread
From: Christophe JAILLET @ 2021-06-24 18:49 UTC (permalink / raw)
  To: clemens, o-takashi, perex, tiwai
  Cc: alsa-devel, linux-kernel, kernel-janitors, Christophe JAILLET

The intent here is to return an error code if we don't find what we are
looking for in the 'list_for_each_entry()' loop.

's' is not NULL if the list is empty or if we scan the complete list.
Introduce a new 'found' variable to handle such cases.

Fixes: 60dd49298ec5 ("ALSA: firewire-lib: handle several AMDTP streams in callback handler of IRQ target")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
We could test with" if (list_entry_is_head(s, &d->streams, list))"
instead, but I find it much less readable.
---
 sound/firewire/amdtp-stream.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c
index aad9778d1c4d..9be2260e4ca2 100644
--- a/sound/firewire/amdtp-stream.c
+++ b/sound/firewire/amdtp-stream.c
@@ -1943,6 +1943,7 @@ int amdtp_domain_start(struct amdtp_domain *d, unsigned int tx_init_skip_cycles,
 	unsigned int events_per_period = d->events_per_period;
 	unsigned int queue_size;
 	struct amdtp_stream *s;
+	bool found = false;
 	int err;
 
 	if (replay_seq) {
@@ -1955,10 +1956,12 @@ int amdtp_domain_start(struct amdtp_domain *d, unsigned int tx_init_skip_cycles,
 
 	// Select an IT context as IRQ target.
 	list_for_each_entry(s, &d->streams, list) {
-		if (s->direction == AMDTP_OUT_STREAM)
+		if (s->direction == AMDTP_OUT_STREAM) {
+			found = true;
 			break;
+		}
 	}
-	if (!s)
+	if (!found)
 		return -ENXIO;
 	d->irq_target = s;
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ALSA: firewire-lib: Fix 'amdtp_domain_start()' when no AMDTP_OUT_STREAM stream is found
  2021-06-24 18:49 [PATCH] ALSA: firewire-lib: Fix 'amdtp_domain_start()' when no AMDTP_OUT_STREAM stream is found Christophe JAILLET
@ 2021-06-24 21:05 ` Takashi Sakamoto
  2021-06-25  9:05   ` Dan Carpenter
  2021-06-25  7:38 ` Takashi Iwai
  1 sibling, 1 reply; 4+ messages in thread
From: Takashi Sakamoto @ 2021-06-24 21:05 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: clemens, perex, tiwai, alsa-devel, linux-kernel, kernel-janitors

Hi,

On Thu, Jun 24, 2021 at 08:49:36PM +0200, Christophe JAILLET wrote:
> The intent here is to return an error code if we don't find what we are
> looking for in the 'list_for_each_entry()' loop.
> 
> 's' is not NULL if the list is empty or if we scan the complete list.
> Introduce a new 'found' variable to handle such cases.
> 
> Fixes: 60dd49298ec5 ("ALSA: firewire-lib: handle several AMDTP streams in callback handler of IRQ target")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> We could test with" if (list_entry_is_head(s, &d->streams, list))"
> instead, but I find it much less readable.
> ---
>  sound/firewire/amdtp-stream.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c
> index aad9778d1c4d..9be2260e4ca2 100644
> --- a/sound/firewire/amdtp-stream.c
> +++ b/sound/firewire/amdtp-stream.c
> @@ -1943,6 +1943,7 @@ int amdtp_domain_start(struct amdtp_domain *d, unsigned int tx_init_skip_cycles,
>  	unsigned int events_per_period = d->events_per_period;
>  	unsigned int queue_size;
>  	struct amdtp_stream *s;
> +	bool found = false;
>  	int err;
>  
>  	if (replay_seq) {
> @@ -1955,10 +1956,12 @@ int amdtp_domain_start(struct amdtp_domain *d, unsigned int tx_init_skip_cycles,
>  
>  	// Select an IT context as IRQ target.
>  	list_for_each_entry(s, &d->streams, list) {
> -		if (s->direction == AMDTP_OUT_STREAM)
> +		if (s->direction == AMDTP_OUT_STREAM) {
> +			found = true;
>  			break;
> +		}
>  	}
> -	if (!s)
> +	if (!found)
>  		return -ENXIO;
>  	d->irq_target = s;
>  
> -- 
> 2.30.2

Indeed. Nice to catch it. The bug affects Linux kernel v5.5 or later.

Acked-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>

In kernel v5.10 or later, we can use 'list_entry_is_head()' macro added
by a commit e130816164e2 ("include/linux/list.h: add a macro to test if
entry is pointing to the head"). However the development of ALSA firewire
stack is out-of-tree repository for my convenience to backport it to kernel
v4.17 or later (I need testers...), so I prefer your change.


Thanks

Takashi Sakamoto

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ALSA: firewire-lib: Fix 'amdtp_domain_start()' when no AMDTP_OUT_STREAM stream is found
  2021-06-24 18:49 [PATCH] ALSA: firewire-lib: Fix 'amdtp_domain_start()' when no AMDTP_OUT_STREAM stream is found Christophe JAILLET
  2021-06-24 21:05 ` Takashi Sakamoto
@ 2021-06-25  7:38 ` Takashi Iwai
  1 sibling, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2021-06-25  7:38 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: clemens, o-takashi, perex, tiwai, alsa-devel, linux-kernel,
	kernel-janitors

On Thu, 24 Jun 2021 20:49:36 +0200,
Christophe JAILLET wrote:
> 
> The intent here is to return an error code if we don't find what we are
> looking for in the 'list_for_each_entry()' loop.
> 
> 's' is not NULL if the list is empty or if we scan the complete list.
> Introduce a new 'found' variable to handle such cases.
> 
> Fixes: 60dd49298ec5 ("ALSA: firewire-lib: handle several AMDTP streams in callback handler of IRQ target")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Applied now.  Thanks.


Takashi


> ---
> We could test with" if (list_entry_is_head(s, &d->streams, list))"
> instead, but I find it much less readable.
> ---
>  sound/firewire/amdtp-stream.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c
> index aad9778d1c4d..9be2260e4ca2 100644
> --- a/sound/firewire/amdtp-stream.c
> +++ b/sound/firewire/amdtp-stream.c
> @@ -1943,6 +1943,7 @@ int amdtp_domain_start(struct amdtp_domain *d, unsigned int tx_init_skip_cycles,
>  	unsigned int events_per_period = d->events_per_period;
>  	unsigned int queue_size;
>  	struct amdtp_stream *s;
> +	bool found = false;
>  	int err;
>  
>  	if (replay_seq) {
> @@ -1955,10 +1956,12 @@ int amdtp_domain_start(struct amdtp_domain *d, unsigned int tx_init_skip_cycles,
>  
>  	// Select an IT context as IRQ target.
>  	list_for_each_entry(s, &d->streams, list) {
> -		if (s->direction == AMDTP_OUT_STREAM)
> +		if (s->direction == AMDTP_OUT_STREAM) {
> +			found = true;
>  			break;
> +		}
>  	}
> -	if (!s)
> +	if (!found)
>  		return -ENXIO;
>  	d->irq_target = s;
>  
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ALSA: firewire-lib: Fix 'amdtp_domain_start()' when no AMDTP_OUT_STREAM stream is found
  2021-06-24 21:05 ` Takashi Sakamoto
@ 2021-06-25  9:05   ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2021-06-25  9:05 UTC (permalink / raw)
  To: Christophe JAILLET, clemens, perex, tiwai, alsa-devel,
	linux-kernel, kernel-janitors

On Fri, Jun 25, 2021 at 06:05:50AM +0900, Takashi Sakamoto wrote:
> 
> In kernel v5.10 or later, we can use 'list_entry_is_head()' macro added
> by a commit e130816164e2 ("include/linux/list.h: add a macro to test if
> entry is pointing to the head").

Someone needs to backport that all the way back...

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-25  9:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-24 18:49 [PATCH] ALSA: firewire-lib: Fix 'amdtp_domain_start()' when no AMDTP_OUT_STREAM stream is found Christophe JAILLET
2021-06-24 21:05 ` Takashi Sakamoto
2021-06-25  9:05   ` Dan Carpenter
2021-06-25  7:38 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).