From: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
To: Rob Clark <robin.clark@oss.qualcomm.com>,
Dmitry Baryshkov <lumag@kernel.org>,
Abhinav Kumar <abhinav.kumar@linux.dev>,
Jessica Zhang <jesszhan0024@gmail.com>,
Sean Paul <sean@poorly.run>,
Marijn Suijten <marijn.suijten@somainline.org>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Archit Taneja <architt@codeaurora.org>,
Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>,
Kalyan Thota <quic_kalyant@quicinc.com>,
Vinod Polimera <quic_vpolimer@quicinc.com>
Cc: linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org,
freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: [PATCH v4 06/14] drm/msm: let the kms drivers clean up a failed kms_init()
Date: Fri, 27 Nov 2026 21:44:19 +0200 [thread overview]
Message-ID: <20261127-msm-kms-destroy-fixes-v4-6-242b0a3f8e47@oss.qualcomm.com> (raw)
In-Reply-To: <20261127-msm-kms-destroy-fixes-v4-0-242b0a3f8e47@oss.qualcomm.com>
A failed priv->kms_init() or ->hw_init() is cleaned up by the ->destroy()
callback, which makes ->destroy() responsible for tearing down a KMS in
any state between "not initialised at all" and "fully initialised". The
kernel convention is the opposite: a function which fails undoes its own
steps, and the teardown only ever sees a fully set up object.
Let the kms drivers switch to that convention one at a time: skip
->destroy() after a failed kms_init() of a driver which sets
init_unwinds, and let the drivers fold their hardware setup into
kms_init() and drop ->hw_init(). Set up the mode config before calling
kms_init(), so that it is already in place for the hardware setup.
While at it, tear the snapshot worker down before the KMS on the error
path as well, matching the order of msm_drm_kms_uninit(). Nothing queues
a snapshot until msm_drm_kms_init() has succeeded, so no dump can be
pending either way, but keeping both teardown paths in the same order is
less surprising.
The flag and the optional ->hw_init() go away once all the drivers have
been converted.
Assisted-by: LLM
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
---
drivers/gpu/drm/msm/msm_kms.c | 25 +++++++++++++++++--------
drivers/gpu/drm/msm/msm_kms.h | 3 +++
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/msm/msm_kms.c b/drivers/gpu/drm/msm/msm_kms.c
index a94d2888a21e..da9ba8583420 100644
--- a/drivers/gpu/drm/msm/msm_kms.c
+++ b/drivers/gpu/drm/msm/msm_kms.c
@@ -283,12 +283,6 @@ int msm_drm_kms_init(struct device *dev, const struct drm_driver *drv)
return ret;
}
- ret = priv->kms_init(ddev);
- if (ret) {
- DRM_DEV_ERROR(dev, "failed to load kms\n");
- goto err_destroy_kms;
- }
-
/* Enable normalization of plane zpos */
ddev->mode_config.normalize_zpos = true;
@@ -296,12 +290,22 @@ int msm_drm_kms_init(struct device *dev, const struct drm_driver *drv)
ddev->mode_config.helper_private = &mode_config_helper_funcs;
kms->dev = ddev;
- ret = kms->funcs->hw_init(kms);
+ ret = priv->kms_init(ddev);
if (ret) {
- DRM_DEV_ERROR(dev, "kms hw init failed: %d\n", ret);
+ DRM_DEV_ERROR(dev, "failed to load kms\n");
+ if (kms->init_unwinds)
+ goto err_destroy_snapshot;
goto err_destroy_kms;
}
+ if (kms->funcs->hw_init) {
+ ret = kms->funcs->hw_init(kms);
+ if (ret) {
+ DRM_DEV_ERROR(dev, "kms hw init failed: %d\n", ret);
+ goto err_destroy_kms;
+ }
+ }
+
drm_helper_move_panel_connectors_to_head(ddev);
drm_for_each_crtc(crtc, ddev) {
@@ -349,6 +353,11 @@ int msm_drm_kms_init(struct device *dev, const struct drm_driver *drv)
kms->funcs->destroy(kms);
return ret;
+
+err_destroy_snapshot:
+ msm_disp_snapshot_destroy(ddev);
+
+ return ret;
}
int msm_kms_pm_prepare(struct device *dev)
diff --git a/drivers/gpu/drm/msm/msm_kms.h b/drivers/gpu/drm/msm/msm_kms.h
index ee98393b9855..2f097e23e2e9 100644
--- a/drivers/gpu/drm/msm/msm_kms.h
+++ b/drivers/gpu/drm/msm/msm_kms.h
@@ -149,6 +149,9 @@ struct msm_kms {
int irq;
bool irq_requested;
+ /* set by the kms drivers whose kms_init() undoes its own failures */
+ bool init_unwinds;
+
/* rate limit the snapshot capture to once per attach */
atomic_t fault_snapshot_capture;
--
2.47.3
next prev parent reply other threads:[~2026-11-27 19:45 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 19:44 [PATCH v4 00/14] drm/msm: fix the error handling of the KMS init Dmitry Baryshkov
2026-11-27 19:44 ` [PATCH v4 01/14] drm/msm: fail the snapshot init when its worker cannot be created Dmitry Baryshkov
2026-11-30 8:45 ` Konrad Dybcio
2026-11-27 19:44 ` [PATCH v4 02/14] drm/msm/mdp5: forget the hardware blocks of a previous bind Dmitry Baryshkov
2026-11-27 19:44 ` [PATCH v4 03/14] drm/msm: unwind msm_drm_kms_init() on failure Dmitry Baryshkov
2026-11-27 19:44 ` [PATCH v4 04/14] drm/msm: order the display snapshot sources around its worker Dmitry Baryshkov
2026-11-30 8:46 ` Konrad Dybcio
2026-11-27 19:44 ` [PATCH v4 05/14] drm/msm: clean up after a failed msm_kms_init() Dmitry Baryshkov
2026-11-27 19:44 ` Dmitry Baryshkov [this message]
2026-11-27 19:44 ` [PATCH v4 07/14] drm/msm/mdp5: unwind a failed mdp5_kms_init() Dmitry Baryshkov
2026-11-27 19:44 ` [PATCH v4 08/14] drm/msm/mdp4: unwind a failed mdp4_kms_init() Dmitry Baryshkov
2026-11-27 19:44 ` [PATCH v4 09/14] drm/msm/dpu: don't tear down a failed hw_init twice Dmitry Baryshkov
2026-11-27 19:44 ` [PATCH v4 10/14] drm/msm: tear down only a successfully initialised KMS Dmitry Baryshkov
2026-11-30 8:49 ` Konrad Dybcio
2026-11-27 19:44 ` [PATCH v4 11/14] drm/msm/dpu: clean up the self-refresh helpers on teardown Dmitry Baryshkov
2026-11-27 19:44 ` [PATCH v4 12/14] drm/msm/dpu: unwind a failed dpu_kms_hw_init() step by step Dmitry Baryshkov
2026-11-27 19:44 ` [PATCH v4 13/14] drm/msm/mdp4: disable the vdd regulator on teardown Dmitry Baryshkov
2026-11-27 19:44 ` [PATCH v4 14/14] drm/msm: drop the runtime PM flags from the KMS teardown Dmitry Baryshkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261127-msm-kms-destroy-fixes-v4-6-242b0a3f8e47@oss.qualcomm.com \
--to=dmitry.baryshkov@oss.qualcomm.com \
--cc=abhinav.kumar@linux.dev \
--cc=airlied@gmail.com \
--cc=architt@codeaurora.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=freedreno@lists.freedesktop.org \
--cc=jesszhan0024@gmail.com \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lumag@kernel.org \
--cc=marijn.suijten@somainline.org \
--cc=quic_kalyant@quicinc.com \
--cc=quic_vpolimer@quicinc.com \
--cc=robin.clark@oss.qualcomm.com \
--cc=sean@poorly.run \
--cc=simona@ffwll.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®