universal7885: fm-aidl: Fix deadlock on get mutex locked

- We started the function ensuring mutex is locked, and in the middle trying to lock again for return. This will cause deadlock or returning false forever. Therefore, put an if condition before locking at start of the function
This commit is contained in:
roynatech2544 2022-10-22 11:56:30 +09:00
commit 8beec828f7
2 changed files with 12 additions and 4 deletions

View file

@ -37,7 +37,9 @@ namespace aidl::vendor::eureka::hardware::fmradio {
}
::ndk::ScopedAStatus FMDevControl::getValue(GetType type, int *_aidl_return) {
RETURN_IF_FAILED_LOCK;
if (type != GetType::GET_TYPE_FM_MUTEX_LOCKED) {
RETURN_IF_FAILED_LOCK;
}
assert(fd > 0);
switch (type) {
case GetType::GET_TYPE_FM_FREQ:
@ -85,7 +87,9 @@ namespace aidl::vendor::eureka::hardware::fmradio {
default:
break;
};
lock.unlock();
if (type != GetType::GET_TYPE_FM_MUTEX_LOCKED) {
lock.unlock();
}
return ::ndk::ScopedAStatus::ok();
}

View file

@ -33,7 +33,9 @@ constexpr const char *FM_FREQ_SEEK = FM_SYSFS_BASE "/radio_freq_seek";
::ndk::ScopedAStatus FMSupport::open(void) { NOT_SUPPORTED; }
::ndk::ScopedAStatus FMSupport::getValue(GetType type, int *_aidl_return) {
RETURN_IF_FAILED_LOCK;
if (type != GetType::GET_TYPE_FM_MUTEX_LOCKED) {
RETURN_IF_FAILED_LOCK;
}
switch (type) {
case GetType::GET_TYPE_FM_FREQ:
*_aidl_return = FileIO::readline(FM_FREQ_CTL);
@ -76,7 +78,9 @@ constexpr const char *FM_FREQ_SEEK = FM_SYSFS_BASE "/radio_freq_seek";
default:
break;
};
lock.unlock();
if (type != GetType::GET_TYPE_FM_MUTEX_LOCKED) {
lock.unlock();
}
return ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus FMSupport::setValue(SetType type, int value) {