From def98e3164a2048323744af92728bc4c7bf4e955 Mon Sep 17 00:00:00 2001 From: jsg Date: Tue, 6 Feb 2024 03:20:00 +0000 Subject: [PATCH] drm/mipi-dsi: Fix detach call without attach From Tomi Valkeinen daf57c5ce16e907405d8a59a4f2be20e204906e4 in linux-6.6.y/6.6.16 90d50b8d85834e73536fdccd5aa913b30494fef0 in mainline linux --- sys/dev/pci/drm/drm_mipi_dsi.c | 17 +++++++++++++++-- sys/dev/pci/drm/include/drm/drm_mipi_dsi.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sys/dev/pci/drm/drm_mipi_dsi.c b/sys/dev/pci/drm/drm_mipi_dsi.c index 028fa3b858c..97fd47b3615 100644 --- a/sys/dev/pci/drm/drm_mipi_dsi.c +++ b/sys/dev/pci/drm/drm_mipi_dsi.c @@ -353,7 +353,8 @@ static int mipi_dsi_remove_device_fn(struct device *dev, void *priv) { struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev); - mipi_dsi_detach(dsi); + if (dsi->attached) + mipi_dsi_detach(dsi); mipi_dsi_device_unregister(dsi); return 0; @@ -378,11 +379,18 @@ EXPORT_SYMBOL(mipi_dsi_host_unregister); int mipi_dsi_attach(struct mipi_dsi_device *dsi) { const struct mipi_dsi_host_ops *ops = dsi->host->ops; + int ret; if (!ops || !ops->attach) return -ENOSYS; - return ops->attach(dsi->host, dsi); + ret = ops->attach(dsi->host, dsi); + if (ret) + return ret; + + dsi->attached = true; + + return 0; } EXPORT_SYMBOL(mipi_dsi_attach); @@ -394,9 +402,14 @@ int mipi_dsi_detach(struct mipi_dsi_device *dsi) { const struct mipi_dsi_host_ops *ops = dsi->host->ops; + if (WARN_ON(!dsi->attached)) + return -EINVAL; + if (!ops || !ops->detach) return -ENOSYS; + dsi->attached = false; + return ops->detach(dsi->host, dsi); } EXPORT_SYMBOL(mipi_dsi_detach); diff --git a/sys/dev/pci/drm/include/drm/drm_mipi_dsi.h b/sys/dev/pci/drm/include/drm/drm_mipi_dsi.h index 47f34f5dccd..ca58202ec51 100644 --- a/sys/dev/pci/drm/include/drm/drm_mipi_dsi.h +++ b/sys/dev/pci/drm/include/drm/drm_mipi_dsi.h @@ -27,6 +27,7 @@ struct mipi_dsi_device { uint32_t channel; uint32_t mode_flags; #define MIPI_DSI_MODE_LPM (1 << 0) + bool attached; }; struct mipi_dsi_msg { -- 2.20.1