Usb: Add status check to prevent NPE
This patch prevents a Null Pointer Exception in queryMoistureDetectionStatus() when getPortStatusHelper() fails to open the /sys/class/typec file. The failure results in an empty currentPortStatus vector, causing the NPE when accessing its first element. Bug: 361097811 Flag: EXEMPT bugfix Test: NPE does not occur when getPortStatusHelper() fails Change-Id: I4657ab8dbc9bb7e5d2dc46c1a20b66477604ec36 Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
This commit is contained in:
parent
a2761f3edc
commit
e5f8be36ac
1 changed files with 21 additions and 17 deletions
|
@ -1215,6 +1215,7 @@ void queryVersionHelper(android::hardware::usb::Usb *usb,
|
|||
|
||||
pthread_mutex_lock(&usb->mLock);
|
||||
status = getPortStatusHelper(usb, currentPortStatus);
|
||||
if (status == Status::SUCCESS && currentPortStatus->size() > 0) {
|
||||
queryMoistureDetectionStatus(usb, currentPortStatus);
|
||||
queryPowerTransferStatus(usb, currentPortStatus);
|
||||
queryNonCompliantChargerStatus(currentPortStatus);
|
||||
|
@ -1235,6 +1236,9 @@ void queryVersionHelper(android::hardware::usb::Usb *usb,
|
|||
} else {
|
||||
ALOGI("Notifying userspace skipped. Callback is NULL");
|
||||
}
|
||||
} else {
|
||||
ALOGI("%s skipped. currentPortStatus is empty", __func__);
|
||||
}
|
||||
pthread_mutex_unlock(&usb->mLock);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue