* [PATCH v2] ALSA: aoa: Skip devices with no codecs in i2sbus_resume()
@ 2026-03-10 10:29 Thorsten Blum
2026-03-10 15:07 ` Takashi Iwai
0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2026-03-10 10:29 UTC (permalink / raw)
To: Johannes Berg, Jaroslav Kysela, Takashi Iwai, Kees Cook
Cc: Thorsten Blum, stable, Takashi Iwai, linuxppc-dev, linux-sound,
linux-kernel
In i2sbus_resume(), skip devices with an empty codec list, which avoids
using an uninitialized 'sysclock_factor' in the 32-bit format path in
i2sbus_pcm_prepare().
In i2sbus_pcm_prepare(), replace two list_for_each_entry() loops with a
single list_first_entry() now that the codec list is guaranteed to be
non-empty by all callers.
Fixes: f3d9478b2ce4 ("[ALSA] snd-aoa: add snd-aoa")
Cc: stable@vger.kernel.org
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Changes in v2:
- Skip devices with no codecs in i2sbus_resume() and use
list_first_entry() in i2sbus_pcm_prepare() now that the codec list is
guaranteed to be non-empty by all callers (Takashi)
- Link to v1: https://lore.kernel.org/lkml/20260309114159.765304-3-thorsten.blum@linux.dev/
---
sound/aoa/soundbus/i2sbus/core.c | 3 +++
sound/aoa/soundbus/i2sbus/pcm.c | 16 +++++-----------
2 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/sound/aoa/soundbus/i2sbus/core.c b/sound/aoa/soundbus/i2sbus/core.c
index f974b96e98cd..22c956267f4e 100644
--- a/sound/aoa/soundbus/i2sbus/core.c
+++ b/sound/aoa/soundbus/i2sbus/core.c
@@ -405,6 +405,9 @@ static int i2sbus_resume(struct macio_dev* dev)
int err, ret = 0;
list_for_each_entry(i2sdev, &control->list, item) {
+ if (list_empty(&i2sdev->sound.codec_list))
+ continue;
+
/* reset i2s bus format etc. */
i2sbus_pcm_prepare_both(i2sdev);
diff --git a/sound/aoa/soundbus/i2sbus/pcm.c b/sound/aoa/soundbus/i2sbus/pcm.c
index aff99003d833..97c807e67d56 100644
--- a/sound/aoa/soundbus/i2sbus/pcm.c
+++ b/sound/aoa/soundbus/i2sbus/pcm.c
@@ -383,6 +383,9 @@ static int i2sbus_pcm_prepare(struct i2sbus_dev *i2sdev, int in)
/* set stop command */
command->command = cpu_to_le16(DBDMA_STOP);
+ cii = list_first_entry(&i2sdev->sound.codec_list,
+ struct codec_info_item, list);
+
/* ok, let's set the serial format and stuff */
switch (runtime->format) {
/* 16 bit formats */
@@ -390,13 +393,7 @@ static int i2sbus_pcm_prepare(struct i2sbus_dev *i2sdev, int in)
case SNDRV_PCM_FORMAT_U16_BE:
/* FIXME: if we add different bus factors we need to
* do more here!! */
- bi.bus_factor = 0;
- list_for_each_entry(cii, &i2sdev->sound.codec_list, list) {
- bi.bus_factor = cii->codec->bus_factor;
- break;
- }
- if (!bi.bus_factor)
- return -ENODEV;
+ bi.bus_factor = cii->codec->bus_factor;
input_16bit = 1;
break;
case SNDRV_PCM_FORMAT_S32_BE:
@@ -410,10 +407,7 @@ static int i2sbus_pcm_prepare(struct i2sbus_dev *i2sdev, int in)
return -EINVAL;
}
/* we assume all sysclocks are the same! */
- list_for_each_entry(cii, &i2sdev->sound.codec_list, list) {
- bi.sysclock_factor = cii->codec->sysclock_factor;
- break;
- }
+ bi.sysclock_factor = cii->codec->sysclock_factor;
if (clock_and_divisors(bi.sysclock_factor,
bi.bus_factor,
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ALSA: aoa: Skip devices with no codecs in i2sbus_resume()
2026-03-10 10:29 [PATCH v2] ALSA: aoa: Skip devices with no codecs in i2sbus_resume() Thorsten Blum
@ 2026-03-10 15:07 ` Takashi Iwai
2026-03-10 16:30 ` Thorsten Blum
0 siblings, 1 reply; 4+ messages in thread
From: Takashi Iwai @ 2026-03-10 15:07 UTC (permalink / raw)
To: Thorsten Blum
Cc: Johannes Berg, Jaroslav Kysela, Takashi Iwai, Kees Cook, stable,
Takashi Iwai, linuxppc-dev, linux-sound, linux-kernel
On Tue, 10 Mar 2026 11:29:20 +0100,
Thorsten Blum wrote:
> --- a/sound/aoa/soundbus/i2sbus/core.c
> +++ b/sound/aoa/soundbus/i2sbus/core.c
> @@ -405,6 +405,9 @@ static int i2sbus_resume(struct macio_dev* dev)
> int err, ret = 0;
>
> list_for_each_entry(i2sdev, &control->list, item) {
> + if (list_empty(&i2sdev->sound.codec_list))
> + continue;
This can be even outside the loop and immediately return 0, as the
remaining part is also the loop of codec_list.
int err, ret = 0;
+ if (list_empty(&i2sdev->sound.codec_list))
+ return 0;
+
list_for_each_entry(i2sdev, &control->list, item) {
/* reset i2s bus format etc. */
i2sbus_pcm_prepare_both(i2sdev);
thanks,
Takashi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ALSA: aoa: Skip devices with no codecs in i2sbus_resume()
2026-03-10 15:07 ` Takashi Iwai
@ 2026-03-10 16:30 ` Thorsten Blum
2026-03-10 17:21 ` Takashi Iwai
0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2026-03-10 16:30 UTC (permalink / raw)
To: Takashi Iwai
Cc: Johannes Berg, Jaroslav Kysela, Takashi Iwai, Kees Cook, stable,
linuxppc-dev, linux-sound, linux-kernel
On 10. Mar 2026, at 16:07, Takashi Iwai wrote:
> On Tue, 10 Mar 2026 11:29:20 +0100, Thorsten Blum wrote:
>> --- a/sound/aoa/soundbus/i2sbus/core.c
>> +++ b/sound/aoa/soundbus/i2sbus/core.c
>> @@ -405,6 +405,9 @@ static int i2sbus_resume(struct macio_dev* dev)
>> int err, ret = 0;
>>
>> list_for_each_entry(i2sdev, &control->list, item) {
>> + if (list_empty(&i2sdev->sound.codec_list))
>> + continue;
>
> This can be even outside the loop and immediately return 0, as the
> remaining part is also the loop of codec_list.
The i2sdev pointer is only assigned by the outer list_for_each_entry(),
which iterates the controller's device list. Since each device has its
own codec list, list_empty(&i2sdev->sound.codec_list) must be checked
inside the loop; before the loop i2sdev is uninitialized.
Thanks,
Thorsten
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ALSA: aoa: Skip devices with no codecs in i2sbus_resume()
2026-03-10 16:30 ` Thorsten Blum
@ 2026-03-10 17:21 ` Takashi Iwai
0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2026-03-10 17:21 UTC (permalink / raw)
To: Thorsten Blum
Cc: Takashi Iwai, Johannes Berg, Jaroslav Kysela, Takashi Iwai,
Kees Cook, stable, linuxppc-dev, linux-sound, linux-kernel
On Tue, 10 Mar 2026 17:30:01 +0100,
Thorsten Blum wrote:
>
> On 10. Mar 2026, at 16:07, Takashi Iwai wrote:
> > On Tue, 10 Mar 2026 11:29:20 +0100, Thorsten Blum wrote:
> >> --- a/sound/aoa/soundbus/i2sbus/core.c
> >> +++ b/sound/aoa/soundbus/i2sbus/core.c
> >> @@ -405,6 +405,9 @@ static int i2sbus_resume(struct macio_dev* dev)
> >> int err, ret = 0;
> >>
> >> list_for_each_entry(i2sdev, &control->list, item) {
> >> + if (list_empty(&i2sdev->sound.codec_list))
> >> + continue;
> >
> > This can be even outside the loop and immediately return 0, as the
> > remaining part is also the loop of codec_list.
>
> The i2sdev pointer is only assigned by the outer list_for_each_entry(),
> which iterates the controller's device list. Since each device has its
> own codec list, list_empty(&i2sdev->sound.codec_list) must be checked
> inside the loop; before the loop i2sdev is uninitialized.
Ah indeed. Now I applied to for-next branch.
thanks,
Takashi
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-10 17:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-10 10:29 [PATCH v2] ALSA: aoa: Skip devices with no codecs in i2sbus_resume() Thorsten Blum
2026-03-10 15:07 ` Takashi Iwai
2026-03-10 16:30 ` Thorsten Blum
2026-03-10 17:21 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox