From: Jason Gunthorpe <jgg@ziepe.ca>
To: Alessandro Zanni <alessandrozanni.dev@gmail.com>
Cc: Alessandro Zanni <alessandro.zanni87@gmail.com>,
kevin.tian@intel.com, shuah@kernel.org, iommu@lists.linux.dev,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests/iommu: prevent use of uninitialized variable
Date: Wed, 24 Sep 2025 09:45:50 -0300 [thread overview]
Message-ID: <20250924124550.GH2547959@ziepe.ca> (raw)
In-Reply-To: <y7xzjzbquglgrmbufbbqksvshuaofod6alql6gqfbzhq6s33pk@dw4ma6kctr5s>
On Tue, Sep 23, 2025 at 11:38:13PM +0200, Alessandro Zanni wrote:
> On Tue, Sep 23, 2025 at 02:28:22PM -0300, Jason Gunthorpe wrote:
> > On Tue, Sep 23, 2025 at 05:01:06PM +0200, Alessandro Zanni wrote:
> > > 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
> > >
> > > Signed-off-by: Alessandro Zanni <alessandro.zanni87@gmail.com>
> > > ---
> > > tools/testing/selftests/iommu/iommufd_utils.h | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > I think it should be like this?
> >
> > @@ -1042,15 +1042,12 @@ 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)
> > + while (nvevents--)
> > + if (ioctl(fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_TRIGGER_VEVENT),
> > + &trigger_vevent_cmd))
> > return -1;
> > - }
> > - return ret;
> > + return 0;
> > }
> >
> > And add a fixes line?
> >
> > Jason
>
> Thank you for the reply.
> I'm not sure the right behavior the test should have:
> - in the version you proposed, when ioctl() returns a positive
> value the loop ends and the next tests are skipped.
> - in the original version, if the function ioctl() returns a
> positive value the loop continues with the following tests.
>
> Which one is the desired behavior?
Sorry it should be !ioctl()
The ioctl will only return 0 or -errno
Jason
prev parent reply other threads:[~2025-09-24 12:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-23 15:01 Alessandro Zanni
2025-09-23 17:28 ` Jason Gunthorpe
2025-09-23 21:38 ` Alessandro Zanni
2025-09-24 12:45 ` Jason Gunthorpe [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250924124550.GH2547959@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=alessandro.zanni87@gmail.com \
--cc=alessandrozanni.dev@gmail.com \
--cc=iommu@lists.linux.dev \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®