backends/drm: don't crash if connector has no modes

This commit is contained in:
Xaver Hugl 2022-10-17 13:05:23 +02:00
parent 50b4e988a4
commit 850ae0cfe9

View file

@ -133,10 +133,7 @@ bool DrmConnector::init()
bool DrmConnector::isConnected() const bool DrmConnector::isConnected() const
{ {
if (!m_conn) { return !m_driverModes.empty() && m_conn && m_conn->connection == DRM_MODE_CONNECTED;
return false;
}
return m_conn->connection == DRM_MODE_CONNECTED;
} }
static QHash<int, QByteArray> s_connectorNames = { static QHash<int, QByteArray> s_connectorNames = {
@ -293,7 +290,7 @@ bool DrmConnector::updateProperties()
if (!m_edid.isValid()) { if (!m_edid.isValid()) {
qCWarning(KWIN_DRM) << "Couldn't parse EDID for connector" << this; qCWarning(KWIN_DRM) << "Couldn't parse EDID for connector" << this;
} }
} else if (isConnected()) { } else if (m_conn->connection == DRM_MODE_CONNECTED) {
qCDebug(KWIN_DRM) << "Could not find edid for connector" << this; qCDebug(KWIN_DRM) << "Could not find edid for connector" << this;
} }
@ -309,15 +306,12 @@ bool DrmConnector::updateProperties()
for (int i = 0; equal && i < m_conn->count_modes; i++) { for (int i = 0; equal && i < m_conn->count_modes; i++) {
equal &= checkIfEqual(m_driverModes[i]->nativeMode(), &m_conn->modes[i]); equal &= checkIfEqual(m_driverModes[i]->nativeMode(), &m_conn->modes[i]);
} }
if (!equal && (m_driverModes.empty() || m_conn->count_modes > 0)) { if (!equal && m_conn->count_modes > 0) {
// reload modes // reload modes
m_driverModes.clear(); m_driverModes.clear();
for (int i = 0; i < m_conn->count_modes; i++) { for (int i = 0; i < m_conn->count_modes; i++) {
m_driverModes.append(std::make_shared<DrmConnectorMode>(this, m_conn->modes[i])); m_driverModes.append(std::make_shared<DrmConnectorMode>(this, m_conn->modes[i]));
} }
if (m_driverModes.isEmpty()) {
return false;
} else {
m_modes.clear(); m_modes.clear();
m_modes.append(m_driverModes); m_modes.append(m_driverModes);
m_modes.append(generateCommonModes()); m_modes.append(generateCommonModes());
@ -335,7 +329,6 @@ bool DrmConnector::updateProperties()
m_pipeline->output()->updateModes(); m_pipeline->output()->updateModes();
} }
} }
}
return true; return true;
} }