Fix to avoid the usage of the `res` variable uninitialized in the following macro expansions.
PATCH v2 1/1 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
--- tools/testing/selftests/iommu/iommufd_utils.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
tools/testing/selftests/iommu/iommufd_utils.h +3 -5
@@ -1042,15 +1042,13 @@ static int _test_cmd_trigger_vevents(int fd, __u32 dev_id, __u32 nvevents) .dev_id = dev_id, }, }; -int ret;while (nvevents--) { - ret =ioctl (fd,_IOMMU_TEST_CMD (IOMMU_TEST_OP_TRIGGER_VEVENT ), - &trigger_vevent_cmd); -if (ret <0 ) +if (!ioctl (fd,_IOMMU_TEST_CMD (IOMMU_TEST_OP_TRIGGER_VEVENT ), + &trigger_vevent_cmd))return -1 ; } -return ret; +return 0 ; }#define test_cmd_trigger_vevents (dev_id, nvevents) \
Signature · 1 line
2.43.0
Shuah Khan
maintainerOn 9/24/25 10:57, Alessandro Zanni wrote:
Fix to avoid the usage of the res variable uninitialized in the following macro expansions.
ret not res?
You can simplify the shortlog "Fix ret unitialized warning" perhaps.
Quoted 1 line
It solves the following warning:
Fix the following warning.
Quoted 36 lines
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 -Ctools/testing/selftestsTARGETS=iommuSigned-off-by Alessandro Zanni <[email protected]>--- tools/testing/selftests/iommu/iommufd_utils.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)tools/testing/selftests/iommu/iommufd_utils.h +0
-1@@ -1042,15 +1042,13 @@ static int _test_cmd_trigger_vevents(int fd, __u32 dev_id, __u32 nvevents) .dev_id = dev_id, }, }; -int ret;
tools/testing/selftests/iommu/iommufd_utils.h static int _test_cmd_trigger_vevents(int fd, __u32 dev_id, __u32 nvevents) · line 1053
Quoted 10 lines
tools/testing/selftests/iommu/iommufd_utils.h +2
-4while (nvevents--) { - ret =ioctl (fd,_IOMMU_TEST_CMD (IOMMU_TEST_OP_TRIGGER_VEVENT ), - &trigger_vevent_cmd); -if (ret <0 ) +if (!ioctl (fd,_IOMMU_TEST_CMD (IOMMU_TEST_OP_TRIGGER_VEVENT ), + &trigger_vevent_cmd))return -1 ; } -return ret;
Hmm. with this change -1 is returned instead of ret
tools/testing/selftests/iommu/iommufd_utils.h static int _test_cmd_trigger_vevents(int fd, __u32 dev_id, __u32 nvevents) · line 1054
Quoted 4 lines
tools/testing/selftests/iommu/iommufd_utils.h +1
-0+return 0 ; }#define test_cmd_trigger_vevents (dev_id, nvevents) \
thanks,
-- Shuah
Quoted 61 lines · Shuah Khan
On 9/24/25 10:57, Alessandro Zanni wrote:
Fix to avoid the usage of the
resvariable uninitialized in the following macro expansions.ret not res?
You can simplify the shortlog "Fix ret unitialized warning" perhaps.
Quoted 1 line
It solves the following warning:
Fix the following warning.
Quoted 35 lines
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 -Ctools/testing/selftestsTARGETS=iommuSigned-off-by Alessandro Zanni <[email protected]>--- tools/testing/selftests/iommu/iommufd_utils.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)tools/testing/selftests/iommu/iommufd_utils.h +0
-0@@ -1042,15 +1042,13 @@ static int _test_cmd_trigger_vevents(int fd, __u32 dev_id, __u32 nvevents) .dev_id = dev_id, }, };tools/testing/selftests/iommu/iommufd_utils.h static int _test_cmd_trigger_vevents(int fd, __u32 dev_id, __u32 nvevents) · line 1052
Quoted 10 lines
tools/testing/selftests/iommu/iommufd_utils.h +2
-5-int ret;while (nvevents--) { - ret =ioctl (fd,_IOMMU_TEST_CMD (IOMMU_TEST_OP_TRIGGER_VEVENT ), - &trigger_vevent_cmd); -if (ret <0 ) +if (!ioctl (fd,_IOMMU_TEST_CMD (IOMMU_TEST_OP_TRIGGER_VEVENT ), + &trigger_vevent_cmd))return -1 ; } -return ret;Hmm. with this change -1 is returned instead of ret
Quoted 7 lines
tools/testing/selftests/iommu/iommufd_utils.h static int _test_cmd_trigger_vevents(int fd, __u32 dev_id, __u32 nvevents) · line 1054
Quoted 3 lines
tools/testing/selftests/iommu/iommufd_utils.h +1
-0+return 0 ; }#define test_cmd_trigger_vevents (dev_id, nvevents) \thanks,
-- Shuah
This patch has a malformed title. Please refer to the patch called '[PATCH v2] selftests/iommu: prevent use of uninitialized variable'. But the typo res->ret is still present. Sorry for that.
About the fix, the assert test just checks if the return value is 0 or not. That's why the variable has been deleted.
By the way, if we prefer to return also the error values, the patch v1 just solves the warnings returning the negative values.
Let me know which version is preferable.
Thank you,
Alessandro
Quoted 1 line · Alessandro Zanni
Let me know which version is preferable.
I already applied your fix for this, no need to resend
Jason