tvservice: Avoid unmatched reference counting on attach/unplugged events
authorpopcornmix <popcornmix@gmail.com>
Fri, 15 Sep 2017 15:07:38 +0000 (16:07 +0100)
committerpopcornmix <popcornmix@gmail.com>
Fri, 6 Oct 2017 17:45:47 +0000 (18:45 +0100)
Thanks to Phil for spotting the suspicious code.
See: https://github.com/raspberrypi/firmware/issues/875

interface/vmcs_host/vc_vchi_tvservice.c

index b8337f38c816a0f31f329aa0af1a2b43c927ce17..69832ad5a1565cbef240b3a0d4df8c6d479fdec6 100644 (file)
@@ -693,6 +693,9 @@ static void *tvservice_notify_func(void *arg) {
          vchi_service_use(state->notify_handle[0]);
       }
    }
+   // the state machine below only wants a single bit to be set
+   if (tvstate.state & (VC_HDMI_ATTACHED|VC_HDMI_UNPLUGGED))
+      tvstate.state &= ~(VC_HDMI_HDMI | VC_HDMI_DVI);
 
    while(1) {
       VCOS_STATUS_T status = vcos_event_wait(&tvservice_notify_available_event);
@@ -718,7 +721,7 @@ static void *tvservice_notify_func(void *arg) {
                         param1, param2);
          switch(reason) {
          case VC_HDMI_UNPLUGGED:
-            if(tvstate.state & (VC_HDMI_HDMI|VC_HDMI_DVI|VC_HDMI_ATTACHED)) {
+            if(tvstate.state & (VC_HDMI_HDMI|VC_HDMI_DVI)) {
                state->copy_protect = 0;
                if((tvstate.state & VC_HDMI_ATTACHED) == 0) {
                   vchi_service_release(state->notify_handle[0]);