diff mbox series

selftests/powerpc: Avoid GCC 12 uninitialised variable warning

Message ID 20220801113746.802046-1-mpe@ellerman.id.au (mailing list archive)
State Accepted
Headers show
Series selftests/powerpc: Avoid GCC 12 uninitialised variable warning | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 10 jobs.
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 10 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 23 jobs.
snowpatch_ozlabs/github-powerpc_clang fail kernel (ppc44x, ubuntu-21.10, ppc64) failed at step build.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.

Commit Message

Michael Ellerman Aug. 1, 2022, 11:37 a.m. UTC
GCC 12 thinks that `actual` might be used uninitialised. It's not, the
use is guarded by `bad_mmcr2` which is only set to true at the same
point where `actual` is initialised.

  cycles_with_mmcr2_test.c: In function ‘cycles_with_mmcr2’:
  cycles_with_mmcr2_test.c:81:17: error: ‘actual’ may be used uninitialized [-Werror=maybe-uninitialized]
     81 |                 printf("Bad MMCR2 value seen is 0x%lx\n", actual);

Silence the warning by initialising `actual` to zero.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 tools/testing/selftests/powerpc/pmu/ebb/cycles_with_mmcr2_test.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Michael Ellerman Aug. 2, 2022, 11:03 a.m. UTC | #1
On Mon, 1 Aug 2022 21:37:46 +1000, Michael Ellerman wrote:
> GCC 12 thinks that `actual` might be used uninitialised. It's not, the
> use is guarded by `bad_mmcr2` which is only set to true at the same
> point where `actual` is initialised.
> 
>   cycles_with_mmcr2_test.c: In function ‘cycles_with_mmcr2’:
>   cycles_with_mmcr2_test.c:81:17: error: ‘actual’ may be used uninitialized [-Werror=maybe-uninitialized]
>      81 |                 printf("Bad MMCR2 value seen is 0x%lx\n", actual);
> 
> [...]

Applied to powerpc/next.

[1/1] selftests/powerpc: Avoid GCC 12 uninitialised variable warning
      https://git.kernel.org/powerpc/c/ff446cd76854d47f451a84c26bb70934ae2ec5a7

cheers
diff mbox series

Patch

diff --git a/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_mmcr2_test.c b/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_mmcr2_test.c
index 4b45a2e70f62..fc32187d483d 100644
--- a/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_mmcr2_test.c
+++ b/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_mmcr2_test.c
@@ -50,6 +50,7 @@  int cycles_with_mmcr2(void)
 	expected[1] = MMCR2_EXPECTED_2;
 	i = 0;
 	bad_mmcr2 = false;
+	actual = 0;
 
 	/* Make sure we loop until we take at least one EBB */
 	while ((ebb_state.stats.ebb_count < 20 && !bad_mmcr2) ||