[igt-dev] [PATCH i-g-t v2 03/21] lib/ioctl_wrappers: Help static analysis with execution flow

Petri Latvala
2019-01-18T10:42:52Z

If an ioctl fails, errno is set to non-zero, and static analysis
doesn't quite get it. Add igt_assume()s where applicable.

v2: Braces on both branches of an if (Chris)

Signed-off-by: Petri Latvala <petri.latvala@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Michał Winiarski <michal.winiarski@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
---
lib/ioctl_wrappers.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index 19e59794..404c2fbf 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -547,10 +547,12 @@ int __gem_create(int fd, uint64_t size, uint32_t *handle)
};
int err = 0;

- if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create) == 0)
+ if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create) == 0) {
*handle = create.handle;
- else
+ } else {
err = -errno;
+ igt_assume(err != 0);
+ }

errno = 0;
return err;
@@ -586,8 +588,10 @@ uint32_t gem_create(int fd, uint64_t size)
int __gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
{
int err = 0;
- if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, execbuf))
+ if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, execbuf)) {
err = -errno;
+ igt_assume(err != 0);
+ }
errno = 0;
return err;
}
@@ -616,8 +620,10 @@ void gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
int __gem_execbuf_wr(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
{
int err = 0;
- if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2_WR, execbuf))
+ if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2_WR, execbuf)) {
err = -errno;
+ igt_assume(err != 0);
+ }
errno = 0;
return err;
}
--
2.19.1