ams: globally prefer R_RETURN to return for ams::Result

This commit is contained in:
Michael Scire
2022-03-26 14:48:33 -07:00
parent dd78ede99f
commit bbf22b4c60
325 changed files with 1955 additions and 1993 deletions

View File

@@ -192,7 +192,7 @@ namespace ams::i2c::driver::board::nintendo::nx::impl {
}
/* Send the data. */
return this->Send(static_cast<const u8 *>(src), src_size, option, device->GetAddress(), device->GetAddressingMode());
R_RETURN(this->Send(static_cast<const u8 *>(src), src_size, option, device->GetAddress(), device->GetAddressingMode()));
}
Result I2cBusAccessor::Receive(void *dst, size_t dst_size, I2cDeviceProperty *device, TransactionOption option) {
@@ -208,7 +208,7 @@ namespace ams::i2c::driver::board::nintendo::nx::impl {
}
/* Send the data. */
return this->Receive(static_cast<u8 *>(dst), dst_size, option, device->GetAddress(), device->GetAddressingMode());
R_RETURN(this->Receive(static_cast<u8 *>(dst), dst_size, option, device->GetAddress(), device->GetAddressingMode()));
}
void I2cBusAccessor::SuspendBus() {
@@ -399,7 +399,7 @@ namespace ams::i2c::driver::board::nintendo::nx::impl {
this->DisableInterruptMask();
os::ClearInterruptEvent(std::addressof(m_interrupt_event));
return i2c::ResultTimeout();
R_THROW(i2c::ResultTimeout());
}
/* Check and handle any errors. */
@@ -429,7 +429,7 @@ namespace ams::i2c::driver::board::nintendo::nx::impl {
this->DisableInterruptMask();
os::ClearInterruptEvent(std::addressof(m_interrupt_event));
return i2c::ResultTimeout();
R_THROW(i2c::ResultTimeout());
}
}
@@ -474,7 +474,7 @@ namespace ams::i2c::driver::board::nintendo::nx::impl {
this->DisableInterruptMask();
os::ClearInterruptEvent(std::addressof(m_interrupt_event));
return i2c::ResultTimeout();
R_THROW(i2c::ResultTimeout());
}
/* Check and handle any errors. */

View File

@@ -101,13 +101,13 @@ namespace ams::i2c::driver::board::nintendo::nx::impl {
Result CheckAndHandleError() {
const Result result = this->GetTransactionResult();
this->HandleTransactionError(result);
if (R_FAILED(result)) {
this->DisableInterruptMask();
os::ClearInterruptEvent(std::addressof(m_interrupt_event));
return result;
}
R_SUCCEED();
R_RETURN(result);
}
public:
virtual void InitializeDriver() override;

View File

@@ -27,14 +27,10 @@ namespace ams::i2c::driver {
Result OpenSessionImpl(I2cSession *out, I2cDeviceProperty *device) {
/* Construct the session. */
auto *session = std::construct_at(std::addressof(impl::GetI2cSessionImpl(*out)), DefaultRetryCount, DefaultRetryInterval);
auto session_guard = SCOPE_GUARD { std::destroy_at(session); };
ON_RESULT_FAILURE { std::destroy_at(session); };
/* Open the session. */
R_TRY(session->Open(device, ddsf::AccessMode_ReadWrite));
/* We succeeded. */
session_guard.Cancel();
R_SUCCEED();
R_RETURN(session->Open(device, ddsf::AccessMode_ReadWrite));
}
}
@@ -48,9 +44,7 @@ namespace ams::i2c::driver {
AMS_ASSERT(device != nullptr);
/* Open the session. */
R_TRY(OpenSessionImpl(out, device));
R_SUCCEED();
R_RETURN(OpenSessionImpl(out, device));
}
void CloseSession(I2cSession &session) {
@@ -61,14 +55,14 @@ namespace ams::i2c::driver {
AMS_ASSERT(src != nullptr);
AMS_ABORT_UNLESS(src_size > 0);
return impl::GetOpenI2cSessionImpl(session).Send(src, src_size, option);
R_RETURN(impl::GetOpenI2cSessionImpl(session).Send(src, src_size, option));
}
Result Receive(void *dst, size_t dst_size, I2cSession &session, TransactionOption option) {
AMS_ASSERT(dst != nullptr);
AMS_ABORT_UNLESS(dst_size > 0);
return impl::GetOpenI2cSessionImpl(session).Receive(dst, dst_size, option);
R_RETURN(impl::GetOpenI2cSessionImpl(session).Receive(dst, dst_size, option));
}
Result ExecuteCommandList(void *dst, size_t dst_size, I2cSession &session, const void *src, size_t src_size) {
@@ -78,14 +72,14 @@ namespace ams::i2c::driver {
AMS_ABORT_UNLESS(src_size > 0);
AMS_ABORT_UNLESS(dst_size > 0);
return impl::GetOpenI2cSessionImpl(session).ExecuteCommandList(dst, dst_size, src, src_size);
R_RETURN(impl::GetOpenI2cSessionImpl(session).ExecuteCommandList(dst, dst_size, src, src_size));
}
Result SetRetryPolicy(I2cSession &session, int max_retry_count, int retry_interval_us) {
AMS_ASSERT(max_retry_count > 0);
AMS_ASSERT(retry_interval_us > 0);
return impl::GetOpenI2cSessionImpl(session).SetRetryPolicy(max_retry_count, retry_interval_us);
R_RETURN(impl::GetOpenI2cSessionImpl(session).SetRetryPolicy(max_retry_count, retry_interval_us));
}
}

View File

@@ -28,7 +28,7 @@ namespace ams::i2c::driver {
}
Result RegisterDeviceCode(DeviceCode device_code, I2cDeviceProperty *device) {
return impl::RegisterDeviceCode(device_code, device);
R_RETURN(impl::RegisterDeviceCode(device_code, device));
}
bool UnregisterDeviceCode(DeviceCode device_code) {

View File

@@ -148,7 +148,7 @@ namespace ams::i2c::driver::impl {
os::SleepThread(m_retry_interval);
continue;
}
return i2c::ResultBusBusy();
R_THROW(i2c::ResultBusBusy());
}
} R_END_TRY_CATCH;
@@ -160,14 +160,14 @@ namespace ams::i2c::driver::impl {
/* Acquire exclusive access to the device. */
std::scoped_lock lk(this->GetDevice().SafeCastTo<I2cDeviceProperty>().GetDriver().SafeCastTo<II2cDriver>().GetTransactionOrderMutex());
return this->ExecuteTransactionWithRetry(nullptr, Command::Send, src, src_size, option);
R_RETURN(this->ExecuteTransactionWithRetry(nullptr, Command::Send, src, src_size, option));
}
Result I2cSessionImpl::Receive(void *dst, size_t dst_size, TransactionOption option) {
/* Acquire exclusive access to the device. */
std::scoped_lock lk(this->GetDevice().SafeCastTo<I2cDeviceProperty>().GetDriver().SafeCastTo<II2cDriver>().GetTransactionOrderMutex());
return this->ExecuteTransactionWithRetry(dst, Command::Receive, nullptr, dst_size, option);
R_RETURN(this->ExecuteTransactionWithRetry(dst, Command::Receive, nullptr, dst_size, option));
}
Result I2cSessionImpl::ExecuteCommandList(void *dst, size_t dst_size, const void *src, size_t src_size) {