Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/rockchip: Fix suspend crash when drm is not bound

Currently we are allocating drm_device in rockchip_drm_bind, so if the
suspend/resume code access it when drm is not bound, we would hit this
crash:

[ 253.402836] Unable to handle kernel NULL pointer dereference at virtual address 00000028
[ 253.402837] pgd = ffffffc06c9b0000
[ 253.402841] [00000028] *pgd=0000000000000000, *pud=0000000000000000
[ 253.402844] Internal error: Oops: 96000005 [#1] PREEMPT SMP
[ 253.402859] Modules linked in: btusb btrtl btbcm btintel bluetooth ath10k_pci ath10k_core ar10k_ath ar10k_mac80211 cfg80211 ip6table_filter asix usbnet mii
[ 253.402864] CPU: 4 PID: 1331 Comm: cat Not tainted 4.4.70 #15
[ 253.402865] Hardware name: Google Scarlet (DT)
[ 253.402867] task: ffffffc076c0ce00 ti: ffffffc06c2c8000 task.ti: ffffffc06c2c8000
[ 253.402871] PC is at rockchip_drm_sys_suspend+0x20/0x5c

Add sanity checks to prevent that.

Reported-by: Brian Norris <briannorris@chromium.com>
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
Signed-off-by: Sean Paul <seanpaul@chromium.org>
Link: https://patchwork.kernel.org/patch/9890297/

authored by

Jeffy Chen and committed by
Sean Paul
0fa375e6 80c471ea

+10 -2
+10 -2
drivers/gpu/drm/rockchip/rockchip_drm_drv.c
··· 275 275 static int rockchip_drm_sys_suspend(struct device *dev) 276 276 { 277 277 struct drm_device *drm = dev_get_drvdata(dev); 278 - struct rockchip_drm_private *priv = drm->dev_private; 278 + struct rockchip_drm_private *priv; 279 + 280 + if (!drm) 281 + return 0; 279 282 280 283 drm_kms_helper_poll_disable(drm); 281 284 rockchip_drm_fb_suspend(drm); 282 285 286 + priv = drm->dev_private; 283 287 priv->state = drm_atomic_helper_suspend(drm); 284 288 if (IS_ERR(priv->state)) { 285 289 rockchip_drm_fb_resume(drm); ··· 297 293 static int rockchip_drm_sys_resume(struct device *dev) 298 294 { 299 295 struct drm_device *drm = dev_get_drvdata(dev); 300 - struct rockchip_drm_private *priv = drm->dev_private; 296 + struct rockchip_drm_private *priv; 301 297 298 + if (!drm) 299 + return 0; 300 + 301 + priv = drm->dev_private; 302 302 drm_atomic_helper_resume(drm, priv->state); 303 303 rockchip_drm_fb_resume(drm); 304 304 drm_kms_helper_poll_enable(drm);