From 523717b768f5b5ffedfcad86d5403dc8ac87b6a7 Mon Sep 17 00:00:00 2001 From: RD Babiera Date: Tue, 19 Mar 2024 18:28:45 +0000 Subject: [PATCH] usb: handle displayport debounce timer empty reads If the device is unplugged then plugged before mDisplayPortDebounceTimer triggers, then the new displayPortPollWork could process the trigger in the intial epoll handling loop. Because the timer can be rearmed, the timerfd read results in -EAGAIN because no data is ready, but stale data was ready to begin with. Disarm the debounce timer when displayPortPollWork closes to prevent new work threads from reading timer when not ready. Also log debounce read errors as a warning and not an error. Test: manual test on device Bug: 328553922 (cherry-picked from 94c9c1ac86f398c22ddc446f17bd7ab3fddb675c) Change-Id: Icf3dbe929eb9f0520941a4efe3dcea79a71d46c3 Signed-off-by: RD Babiera --- usb/usb/Usb.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index 7b037303..fcb31ead 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -1724,8 +1724,10 @@ void *displayPortPollWork(void *param) { std::vector currentPortStatus; ret = read(usb->mDisplayPortDebounceTimer, &res, sizeof(res)); ALOGI("usbdp: dp debounce triggered, val:%lu ret:%d", res, ret); - if (ret < 0) - ALOGE("usbdp: debounce read errno:%d", errno); + if (ret < 0) { + ALOGW("usbdp: debounce read error:%d", errno); + continue; + } queryVersionHelper(usb, ¤tPortStatus); } else if (events[n].data.fd == usb->mDisplayPortActivateTimer) { string activePartner, activePort; @@ -1776,6 +1778,7 @@ void *displayPortPollWork(void *param) { error: /* Need to disarm so new threads don't get old event */ + armTimerFdHelper(usb->mDisplayPortDebounceTimer, 0); armTimerFdHelper(usb->mDisplayPortActivateTimer, 0); close(link_training_status_fd); link_training_status_fd_error: