linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests: arm64: Check fread return value in exec_target
@ 2025-08-07 15:49 Bala-Vignesh-Reddy
  2025-08-07 19:23 ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Bala-Vignesh-Reddy @ 2025-08-07 15:49 UTC (permalink / raw)
  To: catalin.marinas, will, shuah, broonie
  Cc: Bala-Vignesh-Reddy, linux-arm-kernel, linux-kselftest,
	linux-kernel

Fix -Wunused-result warning generated when compiled with gcc 13.3.0,
by checking fread's return value and handling errors, preventing
potential failures when reading from stdin.

Fixes compiler warning:
warning: ignoring return value of 'fread' declared with attribute
'warn_unused_result' [-Wunused-result]

Fixes: 806a15b2545e ("kselftests/arm64: add PAuth test for whether exec() changes keys")

Signed-off-by: Bala-Vignesh-Reddy <reddybalavignesh9979@gmail.com>
---
 tools/testing/selftests/arm64/pauth/exec_target.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/arm64/pauth/exec_target.c b/tools/testing/selftests/arm64/pauth/exec_target.c
index 4435600ca400..c22db59194eb 100644
--- a/tools/testing/selftests/arm64/pauth/exec_target.c
+++ b/tools/testing/selftests/arm64/pauth/exec_target.c
@@ -13,7 +13,12 @@ int main(void)
 	unsigned long hwcaps;
 	size_t val;
 
-	fread(&val, sizeof(size_t), 1, stdin);
+	size_t size = fread(&val, sizeof(size_t), 1, stdin);
+
+	if (size != 1) {
+		fprintf(stderr, "Could not read input from stdin\n");
+		return -1;
+	}
 
 	/* don't try to execute illegal (unimplemented) instructions) caller
 	 * should have checked this and keep worker simple
-- 
2.43.0


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

* Re: [PATCH] selftests: arm64: Check fread return value in exec_target
  2025-08-07 15:49 [PATCH] selftests: arm64: Check fread return value in exec_target Bala-Vignesh-Reddy
@ 2025-08-07 19:23 ` Mark Brown
  2025-08-08  8:08   ` [PATCH v2] " Bala-Vignesh-Reddy
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2025-08-07 19:23 UTC (permalink / raw)
  To: Bala-Vignesh-Reddy
  Cc: catalin.marinas, will, shuah, linux-arm-kernel, linux-kselftest,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 938 bytes --]

On Thu, Aug 07, 2025 at 09:19:47PM +0530, Bala-Vignesh-Reddy wrote:

> Fix -Wunused-result warning generated when compiled with gcc 13.3.0,
> by checking fread's return value and handling errors, preventing
> potential failures when reading from stdin.
> 
> Fixes compiler warning:
> warning: ignoring return value of 'fread' declared with attribute
> 'warn_unused_result' [-Wunused-result]

> --- a/tools/testing/selftests/arm64/pauth/exec_target.c
> +++ b/tools/testing/selftests/arm64/pauth/exec_target.c
> @@ -13,7 +13,12 @@ int main(void)

> -	fread(&val, sizeof(size_t), 1, stdin);
> +	size_t size = fread(&val, sizeof(size_t), 1, stdin);
> +
> +	if (size != 1) {
> +		fprintf(stderr, "Could not read input from stdin\n");
> +		return -1;
> +	}

It doesn't really matter but it'd be nicer to return a standard value
from main(), EXIT_FAILURE is probably a good choice.  Exit values are in
the range 0..255.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* [PATCH v2] selftests: arm64: Check fread return value in exec_target
  2025-08-07 19:23 ` Mark Brown
@ 2025-08-08  8:08   ` Bala-Vignesh-Reddy
  2025-08-08 12:05     ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Bala-Vignesh-Reddy @ 2025-08-08  8:08 UTC (permalink / raw)
  To: broonie
  Cc: linux-arm-kernel, catalin.marinas, will, shuah, linux-kselftest,
	linux-kernel, Bala-Vignesh-Reddy

Fix -Wunused-result warning generated when compiled with gcc 13.3.0,
by checking fread's return value and handling errors, preventing
potential failures when reading from stdin.

Fixes compiler warning:
warning: ignoring return value of 'fread' declared with attribute
'warn_unused_result' [-Wunused-result]

Fixes: 806a15b2545e ("kselftests/arm64: add PAuth test for whether exec() changes keys")

Signed-off-by: Bala-Vignesh-Reddy <reddybalavignesh9979@gmail.com>
---
Changes in v2:
	Use EXIT_FAILURE instead of -1.
---
 tools/testing/selftests/arm64/pauth/exec_target.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/arm64/pauth/exec_target.c b/tools/testing/selftests/arm64/pauth/exec_target.c
index 4435600ca400..e597861b26d6 100644
--- a/tools/testing/selftests/arm64/pauth/exec_target.c
+++ b/tools/testing/selftests/arm64/pauth/exec_target.c
@@ -13,7 +13,12 @@ int main(void)
 	unsigned long hwcaps;
 	size_t val;
 
-	fread(&val, sizeof(size_t), 1, stdin);
+	size_t size = fread(&val, sizeof(size_t), 1, stdin);
+
+	if (size != 1) {
+		fprintf(stderr, "Could not read input from stdin\n");
+		return EXIT_FAILURE;
+	}
 
 	/* don't try to execute illegal (unimplemented) instructions) caller
 	 * should have checked this and keep worker simple
-- 
2.43.0


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

* Re: [PATCH v2] selftests: arm64: Check fread return value in exec_target
  2025-08-08  8:08   ` [PATCH v2] " Bala-Vignesh-Reddy
@ 2025-08-08 12:05     ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2025-08-08 12:05 UTC (permalink / raw)
  To: Bala-Vignesh-Reddy
  Cc: linux-arm-kernel, catalin.marinas, will, shuah, linux-kselftest,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 446 bytes --]

On Fri, Aug 08, 2025 at 01:38:30PM +0530, Bala-Vignesh-Reddy wrote:
> Fix -Wunused-result warning generated when compiled with gcc 13.3.0,
> by checking fread's return value and handling errors, preventing
> potential failures when reading from stdin.
> 
> Fixes compiler warning:
> warning: ignoring return value of 'fread' declared with attribute
> 'warn_unused_result' [-Wunused-result]

Reviewed-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2025-08-08 12:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-07 15:49 [PATCH] selftests: arm64: Check fread return value in exec_target Bala-Vignesh-Reddy
2025-08-07 19:23 ` Mark Brown
2025-08-08  8:08   ` [PATCH v2] " Bala-Vignesh-Reddy
2025-08-08 12:05     ` Mark Brown

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).