Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp98842imm; Tue, 9 Oct 2018 14:31:41 -0700 (PDT) X-Google-Smtp-Source: ACcGV62m0/YjVHaqtgI4w33KEZKbeL9hJ5AkWkjnv6vA5zVwRYGB7keAKB5UFHBhiFrBFqxeCPTq X-Received: by 2002:aa7:8895:: with SMTP id l21-v6mr31558948pfo.74.1539120701761; Tue, 09 Oct 2018 14:31:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539120701; cv=none; d=google.com; s=arc-20160816; b=FeY7EuyJLJ1EwnDLg8dsCpgHP2M0GkeckN634XZIf6riQrT8aUkVATukHhnMLMchsB fJ/lgWqVPSbIccZqnEM+5VKReKs/VrFq8ulsz35EpyA5NiqeSI0jYs/UrJ9yvfz2cHPG LFQ+tMucHQ/MYwdjeuEuxjCYrPKfNdyxl3cVUJ7j5Y3fk8Qs5lqooRZ65khnOnbwMlKK 5HIuE5vyCm06aJHa2QvalQCIhKDUqLcNO+qh1MVcv77GW/k7uhQS0HI+PKLYnBTDSs0C 6OSBmh/FHwewyG4RT2M5AGrWy4MPJYJ2Wi1dTIV7FuOtu8Xa5uJdJhWZVgRmPbCYMGFc PYxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oxKES5i8OdqEPY0M+7sSXxnNFq2ypMEHz1LKRg/ZWX8=; b=WbZeIb0Jd45otB+nP+GBgLppmvOo26/5P2B6rhWRnB9HMf+I2MqHW8+2kh7Bk/HMmt 2BVGMV1GE8q8PbKxasUVe75kUeKVt5pjcKM2+vmbRGoSwB0/Esw9hVzP3eY1S4Kuz5j9 Ox90TMadrXpjPWSnAgKbZ8K6zKql9hkjkN2iqXnVo+hGplpwPOvpsxcXBEmsHxJNi3x1 93ObdnK4BlKsimw8KXd72j6HTZpHds6r5DjgLctYUgNyjQUoTPvJz6kfox3Su9azqpd3 pBZeMQAx5RZp0mrzikmFH88rKt9N59pl0N/E9NCsxXMngmFHqWduvDmT3HPcOOQBklRT fQMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@agner.ch header.s=dkim header.b=IXKnDQxY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i191-v6si21236037pge.545.2018.10.09.14.31.26; Tue, 09 Oct 2018 14:31:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@agner.ch header.s=dkim header.b=IXKnDQxY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727271AbeJJEtv (ORCPT + 99 others); Wed, 10 Oct 2018 00:49:51 -0400 Received: from mail.kmu-office.ch ([178.209.48.109]:53196 "EHLO mail.kmu-office.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725837AbeJJEtq (ORCPT ); Wed, 10 Oct 2018 00:49:46 -0400 Received: from allenwind.lan (unknown [37.17.239.109]) by mail.kmu-office.ch (Postfix) with ESMTPSA id 300D15C097A; Tue, 9 Oct 2018 23:30:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1539120651; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oxKES5i8OdqEPY0M+7sSXxnNFq2ypMEHz1LKRg/ZWX8=; b=IXKnDQxYRNYsCQ8OJd65+MojUtbqTAobgET+WYt5lfpgiqtBYSEdB1SKTeRUajfeUT3v+x QlSp5XQlOy46VIcdAv/A7VjDqBnWVTYVyJT2pp/x+hjfoWg8L/miTxzQ2jW/0Vt5bVsPv7 /+kjdFzwwq9iGha5oATJ0ELVCnPU6nI= From: Stefan Agner 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 Subject: [PATCH 2/2] drm/imx: make sure to cleanup DRM before unbinding components Date: Tue, 9 Oct 2018 23:30:49 +0200 Message-Id: X-Mailer: git-send-email 2.19.1 In-Reply-To: <83a28282a3f745a4cd4ca77d0593ad2e61359a5d.1539120077.git.stefan@agner.ch> References: <83a28282a3f745a4cd4ca77d0593ad2e61359a5d.1539120077.git.stefan@agner.ch> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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