backends/drm: Handle failing to reopen drm node

Otherwise the drm backend will crash.
This commit is contained in:
Vlad Zahorodnii 2024-03-20 12:40:55 +02:00
parent 8934a31dad
commit 236baa63df
2 changed files with 10 additions and 3 deletions

View file

@ -204,11 +204,16 @@ DrmGpu *DrmBackend::addGpu(const QString &fileName)
return nullptr;
}
DrmGpu *gpu = new DrmGpu(this, fileName, fd, buf.st_rdev);
if (!gpu->graphicsBufferAllocator()) {
delete gpu;
return nullptr;
}
qCDebug(KWIN_DRM, "adding GPU %s", qPrintable(fileName));
m_gpus.push_back(std::make_unique<DrmGpu>(this, fileName, fd, buf.st_rdev));
auto gpu = m_gpus.back().get();
connect(gpu, &DrmGpu::outputAdded, this, &DrmBackend::addOutput);
connect(gpu, &DrmGpu::outputRemoved, this, &DrmBackend::removeOutput);
m_gpus.emplace_back(gpu);
Q_EMIT gpuAdded(gpu);
return gpu;
}

View file

@ -87,7 +87,9 @@ DrmGpu::DrmGpu(DrmBackend *backend, const QString &devNode, int fd, dev_t device
// Reopen the drm node to create a new GEM handle namespace.
m_gbmFd = FileDescriptor{open(devNode.toLocal8Bit(), O_RDWR | O_CLOEXEC)};
if (m_gbmFd.isValid()) {
if (!m_gbmFd.isValid()) {
qCCritical(KWIN_DRM) << "Failed to reopen" << devNode << "drm node, expect bad things to happen:" << strerror(errno);
} else {
drm_magic_t magic;
drmGetMagic(m_gbmFd.get(), &magic);
drmAuthMagic(m_fd, magic);