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
Change-Id: Icf3dbe929eb9f0520941a4efe3dcea79a71d46c3
Signed-off-by: RD Babiera <rdbabiera@google.com>
This commit is contained in:
RD Babiera 2024-03-19 18:28:45 +00:00
parent f5f7a90578
commit 94c9c1ac86

View file

@ -1749,8 +1749,10 @@ void *displayPortPollWork(void *param) {
std::vector<PortStatus> currentPortStatus; std::vector<PortStatus> currentPortStatus;
ret = read(usb->mDisplayPortDebounceTimer, &res, sizeof(res)); ret = read(usb->mDisplayPortDebounceTimer, &res, sizeof(res));
ALOGI("usbdp: dp debounce triggered, val:%lu ret:%d", res, ret); ALOGI("usbdp: dp debounce triggered, val:%lu ret:%d", res, ret);
if (ret < 0) if (ret < 0) {
ALOGE("usbdp: debounce read errno:%d", errno); ALOGW("usbdp: debounce read error:%d", errno);
continue;
}
queryVersionHelper(usb, &currentPortStatus); queryVersionHelper(usb, &currentPortStatus);
} else if (events[n].data.fd == usb->mDisplayPortActivateTimer) { } else if (events[n].data.fd == usb->mDisplayPortActivateTimer) {
string activePartner, activePort; string activePartner, activePort;
@ -1801,6 +1803,7 @@ void *displayPortPollWork(void *param) {
error: error:
/* Need to disarm so new threads don't get old event */ /* Need to disarm so new threads don't get old event */
armTimerFdHelper(usb->mDisplayPortDebounceTimer, 0);
armTimerFdHelper(usb->mDisplayPortActivateTimer, 0); armTimerFdHelper(usb->mDisplayPortActivateTimer, 0);
close(link_training_status_fd); close(link_training_status_fd);
link_training_status_fd_error: link_training_status_fd_error: