Skip to contentSkip to conversation

ALSA: kunit: make read-only array buf_samples static const

PATCH Applied Colin Ian King 4 participants 7 messages Apr 25, 2024 – Apr 26, 2024

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

PATCH 1/1 ALSA: kunit: make read-only array buf_samples static const

Don't populate the read-only array buf_samples on the stack at run time, instead make it static const.

---
 sound/core/sound_kunit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/sound_kunit.c +1 -1
index eb90f62228c0..e34c4317f5eb 100644
@@ -167,7 +167,7 @@ static void _test_fill_silence(struct kunit *test, struct snd_format_test_data *
 
 static void test_format_fill_silence(struct kunit *test)
 {
-	u32 buf_samples[] = { 10, 20, 32, 64, 129, SILENCE_BUFFER_MAX_FRAMES };
+	static const u32 buf_samples[] = { 10, 20, 32, 64, 129, SILENCE_BUFFER_MAX_FRAMES };
 	u8 *buffer;
 	u32 i, j;
 
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 13 lines · Colin Ian King

Don't populate the read-only array buf_samples on the stack at run time, instead make it static const.

---
 sound/core/sound_kunit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/sound_kunit.c +0 -0
index eb90f62228c0..e34c4317f5eb 100644

sound/core/sound_kunit.c static void _test_fill_silence(struct kunit *test, struct snd_format_test_data * · line 172

Quoted 7 lines
sound/core/sound_kunit.c +1 -1
@@ -167,7 +167,7 @@ static void _test_fill_silence(struct kunit *test, struct snd_format_test_data *
 
 static void test_format_fill_silence(struct kunit *test)
 {
-	u32 buf_samples[] = { 10, 20, 32, 64, 129, SILENCE_BUFFER_MAX_FRAMES };
+	static const u32 buf_samples[] = { 10, 20, 32, 64, 129, SILENCE_BUFFER_MAX_FRAMES };
 	u8 *buffer;
 	u32 i, j;

We can see the other similar cases in the kunit file. I'll post the fix later.

Thanks

Takashi Sakamoto

maintainer
#2 lore raw
Quoted 26 lines · Takashi Sakamoto

Hi,

Quoted 13 lines · Colin Ian King

Don't populate the read-only array buf_samples on the stack at run time, instead make it static const.

---
  sound/core/sound_kunit.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/sound_kunit.c +0 -0
index eb90f62228c0..e34c4317f5eb 100644

sound/core/sound_kunit.c static void _test_fill_silence(struct kunit *test, struct snd_format_test_data * · line 172

Quoted 7 lines
sound/core/sound_kunit.c +1 -1
@@ -167,7 +167,7 @@ static void _test_fill_silence(struct kunit *test, struct snd_format_test_data *
 
  static void test_format_fill_silence(struct kunit *test)
  {
-	u32 buf_samples[] = { 10, 20, 32, 64, 129, SILENCE_BUFFER_MAX_FRAMES };
+	static const u32 buf_samples[] = { 10, 20, 32, 64, 129, SILENCE_BUFFER_MAX_FRAMES };
  	u8 *buffer;
  	u32 i, j;
Quoted 3 lines

We can see the other similar cases in the kunit file. I'll post the fix later.

Hi Takashi,

Hmm, correct me if I'm wrong, but I don't see any other significant allocations on the stack in the test.

Signature · 2 lines
Kind regards,
Ivan Orlov
#3 lore raw
Quoted 27 lines · Ivan Orlov
Quoted 25 lines · Takashi Sakamoto

Hi,

Quoted 13 lines · Colin Ian King

Don't populate the read-only array buf_samples on the stack at run time, instead make it static const.

---
  sound/core/sound_kunit.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/sound_kunit.c +0 -0
index eb90f62228c0..e34c4317f5eb 100644

sound/core/sound_kunit.c static void _test_fill_silence(struct kunit *test, struct snd_format_test_data * · line 171

Quoted 6 lines
sound/core/sound_kunit.c +1 -1
@@ -167,7 +167,7 @@ static void _test_fill_silence(struct kunit *test, struct snd_format_test_data *
    static void test_format_fill_silence(struct kunit *test)
  {
-	u32 buf_samples[] = { 10, 20, 32, 64, 129, SILENCE_BUFFER_MAX_FRAMES };
+	static const u32 buf_samples[] = { 10, 20, 32, 64, 129, SILENCE_BUFFER_MAX_FRAMES };
  	u8 *buffer;
  	u32 i, j;
Quoted 8 lines
Quoted 3 lines

We can see the other similar cases in the kunit file. I'll post the fix later.

Hi Takashi,

Hmm, correct me if I'm wrong, but I don't see any other significant allocations on the stack in the test.

I guess he meant slightly different ones
https://lore.kernel.org/r/[email protected]

Takashi

maintainer
#4 lore raw
Quoted 33 lines · Takashi Iwai
Quoted 31 lines · Ivan Orlov
Quoted 28 lines · Takashi Sakamoto

Hi,

Quoted 13 lines · Colin Ian King

Don't populate the read-only array buf_samples on the stack at run time, instead make it static const.

---
   sound/core/sound_kunit.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/sound_kunit.c +0 -0
index eb90f62228c0..e34c4317f5eb 100644

sound/core/sound_kunit.c static void _test_fill_silence(struct kunit *test, struct snd_format_test_data * · line 171

Quoted 6 lines
sound/core/sound_kunit.c +1 -1
@@ -167,7 +167,7 @@ static void _test_fill_silence(struct kunit *test, struct snd_format_test_data *
     static void test_format_fill_silence(struct kunit *test)
   {
-	u32 buf_samples[] = { 10, 20, 32, 64, 129, SILENCE_BUFFER_MAX_FRAMES };
+	static const u32 buf_samples[] = { 10, 20, 32, 64, 129, SILENCE_BUFFER_MAX_FRAMES };
   	u8 *buffer;
   	u32 i, j;

We can see the other similar cases in the kunit file. I'll post the fix later.

Quoted 8 lines
Quoted 4 lines

Hi Takashi,

Hmm, correct me if I'm wrong, but I don't see any other significant allocations on the stack in the test.

I guess he meant slightly different ones
https://lore.kernel.org/r/[email protected]

Ah, alright, found it. Thank you!

Signature · 2 lines
Kind regards,
Ivan Orlov
maintainer Acked-by on v1 1/1
#5 lore raw
In reply to Colin Ian King
Quoted 13 lines · Colin Ian King

Don't populate the read-only array buf_samples on the stack at run time, instead make it static const.

---
  sound/core/sound_kunit.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/sound_kunit.c +0 -0
index eb90f62228c0..e34c4317f5eb 100644

sound/core/sound_kunit.c static void _test_fill_silence(struct kunit *test, struct snd_format_test_data * · line 173

Quoted 8 lines
sound/core/sound_kunit.c +1 -1
@@ -167,7 +167,7 @@ static void _test_fill_silence(struct kunit *test, struct snd_format_test_data *
 
  static void test_format_fill_silence(struct kunit *test)
  {
-	u32 buf_samples[] = { 10, 20, 32, 64, 129, SILENCE_BUFFER_MAX_FRAMES };
+	static const u32 buf_samples[] = { 10, 20, 32, 64, 129, SILENCE_BUFFER_MAX_FRAMES };
  	u8 *buffer;
  	u32 i, j;
 

Hi Colin,

Thank you for fixing this issue.

Signature · 2 lines
Kind regards,
Ivan Orlov