Skip to content

Commit 1d235d8

Browse files
Alez87jgunthorpe
authored andcommitted
iommu/selftest: prevent use of uninitialized variable
Fix to avoid the usage of the `res` variable uninitialized in the following macro expansions. It solves the following warning: In function ‘iommufd_viommu_vdevice_alloc’, inlined from ‘wrapper_iommufd_viommu_vdevice_alloc’ at iommufd.c:2889:1: ../kselftest_harness.h:760:12: warning: ‘ret’ may be used uninitialized [-Wmaybe-uninitialized] 760 | if (!(__exp _t __seen)) { \ | ^ ../kselftest_harness.h:513:9: note: in expansion of macro ‘__EXPECT’ 513 | __EXPECT(expected, #expected, seen, #seen, ==, 1) | ^~~~~~~~ iommufd_utils.h:1057:9: note: in expansion of macro ‘ASSERT_EQ’ 1057 | ASSERT_EQ(0, _test_cmd_trigger_vevents(self->fd, dev_id, nvevents)) | ^~~~~~~~~ iommufd.c:2924:17: note: in expansion of macro ‘test_cmd_trigger_vevents’ 2924 | test_cmd_trigger_vevents(dev_id, 3); | ^~~~~~~~~~~~~~~~~~~~~~~~ The issue can be reproduced, building the tests, with the command: make -C tools/testing/selftests TARGETS=iommu Link: https://patch.msgid.link/r/[email protected] Fixes: 97717a1 ("iommufd/selftest: Add IOMMU_VEVENTQ_ALLOC test coverage") Signed-off-by: Alessandro Zanni <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 43f6bee commit 1d235d8

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

tools/testing/selftests/iommu/iommufd_utils.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,15 +1042,13 @@ static int _test_cmd_trigger_vevents(int fd, __u32 dev_id, __u32 nvevents)
10421042
.dev_id = dev_id,
10431043
},
10441044
};
1045-
int ret;
10461045

10471046
while (nvevents--) {
1048-
ret = ioctl(fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_TRIGGER_VEVENT),
1049-
&trigger_vevent_cmd);
1050-
if (ret < 0)
1047+
if (!ioctl(fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_TRIGGER_VEVENT),
1048+
&trigger_vevent_cmd))
10511049
return -1;
10521050
}
1053-
return ret;
1051+
return 0;
10541052
}
10551053

10561054
#define test_cmd_trigger_vevents(dev_id, nvevents) \

0 commit comments

Comments
 (0)