Skip to content

Commit

Permalink
kselftests: dmabuf-heaps: Ensure the driver name is null-terminated
Browse files Browse the repository at this point in the history
[ Upstream commit 291e4ba ]

Even if a vgem device is configured in, we will skip the import_vgem_fd()
test almost every time.

  TAP version 13
  1..11
  # Testing heap: system
  # =======================================
  # Testing allocation and importing:
  ok 1 # SKIP Could not open vgem -1

The problem is that we use the DRM_IOCTL_VERSION ioctl to query the driver
version information but leave the name field a non-null-terminated string.
Terminate it properly to actually test against the vgem device.

While at it, let's check the length of the driver name is exactly 4 bytes
and return early otherwise (in case there is a name like "vgemfoo" that
gets converted to "vgem\0" unexpectedly).

Signed-off-by: Zenghui Yu <[email protected]>
Signed-off-by: Daniel Vetter <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Zenghui Yu authored and gregkh committed Sep 12, 2024
1 parent e2d14bf commit f743662
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ static int check_vgem(int fd)
version.name = name;

ret = ioctl(fd, DRM_IOCTL_VERSION, &version);
if (ret)
if (ret || version.name_len != 4)
return 0;

name[4] = '\0';

return !strcmp(name, "vgem");
}

Expand Down

0 comments on commit f743662

Please sign in to comment.