From patchwork Thu Aug 4 02:21:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yao mark X-Patchwork-Id: 9262523 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A76256048F for ; Thu, 4 Aug 2016 02:22:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 977D926E54 for ; Thu, 4 Aug 2016 02:22:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8BA3927FA1; Thu, 4 Aug 2016 02:22:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0064026E54 for ; Thu, 4 Aug 2016 02:22:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bV8J2-0008O5-D1; Thu, 04 Aug 2016 02:22:44 +0000 Received: from regular1.263xmail.com ([211.150.99.138]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bV8Ik-0008JI-Oi; Thu, 04 Aug 2016 02:22:27 +0000 Received: from mark.yao?rock-chips.com (unknown [192.168.167.153]) by regular1.263xmail.com (Postfix) with SMTP id 0796D7A16; Thu, 4 Aug 2016 10:22:03 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 X-ADDR-CHECKED: 0 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.263.net (Postfix) with ESMTP id BFB8A297AE; Thu, 4 Aug 2016 10:22:00 +0800 (CST) X-RL-SENDER: mark.yao@rock-chips.com X-FST-TO: airlied@linux.ie X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: mark.yao@rock-chips.com X-UNIQUE-TAG: <4776c4276b28b87d116610267fcc2530> X-ATTACHMENT-NUM: 0 X-SENDER: yzq@rock-chips.com X-DNS-TYPE: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith ESMTP id 27244XMOFFO; Thu, 04 Aug 2016 10:22:01 +0800 (CST) From: Mark Yao To: David Airlie , Heiko Stuebner , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] drm/rockchip: fix fbdev crash when not use DRM_FBDEV_EMULATION Date: Thu, 4 Aug 2016 10:21:58 +0800 Message-Id: <1470277318-9204-1-git-send-email-mark.yao@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470212025-30336-1-git-send-email-mark.yao@rock-chips.com> References: <1470212025-30336-1-git-send-email-mark.yao@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160803_192227_290312_CEFBEC24 X-CRM114-Status: GOOD ( 11.30 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Yao MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP [ 1.162571] Unable to handle kernel NULL pointer dereference at virtual address 00000200 [ 1.165656] Modules linked in: [ 1.165941] CPU: 5 PID: 143 Comm: kworker/5:2 Not tainted 4.4.15 #237 [ 1.166506] Hardware name: Rockchip RK3399 Evaluation Board v1 (Android) (DT) [ 1.167153] Workqueue: events output_poll_execute [ 1.168231] PC is at mutex_lock+0x14/0x44 [ 1.168586] LR is at drm_fb_helper_hotplug_event+0x28/0xcc [ 1.172192] [] mutex_lock+0x14/0x44 [ 1.172196] [] drm_fb_helper_hotplug_event+0x28/0xcc [ 1.172201] [] rockchip_drm_output_poll_changed+0x14/0x1c [ 1.172204] [] drm_kms_helper_hotplug_event+0x28/0x34 [ 1.172207] [] output_poll_execute+0x150/0x198 [ 1.172212] [] process_one_work+0x218/0x3dc [ 1.172215] [] worker_thread+0x24c/0x374 [ 1.172217] [] kthread+0xdc/0xe4 [ 1.172222] [] ret_from_fork+0x10/0x40 Signed-off-by: Mark Yao --- Change in v1: Advised by Daniel Vetter only do the struct->pointer conversion alone drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 6 +++--- drivers/gpu/drm/rockchip/rockchip_drm_drv.h | 2 +- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 2 +- drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c | 17 ++++++++++------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c index a822d49..fe22f76 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c @@ -261,7 +261,7 @@ static void rockchip_drm_lastclose(struct drm_device *dev) { struct rockchip_drm_private *priv = dev->dev_private; - drm_fb_helper_restore_fbdev_mode_unlocked(&priv->fbdev_helper); + drm_fb_helper_restore_fbdev_mode_unlocked(priv->fbdev_helper); } static const struct file_operations rockchip_drm_driver_fops = { @@ -311,7 +311,7 @@ void rockchip_drm_fb_suspend(struct drm_device *drm) struct rockchip_drm_private *priv = drm->dev_private; console_lock(); - drm_fb_helper_set_suspend(&priv->fbdev_helper, 1); + drm_fb_helper_set_suspend(priv->fbdev_helper, 1); console_unlock(); } @@ -320,7 +320,7 @@ void rockchip_drm_fb_resume(struct drm_device *drm) struct rockchip_drm_private *priv = drm->dev_private; console_lock(); - drm_fb_helper_set_suspend(&priv->fbdev_helper, 0); + drm_fb_helper_set_suspend(priv->fbdev_helper, 0); console_unlock(); } diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h index ea39329..f005f3f 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h @@ -57,7 +57,7 @@ struct rockchip_crtc_state { * @num_pipe: number of pipes for this device. */ struct rockchip_drm_private { - struct drm_fb_helper fbdev_helper; + struct drm_fb_helper *fbdev_helper; struct drm_gem_object *fbdev_bo; const struct rockchip_crtc_funcs *crtc_funcs[ROCKCHIP_MAX_CRTC]; struct drm_atomic_state *state; diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c index 55c5273..dc034ec 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c @@ -156,7 +156,7 @@ err_gem_object_unreference: static void rockchip_drm_output_poll_changed(struct drm_device *dev) { struct rockchip_drm_private *private = dev->dev_private; - struct drm_fb_helper *fb_helper = &private->fbdev_helper; + struct drm_fb_helper *fb_helper = private->fbdev_helper; if (fb_helper) drm_fb_helper_hotplug_event(fb_helper); diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c b/drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c index 207e01d..6b50dfa 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c @@ -22,14 +22,12 @@ #include "rockchip_drm_fb.h" #define PREFERRED_BPP 32 -#define to_drm_private(x) \ - container_of(x, struct rockchip_drm_private, fbdev_helper) static int rockchip_fbdev_mmap(struct fb_info *info, struct vm_area_struct *vma) { struct drm_fb_helper *helper = info->par; - struct rockchip_drm_private *private = to_drm_private(helper); + struct rockchip_drm_private *private = helper->dev->dev_private; return rockchip_gem_mmap_buf(private->fbdev_bo, vma); } @@ -50,7 +48,7 @@ static struct fb_ops rockchip_drm_fbdev_ops = { static int rockchip_drm_fbdev_create(struct drm_fb_helper *helper, struct drm_fb_helper_surface_size *sizes) { - struct rockchip_drm_private *private = to_drm_private(helper); + struct rockchip_drm_private *private = helper->dev->dev_private; struct drm_mode_fb_cmd2 mode_cmd = { 0 }; struct drm_device *dev = helper->dev; struct rockchip_gem_object *rk_obj; @@ -139,7 +137,11 @@ int rockchip_drm_fbdev_init(struct drm_device *dev) num_crtc = dev->mode_config.num_crtc; - helper = &private->fbdev_helper; + helper = devm_kzalloc(dev->dev, sizeof(*helper), GFP_KERNEL); + if (!helper) + return -ENOMEM; + + private->fbdev_helper = helper; drm_fb_helper_prepare(dev, helper, &rockchip_drm_fb_helper_funcs); @@ -173,9 +175,10 @@ err_drm_fb_helper_fini: void rockchip_drm_fbdev_fini(struct drm_device *dev) { struct rockchip_drm_private *private = dev->dev_private; - struct drm_fb_helper *helper; + struct drm_fb_helper *helper = private->fbdev_helper; - helper = &private->fbdev_helper; + if (!helper) + return; drm_fb_helper_unregister_fbi(helper); drm_fb_helper_release_fbi(helper);