Skip to content

Commit 9a96876

Browse files
nicolincjgunthorpe
authored andcommitted
iommufd/selftest: Fix build warnings due to uninitialized mfd
Commit 869c788 ("selftests: harness: Stop using setjmp()/longjmp()") changed the harness structure. For some unknown reason, two build warnings occur to the iommufd selftest: iommufd.c: In function ‘wrapper_iommufd_mock_domain_all_aligns’: iommufd.c:1807:17: warning: ‘mfd’ may be used uninitialized in this function 1807 | close(mfd); | ^~~~~~~~~~ iommufd.c:1767:13: note: ‘mfd’ was declared here 1767 | int mfd; | ^~~ iommufd.c: In function ‘wrapper_iommufd_mock_domain_all_aligns_copy’: iommufd.c:1870:17: warning: ‘mfd’ may be used uninitialized in this function 1870 | close(mfd); | ^~~~~~~~~~ iommufd.c:1819:13: note: ‘mfd’ was declared here 1819 | int mfd; | ^~~ All the mfd have been used in the variant->file path only, so it's likely a false alarm. FWIW, the commit mentioned above does not cause this, yet it might affect gcc in a certain way that resulted in the warnings. It is also found that ading a dummy setjmp (which doesn't make sense) could mute the warnings: https://lore.kernel.org/all/[email protected]/ The job of this selftest is to catch kernel bug, while such warnings will unlikely disrupt its role. Mute the warning by force initializing the mfd and add an ASSERT_GT(). Link: https://patch.msgid.link/r/6951d85d5cd34cbf22abab7714542654e63ecc44.1750787928.git.nicolinc@nvidia.com Reviewed-by: Jason Gunthorpe <[email protected]> Signed-off-by: Nicolin Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent a9bf67e commit 9a96876

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tools/testing/selftests/iommu/iommufd.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,13 +1748,15 @@ TEST_F(iommufd_mock_domain, all_aligns)
17481748
unsigned int end;
17491749
uint8_t *buf;
17501750
int prot = PROT_READ | PROT_WRITE;
1751-
int mfd;
1751+
int mfd = -1;
17521752

17531753
if (variant->file)
17541754
buf = memfd_mmap(buf_size, prot, MAP_SHARED, &mfd);
17551755
else
17561756
buf = mmap(0, buf_size, prot, self->mmap_flags, -1, 0);
17571757
ASSERT_NE(MAP_FAILED, buf);
1758+
if (variant->file)
1759+
ASSERT_GT(mfd, 0);
17581760
check_refs(buf, buf_size, 0);
17591761

17601762
/*
@@ -1800,13 +1802,15 @@ TEST_F(iommufd_mock_domain, all_aligns_copy)
18001802
unsigned int end;
18011803
uint8_t *buf;
18021804
int prot = PROT_READ | PROT_WRITE;
1803-
int mfd;
1805+
int mfd = -1;
18041806

18051807
if (variant->file)
18061808
buf = memfd_mmap(buf_size, prot, MAP_SHARED, &mfd);
18071809
else
18081810
buf = mmap(0, buf_size, prot, self->mmap_flags, -1, 0);
18091811
ASSERT_NE(MAP_FAILED, buf);
1812+
if (variant->file)
1813+
ASSERT_GT(mfd, 0);
18101814
check_refs(buf, buf_size, 0);
18111815

18121816
/*

0 commit comments

Comments
 (0)