Skip to contentSkip to conversation

Using ARRAY_SIZE macro when setting up ASoC audio map?

PATCH Jarkko Nikula 3 participants 6 messages Feb 27, 2008 – Feb 28, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Does an example patch to spitz below make any sense? Yep, noticed when forgot to add array terminator to own code :-)

sound/soc/pxa/spitz.c +1 -3
index d56709e..1cffcd3 100644
@@ -268,8 +268,6 @@ static const char *audio_map[][3] = {
 
 	/* line is connected to input 1 - no bias */
 	{"LINPUT1", NULL, "Line Jack"},
-
-	{NULL, NULL, NULL},
 };
 
 static const char *jack_function[] = {"Headphone", "Mic", "Line", "Headset",
@@ -317,7 +315,7 @@ static int spitz_wm8750_init(struct snd_soc_codec *codec)
 	}
 
 	/* Set up spitz specific audio path audio_map */
-	for (i = 0; audio_map[i][0] != NULL; i++) {
+	for (i = 0; i < ARRAY_SIZE(audio_map); i++) {
 		snd_soc_dapm_connect_input(codec, audio_map[i][0],
 			audio_map[i][1], audio_map[i][2]);
 	}
#1 lore raw
Quoted 1 line · Jarkko Nikula

Does an example patch to spitz below make any sense? Yep, noticed when forgot to add array terminator to own code :-)

Yes, sure.

#2 lore raw
Quoted 6 lines · On Wed, 27 Feb 2008 12:34:18 +0000 "ext Mark Brown"…
Quoted 2 lines · Jarkko Nikula

Does an example patch to spitz below make any sense? Yep, noticed when forgot to add array terminator to own code :-)

Yes, sure.

Ok. Probably not worth to change now to n different drivers but worth to take into account when reviewing new ones or doing some other cleanups.

Signature · 1 line
Jarkko
#3 lore raw
Quoted 3 lines · Jarkko Nikula

Ok. Probably not worth to change now to n different drivers but worth to take into account when reviewing new ones or doing some other cleanups.

For ASoC v2 we've been adding bulk registration functions for everything which should encourage that. This hasn't been done for paths yet but that should be done shortly.

#4 lore raw
In reply to Jarkko Nikula

At Wed, 27 Feb 2008 13:49:23 +0200,

Quoted 17 lines · Jarkko Nikula

Does an example patch to spitz below make any sense? Yep, noticed when forgot to add array terminator to own code :-)

sound/soc/pxa/spitz.c +0 -2
index d56709e..1cffcd3 100644
@@ -268,8 +268,6 @@ static const char *audio_map[][3] = {
 
 	/* line is connected to input 1 - no bias */
 	{"LINPUT1", NULL, "Line Jack"},
-
-	{NULL, NULL, NULL},
 };
 
 static const char *jack_function[] = {"Headphone", "Mic", "Line", "Headset",

sound/soc/pxa/spitz.c static int spitz_wm8750_init(struct snd_soc_codec *codec) · line 318

Quoted 5 lines
sound/soc/pxa/spitz.c +1 -1
@@ -317,7 +315,7 @@ static int spitz_wm8750_init(struct snd_soc_codec *codec)
 	}
 
 	/* Set up spitz specific audio path audio_map */
-	for (i = 0; audio_map[i][0] != NULL; i++) {
+	for (i = 0; i < ARRAY_SIZE(audio_map); i++) {

Does ARRAY_SIZE() work with two-dimensional arrays? Just wondering...

Takashi

#5 lore raw
Quoted 6 lines · On Wed, 27 Feb 2008 17:15:49 +0100 "ext Takashi Iwai" <[email protected]> wrote:

sound/soc/pxa/spitz.c static int spitz_wm8750_init(struct snd_soc_codec *codec) · line 318

Quoted 3 lines
sound/soc/pxa/spitz.c +1 -1
 	/* Set up spitz specific audio path audio_map */
-	for (i = 0; audio_map[i][0] != NULL; i++) {
+	for (i = 0; i < ARRAY_SIZE(audio_map); i++) {

Does ARRAY_SIZE() work with two-dimensional arrays? Just wondering...

Yes it does when counting number of rows since sizeof(arr[0]) operator in ARRAY_SIZE returns a row size in bytes when used with two-dimensional array.

Signature · 1 line
Jarkko