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: I2cbe70d3b00cb2cf8c28a28d91a18fbf7c326ea7 Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
This commit is contained in:
parent
c730474f5e
commit
23cee311f9
1 changed files with 22 additions and 18 deletions
|
@ -1090,6 +1090,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(currentPortStatus);
|
||||
queryPowerTransferStatus(currentPortStatus);
|
||||
queryNonCompliantChargerStatus(currentPortStatus);
|
||||
|
@ -1111,6 +1112,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