video: tegra: hdmi: Fix potential crash when setting up HDMI
Alban Bedel [Tue, 12 May 2015 08:28:51 +0000 (13:28 +0530)]
The HDMI state machine registers an IRQ handler before all the resources
it needs are available. Ideally the IRQ handler should be registered
later, however it would mean a quite large change. Instead we just add
some check to avoid running the state machine as long as the
framebuffer hasn't been registered.
While at it also prevent scheduling the state machine if it hasn't been
initialized yet.

Bug 1618089

Change-Id: I8f9dc07d2a4bf7e33e869206ad83ed80af93f566
Signed-off-by: Alban Bedel <alban.bedel@avionic-design.de>
Signed-off-by: Bibek Basu <bbasu@nvidia.com>
Reviewed-on: http://git-master/r/741616
GVS: Gerrit_Virtual_Submit
Reviewed-by: Venkat Moganty <vmoganty@nvidia.com>

drivers/video/tegra/dc/hdmi_state_machine.c

index 5389ff1..87704e6 100644 (file)
@@ -465,6 +465,13 @@ static void hdmi_state_machine_worker(struct work_struct *work)
 {
        int pending_hpd_evt, cur_hpd;
 
+       /* Check if the DC and FB are setup, if not just abort */
+       if (!work_state.hdmi->dc || !work_state.hdmi->dc->fb) {
+               pr_warn("%s (tid %p): %s is not yet set!\n",
+                               __func__, current, work_state.hdmi->dc ? "FB" : "DC");
+               return;
+       }
+
        /* Observe and clear the pending flag and latch the current HPD state.
         */
        rt_mutex_lock(&work_lock);
@@ -522,8 +529,11 @@ void hdmi_state_machine_set_pending_hpd(void)
        rt_mutex_lock(&work_lock);
 
        /* We always schedule work any time there is a pending HPD event */
-       work_state.pending_hpd_evt = 1;
-       hdmi_state_machine_sched_work_l(0);
+       /* But only if the state machine has been inited */
+       if (unlikely(work_state.hdmi)) {
+               work_state.pending_hpd_evt = 1;
+               hdmi_state_machine_sched_work_l(0);
+       }
 
        rt_mutex_unlock(&work_lock);
 }