diff mbox series

kselftest/alsa: Fix -Wformat compiler warnings

Message ID 20230324092806.363253-1-hallo@alexanderheinrich.de (mailing list archive)
State Accepted
Commit bd574889c25d2ed7e3d61d784c59a539a95f0167
Headers show
Series kselftest/alsa: Fix -Wformat compiler warnings | expand

Commit Message

Alexander Heinrich March 24, 2023, 9:28 a.m. UTC
I noticed some -Wformat compiler warnings in pcm-test.c while building
kselftest, fix them by using the same types for format specifier and arguments.

Signed-off-by: Alexander Heinrich <hallo@alexanderheinrich.de>
---
 tools/testing/selftests/alsa/pcm-test.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Takashi Iwai March 24, 2023, 9:43 a.m. UTC | #1
On Fri, 24 Mar 2023 10:28:06 +0100,
Alexander Heinrich wrote:
> 
> I noticed some -Wformat compiler warnings in pcm-test.c while building
> kselftest, fix them by using the same types for format specifier and arguments.
> 
> Signed-off-by: Alexander Heinrich <hallo@alexanderheinrich.de>

Those variables (rates, channels, etc) should be rather int instead of
long, as these are not 64bit parameters on 32bit archs.
On top of that, the whole '%l' prefix and cast should be dropped.

The only concern is the string to int conversion, and this should be
checked carefully, but other than that, it must be straightforward.

Care to work on that way?


thanks,

Takashi

> ---
>  tools/testing/selftests/alsa/pcm-test.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/selftests/alsa/pcm-test.c b/tools/testing/selftests/alsa/pcm-test.c
> index 58b525a4a32c..44fc5f826ab5 100644
> --- a/tools/testing/selftests/alsa/pcm-test.c
> +++ b/tools/testing/selftests/alsa/pcm-test.c
> @@ -371,7 +371,7 @@ static void test_pcm_time(struct pcm_data *data, enum test_class class,
>  		goto __close;
>  	}
>  	if (rrate != rate) {
> -		snprintf(msg, sizeof(msg), "rate mismatch %ld != %ld", rate, rrate);
> +		snprintf(msg, sizeof(msg), "rate mismatch %ld != %d", rate, rrate);
>  		goto __close;
>  	}
>  	rperiod_size = period_size;
> @@ -437,24 +437,24 @@ static void test_pcm_time(struct pcm_data *data, enum test_class class,
>  			frames = snd_pcm_writei(handle, samples, rate);
>  			if (frames < 0) {
>  				snprintf(msg, sizeof(msg),
> -					 "Write failed: expected %d, wrote %li", rate, frames);
> +					 "Write failed: expected %ld, wrote %li", rate, frames);
>  				goto __close;
>  			}
>  			if (frames < rate) {
>  				snprintf(msg, sizeof(msg),
> -					 "expected %d, wrote %li", rate, frames);
> +					 "expected %ld, wrote %li", rate, frames);
>  				goto __close;
>  			}
>  		} else {
>  			frames = snd_pcm_readi(handle, samples, rate);
>  			if (frames < 0) {
>  				snprintf(msg, sizeof(msg),
> -					 "expected %d, wrote %li", rate, frames);
> +					 "expected %ld, wrote %li", rate, frames);
>  				goto __close;
>  			}
>  			if (frames < rate) {
>  				snprintf(msg, sizeof(msg),
> -					 "expected %d, wrote %li", rate, frames);
> +					 "expected %ld, wrote %li", rate, frames);
>  				goto __close;
>  			}
>  		}
> -- 
> 2.34.1
>
Takashi Iwai March 24, 2023, 9:44 a.m. UTC | #2
On Fri, 24 Mar 2023 10:43:38 +0100,
Takashi Iwai wrote:
> 
> On Fri, 24 Mar 2023 10:28:06 +0100,
> Alexander Heinrich wrote:
> > 
> > I noticed some -Wformat compiler warnings in pcm-test.c while building
> > kselftest, fix them by using the same types for format specifier and arguments.
> > 
> > Signed-off-by: Alexander Heinrich <hallo@alexanderheinrich.de>
> 
> Those variables (rates, channels, etc) should be rather int instead of
> long, as these are not 64bit parameters on 32bit archs.
> On top of that, the whole '%l' prefix and cast should be dropped.
> 
> The only concern is the string to int conversion, and this should be
> checked carefully, but other than that, it must be straightforward.
> 
> Care to work on that way?

... and the code has been already changed meanwhile.  Please work on
for-next branch of my sound.git tree.


thanks,

Takashi
diff mbox series

Patch

diff --git a/tools/testing/selftests/alsa/pcm-test.c b/tools/testing/selftests/alsa/pcm-test.c
index 58b525a4a32c..44fc5f826ab5 100644
--- a/tools/testing/selftests/alsa/pcm-test.c
+++ b/tools/testing/selftests/alsa/pcm-test.c
@@ -371,7 +371,7 @@  static void test_pcm_time(struct pcm_data *data, enum test_class class,
 		goto __close;
 	}
 	if (rrate != rate) {
-		snprintf(msg, sizeof(msg), "rate mismatch %ld != %ld", rate, rrate);
+		snprintf(msg, sizeof(msg), "rate mismatch %ld != %d", rate, rrate);
 		goto __close;
 	}
 	rperiod_size = period_size;
@@ -437,24 +437,24 @@  static void test_pcm_time(struct pcm_data *data, enum test_class class,
 			frames = snd_pcm_writei(handle, samples, rate);
 			if (frames < 0) {
 				snprintf(msg, sizeof(msg),
-					 "Write failed: expected %d, wrote %li", rate, frames);
+					 "Write failed: expected %ld, wrote %li", rate, frames);
 				goto __close;
 			}
 			if (frames < rate) {
 				snprintf(msg, sizeof(msg),
-					 "expected %d, wrote %li", rate, frames);
+					 "expected %ld, wrote %li", rate, frames);
 				goto __close;
 			}
 		} else {
 			frames = snd_pcm_readi(handle, samples, rate);
 			if (frames < 0) {
 				snprintf(msg, sizeof(msg),
-					 "expected %d, wrote %li", rate, frames);
+					 "expected %ld, wrote %li", rate, frames);
 				goto __close;
 			}
 			if (frames < rate) {
 				snprintf(msg, sizeof(msg),
-					 "expected %d, wrote %li", rate, frames);
+					 "expected %ld, wrote %li", rate, frames);
 				goto __close;
 			}
 		}