mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefan Agner <stefan@agner.ch>
To: p.zabel@pengutronix.de, airlied@linux.ie, gregkh@linuxfoundation.org
Cc: rafael@kernel.org, linux@armlinux.org.uk,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Stefan Agner <stefan@agner.ch>
Subject: [PATCH 2/2] drm/imx: make sure to cleanup DRM before unbinding components
Date: Tue,  9 Oct 2018 23:30:49 +0200	[thread overview]
Message-ID: <e08eff2ed53b441c8a6c41758c00c1c91dc48d2c.1539120077.git.stefan@agner.ch> (raw)
In-Reply-To: <83a28282a3f745a4cd4ca77d0593ad2e61359a5d.1539120077.git.stefan@agner.ch>

In situations where a component fails to bind, a previously
successfully bound component might already registered itself
with the DRM framework (e.g. an encoder). When the master
component then calls drm_mode_config_cleanup, we end up in a
use after free sitution.

Use the cleanup callback to make sure all framework level
cleanup is done by the time we unbind components.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 drivers/gpu/drm/imx/imx-drm-core.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/imx/imx-drm-core.c b/drivers/gpu/drm/imx/imx-drm-core.c
index 5ea0c82f9957..b174a0ca9acb 100644
--- a/drivers/gpu/drm/imx/imx-drm-core.c
+++ b/drivers/gpu/drm/imx/imx-drm-core.c
@@ -288,8 +288,8 @@ static int imx_drm_bind(struct device *dev)
 err_unbind:
 #endif
 	component_unbind_all(drm->dev, drm);
-err_kms:
 	drm_mode_config_cleanup(drm);
+err_kms:
 	drm_dev_put(drm);
 
 	return ret;
@@ -313,9 +313,17 @@ static void imx_drm_unbind(struct device *dev)
 	drm_dev_put(drm);
 }
 
+static void imx_drm_cleanup(struct device *dev)
+{
+	struct drm_device *drm = dev_get_drvdata(dev);
+
+	drm_mode_config_cleanup(drm);
+}
+
 static const struct component_master_ops imx_drm_ops = {
 	.bind = imx_drm_bind,
 	.unbind = imx_drm_unbind,
+	.cleanup = imx_drm_cleanup,
 };
 
 static int imx_drm_platform_probe(struct platform_device *pdev)
-- 
2.19.1


  reply	other threads:[~2018-10-09 21:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-09 21:30 [PATCH 1/2] component: add optional cleanup function Stefan Agner
2018-10-09 21:30 ` Stefan Agner [this message]
2018-10-10 10:38   ` [PATCH 2/2] drm/imx: make sure to cleanup DRM before unbinding components Russell King - ARM Linux
2018-10-10 11:02     ` Stefan Agner
2018-10-10 11:22       ` Russell King - ARM Linux

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=e08eff2ed53b441c8a6c41758c00c1c91dc48d2c.1539120077.git.stefan@agner.ch \
    --to=stefan@agner.ch \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=p.zabel@pengutronix.de \
    --cc=rafael@kernel.org \
    /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®