[PATCH 00/11] drm/msm: fix the error handling of the KMS init

From: Dmitry Baryshkov

Date: Fri Oct 02 2026 - 20:27:26 EST


When setting up the KMS fails, msm_drm_kms_init() cleans up by calling
the ->destroy() callback of the kms driver. That makes ->destroy()
responsible for tearing down a KMS in any state, from "not initialised at
all" to "fully initialised", and the drivers get it wrong in several
ways:

- dpu_kms_hw_init() and mdp5_init() already clean up after their own
failures, and ->destroy() then finalises the global state object a
second time;

- mdp4_destroy() dereferences mdp4_kms->dev, which isn't set yet when
mdp_kms_init() fails;

- msm_kms_init() leaves a NULL workqueue behind when it fails to
allocate it, which msm_kms_destroy() passes to destroy_workqueue();

- msm_drm_kms_init() hands a half initialised KMS to the full teardown
of msm_drm_kms_uninit(), and the snapshot init ignores the failure to
create its worker.

Most of these were pointed out by Sashiko while reviewing the "drm/msm:
fix SMMU fault dumps" series, which has been carrying the first fixes.
Rather than teaching ->destroy() about ever more partial states, this
series switches the KMS init to the usual kernel convention: every init
function undoes its own steps when it fails, and ->destroy() only ever
tears down a KMS which was initialised successfully. This reverses the
approach of commit 93c125e4ea98 ("drm/msm: don't tear down KMS twice when
KMS init fails"), which moved all of the cleanup into ->destroy().

To keep every step safe and bisectable, the drivers are converted one at
a time: a temporary flag tells msm_drm_kms_init() that a driver cleans up
its own failures, and both the flag and ->hw_init(), which gets folded
into the drivers' kms_init(), are removed once all the drivers have been
converted. The last patches are follow-ups which the new rules allow:
unwinding the DPU hardware setup step by step, disabling the MDP4 vdd
regulator on teardown, and dropping the runtime PM flags which
->destroy() no longer needs.

Tested on DB820c (MSM8996) with both the MDP5 and the DPU drivers, with
failures injected into the msm_kms_init(), the MDP5 kms_init(), the DPU
hardware setup and after a successful kms_init(): each of them now fails
the bind cleanly, without warnings. MDP4 is build-tested only.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@xxxxxxxxxxxxxxxx>
---
Dmitry Baryshkov (11):
drm/msm: fail the snapshot init when its worker cannot be created
drm/msm: unwind msm_drm_kms_init() on failure
drm/msm: clean up after a failed msm_kms_init()
drm/msm: let the kms drivers clean up a failed kms_init()
drm/msm/mdp5: unwind a failed mdp5_kms_init()
drm/msm/mdp4: unwind a failed mdp4_kms_init()
drm/msm/dpu: don't tear down a failed hw_init twice
drm/msm: tear down only a successfully initialised KMS
drm/msm/dpu: unwind a failed dpu_kms_hw_init() step by step
drm/msm/mdp4: disable the vdd regulator on teardown
drm/msm: drop the runtime PM flags from the KMS teardown

drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c | 55 ++++++++++++------------
drivers/gpu/drm/msm/disp/dpu1/dpu_kms.h | 1 -
drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c | 63 +++++++++++++++++-----------
drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.h | 2 -
drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c | 47 +++++++++++----------
drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.h | 2 -
drivers/gpu/drm/msm/disp/msm_disp_snapshot.c | 12 +++++-
drivers/gpu/drm/msm/msm_drv.c | 27 +++++++++---
drivers/gpu/drm/msm/msm_kms.c | 43 ++++++++++---------
drivers/gpu/drm/msm/msm_kms.h | 17 +++++---
10 files changed, 159 insertions(+), 110 deletions(-)
---
base-commit: a15fac810c76397ec9f62a6fc26c4d7ab6e238a7
change-id: 20260930-msm-kms-destroy-fixes-0f04b1d39b83

Best regards,
--
With best wishes
Dmitry