backends/drm: Fix the closefb ioctl

The DRM_IOCTL_MODE_CLOSEFB ioctl takes a struct drm_mode_closefb as
argument and not the framebuffer id as integer.

That distinction is important because the kernel side explicitly
checks whether the padding in drm_mode_closefb has been correctly
initialized to zero:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/drm_framebuffer.c#n494

Use drm_mode_closefb and thus make sure the kernel side is not reading
garbage when testing the padding.
This commit is contained in:
Zack Rusin 2024-04-01 14:58:54 -04:00 committed by Xaver Hugl
parent 61ca42cd2c
commit d20d84cfa3

View file

@ -28,10 +28,6 @@
#include <linux/dma-buf.h>
#endif
#ifndef DRM_IOCTL_MODE_CLOSEFB
#define DRM_IOCTL_MODE_CLOSEFB 0xD0
#endif
namespace KWin
{
@ -65,9 +61,18 @@ DrmFramebuffer::DrmFramebuffer(DrmGpu *gpu, uint32_t fbId, GraphicsBuffer *buffe
DrmFramebuffer::~DrmFramebuffer()
{
uint32_t nonConstFb = m_framebufferId;
if (drmIoctl(m_gpu->fd(), DRM_IOCTL_MODE_CLOSEFB, &nonConstFb) != 0) {
#ifdef DRM_IOCTL_MODE_CLOSEFB
struct drm_mode_closefb closeArgs{
.fb_id = m_framebufferId,
.pad = 0,
};
if (drmIoctl(m_gpu->fd(), DRM_IOCTL_MODE_CLOSEFB, &closeArgs) != 0) {
drmIoctl(m_gpu->fd(), DRM_IOCTL_MODE_RMFB, &nonConstFb);
}
#else
drmIoctl(m_gpu->fd(), DRM_IOCTL_MODE_RMFB, &nonConstFb);
#endif
}
uint32_t DrmFramebuffer::framebufferId() const